aboutsummaryrefslogtreecommitdiff
path: root/whatmaps
diff options
context:
space:
mode:
Diffstat (limited to 'whatmaps')
-rwxr-xr-xwhatmaps55
1 files changed, 30 insertions, 25 deletions
diff --git a/whatmaps b/whatmaps
index b1fdb46..70ecdae 100755
--- a/whatmaps
+++ b/whatmaps
@@ -83,6 +83,9 @@ class Pkg(object):
def __init__(self):
raise NotImplementedError
+ def __repr__(self):
+ return "<%s Pkg object name:'%s'>" % (self.type, self.name)
+
class DebianDistro(Distro):
"Debian (dpkg) based distribution"""
@@ -106,53 +109,55 @@ class DebianDistro(Distro):
class DebianPkg(Pkg):
+ type = 'Debian'
+ _so_regex = re.compile(r'(?P<so>/.*\.so(\.[^/])*$)')
+ _init_script_re = re.compile('/etc/init.d/[a-zA-Z0-9]')
+
def __init__(self, name):
self.name = name
self._services = None
self._shared_objects = None
+ self._contents = None
- def _get_shared_objects(self):
+ def _get_contents(self):
+ if self._contents:
+ return self._contents
+ else:
+ list_contents = subprocess.Popen(["dpkg-query -L %s 2>/dev/null" % self.name],
+ stdout=subprocess.PIPE, shell=True)
+ output = list_contents.communicate()[0]
+ if list_contents.returncode:
+ raise PkgError
+ self.contents = output.split('\n')
+ return self.contents
+
+ @property
+ def shared_objects(self):
if self._shared_objects != None:
return self._shared_objects
self._shared_objects = []
- regex = re.compile(r'(?P<so>/.*\.so(\.[^/])*$)')
- list_contents = subprocess.Popen(["dpkg-query -L %s 2>/dev/null" % self.name],
- stdout=subprocess.PIPE, shell=True)
- output = list_contents.communicate()[0]
- if list_contents.returncode:
- raise PkgError
+ contents = self._get_contents()
- for line in output.split('\n'):
- m = regex.match(line)
+ for line in contents:
+ m = self._so_regex.match(line)
if m:
self._shared_objects.append(m.group('so'))
return self._shared_objects
- def _get_services(self):
+ @property
+ def services(self):
if self._services != None:
return self._services
self._services = []
+ contents = self._get_contents()
# Only supports sysvinit so far:
- script_re = re.compile('/etc/init.d/[a-zA-Z0-9]')
- list_contents = subprocess.Popen(["dpkg-query -L %s 2>/dev/null" % self.name],
- stdout=subprocess.PIPE, shell=True)
- output = list_contents.communicate()[0]
- if list_contents.returncode:
- raise PkgError
-
- for line in output.split('\n'):
- if script_re.match(line):
+ for line in contents:
+ if self._init_script_re.match(line):
self._services.append(os.path.basename(line.strip()))
return self._services
- def __repr__(self):
- return "<Debian Pkg object name:'%s'>" % self.name
-
- services = property(_get_services, None)
- shared_objects = property(_get_shared_objects, None)
-
def check_maps(procs, shared_objects):
restart_procs = {}