1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-03-22 05:09:12 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -84,59 +84,63 @@ from ansible.module_utils.basic import AnsibleModule
def a_valid_tap(tap):
'''Returns True if the tap is valid.'''
regex = re.compile(r'^([\w-]+)/(homebrew-)?([\w-]+)$')
"""Returns True if the tap is valid."""
regex = re.compile(r"^([\w-]+)/(homebrew-)?([\w-]+)$")
return regex.match(tap)
def already_tapped(module, brew_path, tap):
'''Returns True if already tapped.'''
"""Returns True if already tapped."""
rc, out, err = module.run_command([
brew_path,
'tap',
])
rc, out, err = module.run_command(
[
brew_path,
"tap",
]
)
taps = [tap_.strip().lower() for tap_ in out.split('\n') if tap_]
tap_name = re.sub('homebrew-', '', tap.lower())
taps = [tap_.strip().lower() for tap_ in out.split("\n") if tap_]
tap_name = re.sub("homebrew-", "", tap.lower())
return tap_name in taps
def add_tap(module, brew_path, tap, url=None):
'''Adds a single tap.'''
failed, changed, msg = False, False, ''
"""Adds a single tap."""
failed, changed, msg = False, False, ""
if not a_valid_tap(tap):
failed = True
msg = f'not a valid tap: {tap}'
msg = f"not a valid tap: {tap}"
elif not already_tapped(module, brew_path, tap):
if module.check_mode:
module.exit_json(changed=True)
rc, out, err = module.run_command([
brew_path,
'tap',
tap,
url,
])
rc, out, err = module.run_command(
[
brew_path,
"tap",
tap,
url,
]
)
if rc == 0:
changed = True
msg = f'successfully tapped: {tap}'
msg = f"successfully tapped: {tap}"
else:
failed = True
msg = f'failed to tap: {tap} due to {err}'
msg = f"failed to tap: {tap} due to {err}"
else:
msg = f'already tapped: {tap}'
msg = f"already tapped: {tap}"
return (failed, changed, msg)
def add_taps(module, brew_path, taps):
'''Adds one or more taps.'''
failed, changed, unchanged, added, msg = False, False, 0, 0, ''
"""Adds one or more taps."""
failed, changed, unchanged, added, msg = False, False, 0, 0, ""
for tap in taps:
(failed, changed, msg) = add_tap(module, brew_path, tap)
@ -152,46 +156,48 @@ def add_taps(module, brew_path, taps):
msg = msg % (added, unchanged)
elif added:
changed = True
msg = f'added: {added}, unchanged: {unchanged}'
msg = f"added: {added}, unchanged: {unchanged}"
else:
msg = f'added: {added}, unchanged: {unchanged}'
msg = f"added: {added}, unchanged: {unchanged}"
return (failed, changed, msg)
def remove_tap(module, brew_path, tap):
'''Removes a single tap.'''
failed, changed, msg = False, False, ''
"""Removes a single tap."""
failed, changed, msg = False, False, ""
if not a_valid_tap(tap):
failed = True
msg = f'not a valid tap: {tap}'
msg = f"not a valid tap: {tap}"
elif already_tapped(module, brew_path, tap):
if module.check_mode:
module.exit_json(changed=True)
rc, out, err = module.run_command([
brew_path,
'untap',
tap,
])
rc, out, err = module.run_command(
[
brew_path,
"untap",
tap,
]
)
if not already_tapped(module, brew_path, tap):
changed = True
msg = f'successfully untapped: {tap}'
msg = f"successfully untapped: {tap}"
else:
failed = True
msg = f'failed to untap: {tap} due to {err}'
msg = f"failed to untap: {tap} due to {err}"
else:
msg = f'already untapped: {tap}'
msg = f"already untapped: {tap}"
return (failed, changed, msg)
def remove_taps(module, brew_path, taps):
'''Removes one or more taps.'''
failed, changed, unchanged, removed, msg = False, False, 0, 0, ''
"""Removes one or more taps."""
failed, changed, unchanged, removed, msg = False, False, 0, 0, ""
for tap in taps:
(failed, changed, msg) = remove_tap(module, brew_path, tap)
@ -207,9 +213,9 @@ def remove_taps(module, brew_path, taps):
msg = msg % (removed, unchanged)
elif removed:
changed = True
msg = f'removed: {removed}, unchanged: {unchanged}'
msg = f"removed: {removed}, unchanged: {unchanged}"
else:
msg = f'removed: {removed}, unchanged: {unchanged}'
msg = f"removed: {removed}, unchanged: {unchanged}"
return (failed, changed, msg)
@ -217,31 +223,31 @@ def remove_taps(module, brew_path, taps):
def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(aliases=['tap'], type='list', required=True, elements='str'),
name=dict(aliases=["tap"], type="list", required=True, elements="str"),
url=dict(),
state=dict(default='present', choices=['present', 'absent']),
state=dict(default="present", choices=["present", "absent"]),
path=dict(
default="/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin",
type='path',
type="path",
),
),
supports_check_mode=True,
)
path = module.params['path']
path = module.params["path"]
if path:
path = path.split(':')
path = path.split(":")
brew_path = module.get_bin_path(
'brew',
"brew",
required=True,
opt_dirs=path,
)
taps = module.params['name']
url = module.params['url']
taps = module.params["name"]
url = module.params["url"]
if module.params['state'] == 'present':
if module.params["state"] == "present":
if url is None:
# No tap URL provided explicitly, continue with bulk addition
# of all the taps.
@ -260,7 +266,7 @@ def main():
else:
module.exit_json(changed=changed, msg=msg)
elif module.params['state'] == 'absent':
elif module.params["state"] == "absent":
failed, changed, msg = remove_taps(module, brew_path, taps)
if failed:
@ -269,5 +275,5 @@ def main():
module.exit_json(changed=changed, msg=msg)
if __name__ == '__main__':
if __name__ == "__main__":
main()