diff options
Diffstat (limited to 'whatmaps/distro.py')
-rw-r--r-- | whatmaps/distro.py | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/whatmaps/distro.py b/whatmaps/distro.py index f0f08eb..29d2dc2 100644 --- a/whatmaps/distro.py +++ b/whatmaps/distro.py @@ -17,6 +17,7 @@ import logging import os +import re import subprocess @@ -25,6 +26,7 @@ try: except ImportError: lsb_release = None + class Distro(object): """ A distribution @@ -32,6 +34,8 @@ class Distro(object): @cvar id: distro id as returned by lsb-release @cvar service_blacklist: services that should never be restarted + @cvar service_blacklist_re: regex list of services that should + never be restartet @cvar _pkg_services: A C{dict} that maps packages to services. In case we find binaries that match a key in this hash restart the services listed in values. @@ -40,6 +44,8 @@ class Distro(object): """ id = None service_blacklist = set() + service_blacklist_re = set() + _pkg_services = {} _pkg_blacklist = {} _pkg_service_blacklist = {} @@ -75,8 +81,8 @@ class Distro(object): List of services that package pkg needs restarted that aren't part of pkg itself """ - return [ s for s in klass._pkg_services.get(pkg.name, []) - if klass.is_service_installed(s) ] + return [s for s in klass._pkg_services.get(pkg.name, []) + if klass.is_service_installed(s)] @classmethod def pkg_service_blacklist(klass, pkg): @@ -86,6 +92,17 @@ class Distro(object): """ return klass._pkg_service_blacklist.get(pkg.name, []) + def filter_services(self, services): + """ + Filter out servies that match service_blacklist_re + """ + ret = [] + matchers = [re.compile(b) for b in self.service_blacklist_re] + for s in services: + if not any([m.match(s) for m in matchers]): + ret.append(s) + return set(ret) + @classmethod def has_apt(klass): """Does the distribution use apt""" @@ -95,8 +112,9 @@ class Distro(object): def detect(): return detect() -import whatmaps.debiandistro -import whatmaps.redhatdistro +import whatmaps.debiandistro # noqa: E402 +import whatmaps.redhatdistro # noqa: E402 + def detect(): """ @@ -110,11 +128,11 @@ def detect(): else: try: lsb_cmd = subprocess.Popen(['lsb_release', '--id', '-s'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) output = lsb_cmd.communicate()[0] if not lsb_cmd.returncode: - id = output.strip() + id = output.strip() except OSError: # id is None in this case pass |