mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-26 21:33:12 +00:00
Reformat everything.
This commit is contained in:
@@ -80,8 +80,8 @@ class PSAdapterError(Exception):
|
||||
|
||||
|
||||
class PSAdapter(metaclass=abc.ABCMeta):
|
||||
NAME_ATTRS = ('name', 'cmdline')
|
||||
PATTERN_ATTRS = ('name', 'exe', 'cmdline')
|
||||
NAME_ATTRS = ("name", "cmdline")
|
||||
PATTERN_ATTRS = ("name", "exe", "cmdline")
|
||||
|
||||
def __init__(self, psutil):
|
||||
self._psutil = psutil
|
||||
@@ -89,9 +89,9 @@ class PSAdapter(metaclass=abc.ABCMeta):
|
||||
@staticmethod
|
||||
def from_package(psutil):
|
||||
version = LooseVersion(psutil.__version__)
|
||||
if version < LooseVersion('2.0.0'):
|
||||
if version < LooseVersion("2.0.0"):
|
||||
return PSAdapter100(psutil)
|
||||
elif version < LooseVersion('5.3.0'):
|
||||
elif version < LooseVersion("5.3.0"):
|
||||
return PSAdapter200(psutil)
|
||||
else:
|
||||
return PSAdapter530(psutil)
|
||||
@@ -104,8 +104,11 @@ class PSAdapter(metaclass=abc.ABCMeta):
|
||||
|
||||
def _has_name(self, proc, name):
|
||||
attributes = self._get_proc_attributes(proc, *self.NAME_ATTRS)
|
||||
return (compare_lower(attributes['name'], name) or
|
||||
attributes['cmdline'] and compare_lower(attributes['cmdline'][0], name))
|
||||
return (
|
||||
compare_lower(attributes["name"], name)
|
||||
or attributes["cmdline"]
|
||||
and compare_lower(attributes["cmdline"][0], name)
|
||||
)
|
||||
|
||||
def _get_proc_attributes(self, proc, *attributes):
|
||||
return {attribute: self._get_attribute_from_proc(proc, attribute) for attribute in attributes}
|
||||
@@ -130,9 +133,9 @@ class PSAdapter(metaclass=abc.ABCMeta):
|
||||
def _matches_regex(self, proc, regex):
|
||||
# See https://psutil.readthedocs.io/en/latest/#find-process-by-name for more information
|
||||
attributes = self._get_proc_attributes(proc, *self.PATTERN_ATTRS)
|
||||
matches_name = regex.search(to_native(attributes['name']))
|
||||
matches_exe = attributes['exe'] and regex.search(basename(to_native(attributes['exe'])))
|
||||
matches_cmd = attributes['cmdline'] and regex.search(to_native(' '.join(attributes['cmdline'])))
|
||||
matches_name = regex.search(to_native(attributes["name"]))
|
||||
matches_exe = attributes["exe"] and regex.search(basename(to_native(attributes["exe"])))
|
||||
matches_cmd = attributes["cmdline"] and regex.search(to_native(" ".join(attributes["cmdline"])))
|
||||
|
||||
return any([matches_name, matches_exe, matches_cmd])
|
||||
|
||||
@@ -178,15 +181,14 @@ def compare_lower(a, b):
|
||||
|
||||
class Pids:
|
||||
def __init__(self, module):
|
||||
|
||||
deps.validate(module)
|
||||
|
||||
self._ps = PSAdapter.from_package(psutil)
|
||||
|
||||
self._module = module
|
||||
self._name = module.params['name']
|
||||
self._pattern = module.params['pattern']
|
||||
self._ignore_case = module.params['ignore_case']
|
||||
self._name = module.params["name"]
|
||||
self._pattern = module.params["pattern"]
|
||||
self._ignore_case = module.params["ignore_case"]
|
||||
|
||||
self._pids = []
|
||||
|
||||
@@ -204,7 +206,7 @@ class Pids:
|
||||
@property
|
||||
def result(self):
|
||||
return {
|
||||
'pids': self._pids,
|
||||
"pids": self._pids,
|
||||
}
|
||||
|
||||
|
||||
@@ -215,17 +217,13 @@ def main():
|
||||
pattern=dict(type="str"),
|
||||
ignore_case=dict(type="bool", default=False),
|
||||
),
|
||||
required_one_of=[
|
||||
('name', 'pattern')
|
||||
],
|
||||
mutually_exclusive=[
|
||||
('name', 'pattern')
|
||||
],
|
||||
required_one_of=[("name", "pattern")],
|
||||
mutually_exclusive=[("name", "pattern")],
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
Pids(module).execute()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user