mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-04 11:17:05 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -187,17 +187,17 @@ class Snap(StateModuleHelper):
|
|||
CHANNEL_MISMATCH = 1
|
||||
INSTALLED = 2
|
||||
|
||||
__disable_re = re.compile(r'(?:\S+\s+){5}(?P<notes>\S+)')
|
||||
__set_param_re = re.compile(r'(?P<snap_prefix>\S+:)?(?P<key>\S+)\s*=\s*(?P<value>.+)')
|
||||
__list_re = re.compile(r'^(?P<name>\S+)\s+\S+\s+\S+\s+(?P<channel>\S+)')
|
||||
__disable_re = re.compile(r"(?:\S+\s+){5}(?P<notes>\S+)")
|
||||
__set_param_re = re.compile(r"(?P<snap_prefix>\S+:)?(?P<key>\S+)\s*=\s*(?P<value>.+)")
|
||||
__list_re = re.compile(r"^(?P<name>\S+)\s+\S+\s+\S+\s+(?P<channel>\S+)")
|
||||
module = dict(
|
||||
argument_spec={
|
||||
'name': dict(type='list', elements='str', required=True),
|
||||
'state': dict(type='str', default='present', choices=['absent', 'present', 'enabled', 'disabled']),
|
||||
'classic': dict(type='bool', default=False),
|
||||
'channel': dict(type='str'),
|
||||
'options': dict(type='list', elements='str'),
|
||||
'dangerous': dict(type='bool', default=False),
|
||||
"name": dict(type="list", elements="str", required=True),
|
||||
"state": dict(type="str", default="present", choices=["absent", "present", "enabled", "disabled"]),
|
||||
"classic": dict(type="bool", default=False),
|
||||
"channel": dict(type="str"),
|
||||
"options": dict(type="list", elements="str"),
|
||||
"dangerous": dict(type="bool", default=False),
|
||||
},
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
|
@ -227,7 +227,12 @@ class Snap(StateModuleHelper):
|
|||
else:
|
||||
status_var = "name"
|
||||
self.vars.set("status_var", status_var, output=False)
|
||||
self.vars.set("snap_status", self.snap_status(self.vars[self.vars.status_var], self.vars.channel), output=False, change=True)
|
||||
self.vars.set(
|
||||
"snap_status",
|
||||
self.snap_status(self.vars[self.vars.status_var], self.vars.channel),
|
||||
output=False,
|
||||
change=True,
|
||||
)
|
||||
self.vars.set("snap_status_map", dict(zip(self.vars.name, self.vars.snap_status)), output=False, change=True)
|
||||
|
||||
def __quit_module__(self):
|
||||
|
|
@ -262,10 +267,10 @@ class Snap(StateModuleHelper):
|
|||
results_run_info.append(ctx.run_info)
|
||||
|
||||
return (
|
||||
'; '.join([to_native(x) for x in results_cmd]),
|
||||
"; ".join([to_native(x) for x in results_cmd]),
|
||||
self._first_non_zero(results_rc),
|
||||
'\n'.join(results_out),
|
||||
'\n'.join(results_err),
|
||||
"\n".join(results_out),
|
||||
"\n".join(results_err),
|
||||
results_run_info,
|
||||
)
|
||||
|
||||
|
|
@ -273,8 +278,10 @@ class Snap(StateModuleHelper):
|
|||
option_map = {}
|
||||
|
||||
if not isinstance(json_subtree, dict):
|
||||
self.do_raise("Non-dict non-leaf element encountered while parsing option map. "
|
||||
"The output format of 'snap set' may have changed. Aborting!")
|
||||
self.do_raise(
|
||||
"Non-dict non-leaf element encountered while parsing option map. "
|
||||
"The output format of 'snap set' may have changed. Aborting!"
|
||||
)
|
||||
|
||||
for key, value in json_subtree.items():
|
||||
full_key = key if prefix is None else f"{prefix}.{key}"
|
||||
|
|
@ -307,7 +314,8 @@ class Snap(StateModuleHelper):
|
|||
return option_map
|
||||
except Exception as e:
|
||||
self.do_raise(
|
||||
msg=f"Parsing option map returned by 'snap get {snap_name}' triggers exception '{e}', output:\n'{out}'")
|
||||
msg=f"Parsing option map returned by 'snap get {snap_name}' triggers exception '{e}', output:\n'{out}'"
|
||||
)
|
||||
|
||||
def names_from_snaps(self, snaps):
|
||||
def process_one(rc, out, err):
|
||||
|
|
@ -334,9 +342,11 @@ class Snap(StateModuleHelper):
|
|||
process_ = process_many
|
||||
|
||||
if "warning: no snap found" in check_error:
|
||||
self.do_raise("Snaps not found: {0}.".format([x.split()[-1]
|
||||
for x in out.split('\n')
|
||||
if x.startswith("warning: no snap found")]))
|
||||
self.do_raise(
|
||||
"Snaps not found: {0}.".format(
|
||||
[x.split()[-1] for x in out.split("\n") if x.startswith("warning: no snap found")]
|
||||
)
|
||||
)
|
||||
return process_(rc, out, err)
|
||||
|
||||
names = []
|
||||
|
|
@ -360,9 +370,9 @@ class Snap(StateModuleHelper):
|
|||
|
||||
with self.runner("_list") as ctx:
|
||||
rc, out, err = ctx.run(check_rc=True)
|
||||
list_out = out.split('\n')[1:]
|
||||
list_out = out.split("\n")[1:]
|
||||
list_out = [self.__list_re.match(x) for x in list_out]
|
||||
list_out = [(m.group('name'), m.group('channel')) for m in list_out if m]
|
||||
list_out = [(m.group("name"), m.group("channel")) for m in list_out if m]
|
||||
self.vars.status_out = list_out
|
||||
self.vars.status_run_info = ctx.run_info
|
||||
|
||||
|
|
@ -377,8 +387,8 @@ class Snap(StateModuleHelper):
|
|||
match = self.__disable_re.match(result)
|
||||
if not match:
|
||||
self.do_raise(msg=f"Unable to parse 'snap list {snap_name}' output:\n{out}")
|
||||
notes = match.group('notes')
|
||||
return "disabled" not in notes.split(',')
|
||||
notes = match.group("notes")
|
||||
return "disabled" not in notes.split(",")
|
||||
|
||||
def _present(self, actionable_snaps, refresh=False):
|
||||
self.changed = True
|
||||
|
|
@ -387,35 +397,42 @@ class Snap(StateModuleHelper):
|
|||
if self.check_mode:
|
||||
return
|
||||
|
||||
params = ['state', 'classic', 'channel', 'dangerous'] # get base cmd parts
|
||||
has_one_pkg_params = bool(self.vars.classic) or self.vars.channel != 'stable'
|
||||
params = ["state", "classic", "channel", "dangerous"] # get base cmd parts
|
||||
has_one_pkg_params = bool(self.vars.classic) or self.vars.channel != "stable"
|
||||
has_multiple_snaps = len(actionable_snaps) > 1
|
||||
|
||||
if has_one_pkg_params and has_multiple_snaps:
|
||||
self.vars.cmd, rc, out, err, run_info = self._run_multiple_commands(params, actionable_snaps, bundle=False, refresh=refresh)
|
||||
self.vars.cmd, rc, out, err, run_info = self._run_multiple_commands(
|
||||
params, actionable_snaps, bundle=False, refresh=refresh
|
||||
)
|
||||
else:
|
||||
self.vars.cmd, rc, out, err, run_info = self._run_multiple_commands(params, actionable_snaps, refresh=refresh)
|
||||
self.vars.cmd, rc, out, err, run_info = self._run_multiple_commands(
|
||||
params, actionable_snaps, refresh=refresh
|
||||
)
|
||||
self.vars.run_info = run_info
|
||||
|
||||
if rc == 0:
|
||||
return
|
||||
|
||||
classic_snap_pattern = re.compile(r'^error: This revision of snap "(?P<package_name>\w+)"'
|
||||
r' was published using classic confinement')
|
||||
classic_snap_pattern = re.compile(
|
||||
r'^error: This revision of snap "(?P<package_name>\w+)"'
|
||||
r" was published using classic confinement"
|
||||
)
|
||||
match = classic_snap_pattern.match(err)
|
||||
if match:
|
||||
err_pkg = match.group('package_name')
|
||||
err_pkg = match.group("package_name")
|
||||
msg = f"Couldn't install {err_pkg} because it requires classic confinement"
|
||||
else:
|
||||
msg = f"Ooops! Snap installation failed while executing '{self.vars.cmd}', please examine logs and error output for more details."
|
||||
self.do_raise(msg=msg)
|
||||
|
||||
def state_present(self):
|
||||
self.vars.set_meta("classic", output=True)
|
||||
self.vars.set_meta("channel", output=True)
|
||||
|
||||
self.vars.set_meta('classic', output=True)
|
||||
self.vars.set_meta('channel', output=True)
|
||||
|
||||
actionable_refresh = [snap for snap in self.vars.name if self.vars.snap_status_map[snap] == Snap.CHANNEL_MISMATCH]
|
||||
actionable_refresh = [
|
||||
snap for snap in self.vars.name if self.vars.snap_status_map[snap] == Snap.CHANNEL_MISMATCH
|
||||
]
|
||||
if actionable_refresh:
|
||||
self._present(actionable_refresh, refresh=True)
|
||||
actionable_install = [snap for snap in self.vars.name if self.vars.snap_status_map[snap] == Snap.NOT_INSTALLED]
|
||||
|
|
@ -456,7 +473,9 @@ class Snap(StateModuleHelper):
|
|||
|
||||
if key not in option_map or key in option_map and option_map[key] != value:
|
||||
option_without_prefix = f"{key}={value}"
|
||||
option_with_prefix = option_string if selected_snap_name is not None else f"{snap_name}:{option_string}"
|
||||
option_with_prefix = (
|
||||
option_string if selected_snap_name is not None else f"{snap_name}:{option_string}"
|
||||
)
|
||||
options_changed.append(option_without_prefix)
|
||||
overall_options_changed.append(option_with_prefix)
|
||||
|
||||
|
|
@ -493,18 +512,24 @@ class Snap(StateModuleHelper):
|
|||
self.do_raise(msg=msg)
|
||||
|
||||
def state_absent(self):
|
||||
self._generic_state_action(lambda s: self.vars.snap_status_map[s] != Snap.NOT_INSTALLED, "snaps_removed", ['classic', 'channel', 'state'])
|
||||
self._generic_state_action(
|
||||
lambda s: self.vars.snap_status_map[s] != Snap.NOT_INSTALLED,
|
||||
"snaps_removed",
|
||||
["classic", "channel", "state"],
|
||||
)
|
||||
|
||||
def state_enabled(self):
|
||||
self._generic_state_action(lambda s: not self.is_snap_enabled(s), "snaps_enabled", ['classic', 'channel', 'state'])
|
||||
self._generic_state_action(
|
||||
lambda s: not self.is_snap_enabled(s), "snaps_enabled", ["classic", "channel", "state"]
|
||||
)
|
||||
|
||||
def state_disabled(self):
|
||||
self._generic_state_action(self.is_snap_enabled, "snaps_disabled", ['classic', 'channel', 'state'])
|
||||
self._generic_state_action(self.is_snap_enabled, "snaps_disabled", ["classic", "channel", "state"])
|
||||
|
||||
|
||||
def main():
|
||||
Snap.execute()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue