diff options
author | John Kacur <jkacur@redhat.com> | 2020-09-15 13:50:53 -0400 |
---|---|---|
committer | John Kacur <jkacur@redhat.com> | 2020-09-15 13:50:53 -0400 |
commit | 01d1d79a6e585e80cd8313f2b296f1fd4abbe02d (patch) | |
tree | 5a88e0006febcecd77e4eb5dd6a62adb55ab3a3c | |
parent | 3fd8a5a94123010aea7ad69dfb57c5a5cf374b03 (diff) | |
download | rteval-01d1d79a6e585e80cd8313f2b296f1fd4abbe02d.tar.gz |
rteval: services.py: a few clean-ups
- imports on separate lines
- whitespace fixes
- remove unnecessary else clauses after returns
- don't specify inhertiance from object
Signed-off-by: John Kacur <jkacur@redhat.com>
-rw-r--r-- | rteval/sysinfo/services.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/rteval/sysinfo/services.py b/rteval/sysinfo/services.py index 1bab2de..06ff5ae 100644 --- a/rteval/sysinfo/services.py +++ b/rteval/sysinfo/services.py @@ -25,12 +25,17 @@ # are deemed to be part of the source code. # -import sys, subprocess, os, glob, fnmatch, libxml2 +import sys +import subprocess +import os +import glob +import fnmatch +import libxml2 from rteval.sysinfo.tools import getcmdpath from rteval.Log import Log -class SystemServices(object): +class SystemServices: def __init__(self, logger=None): self.__logger = logger self.__init = "unknown" @@ -54,7 +59,8 @@ class SystemServices(object): ret_services = {} for service in glob.glob(os.path.join(servicesdir, '*')): servicename = os.path.basename(service) - if not [1 for p in reject if fnmatch.fnmatch(servicename, p)] and os.access(service, os.X_OK): + if not [1 for p in reject if fnmatch.fnmatch(servicename, p)] \ + and os.access(service, os.X_OK): cmd = '%s -qs "\(^\|\W\)status)" %s' % (getcmdpath('grep'), service) c = subprocess.Popen(cmd, shell=True) c.wait() @@ -84,19 +90,18 @@ class SystemServices(object): def services_get(self): - cmd = [getcmdpath('ps'), '-ocomm=', '1'] + cmd = [getcmdpath('ps'), '-ocomm=', '1'] c = subprocess.Popen(cmd, stdout=subprocess.PIPE) self.__init = c.stdout.read().strip() if self.__init == 'systemd': self.__log(Log.DEBUG, "Using systemd to get services status") return self.__get_services_systemd() - elif self.__init == 'init': + if self.__init == 'init': self.__init = 'sysvinit' self.__log(Log.DEBUG, "Using sysvinit to get services status") return self.__get_services_sysvinit() - else: - self.__init = 'container' - self.__log(Log.DEBUG, "Running inside container") + self.__init = 'container' + self.__log(Log.DEBUG, "Running inside container") return {} @@ -127,8 +132,8 @@ def unit_test(rootdir): xml_d.saveFormatFileEnc("-", "UTF-8", 1) return 0 - except Exception as e: - print("** EXCEPTION: %s" % str(e)) + except Exception as err: + print("** EXCEPTION: %s" % str(err)) return 1 |