-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdpkg.py
52 lines (46 loc) · 1.68 KB
/
dpkg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
"""
This file will implement the dpkg class
"""
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
import subprocess
import checkers
import logging
class Dpkg:
"""This class will implement the internals of the dpkg handling"""
def __init__(self, log_level, dpkg_exe='/usr/bin/dpkg', dpkg_dir='/var/lib/dpkg/'):
"""Set some local variables"""
self.log = logging.getLogger("Dpkg")
self.log.setLevel(log_level)
self.loglevel = log_level
self._dpkg_exe = dpkg_exe
self._dpkg_dir = dpkg_dir
self._config_checker_list = list()
for checker in checkers.checkerslist:
self._config_checker_list.append(checker)
def make_dpkg_listing(self):
"""Make a listing of installed packages"""
process = subprocess.Popen([self._dpkg_exe, '--get-selections'],
stdout=subprocess.PIPE)
output = process.communicate()[0]
_new_list = list()
for line in output.splitlines():
(pkg, status) = line.split()
if status == 'install':
_new_list.append(pkg)
return _new_list
def find_altered_config(self, pkg):
"""Return a list of config files to be included based on the package
name.
"""
files = list()
for checker in self._config_checker_list:
checker.set_debug(self.loglevel)
retval = checker.do_check(pkg, self._dpkg_exe, self._dpkg_dir)
if retval:
files.extend(retval)
self.log.debug('Config file (%s) is changed' % (retval))
return files
if __name__ == '__main__':
# No unit test implemented yet
pass