mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -86,6 +86,7 @@ LAYMAN_IMP_ERR = None
|
|||
try:
|
||||
from layman.api import LaymanAPI
|
||||
from layman.config import BareConfig
|
||||
|
||||
HAS_LAYMAN_API = True
|
||||
except ImportError:
|
||||
LAYMAN_IMP_ERR = traceback.format_exc()
|
||||
|
|
@ -95,7 +96,7 @@ from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
|||
from ansible.module_utils.urls import fetch_url
|
||||
|
||||
|
||||
USERAGENT = 'ansible-httpget'
|
||||
USERAGENT = "ansible-httpget"
|
||||
|
||||
|
||||
class ModuleError(Exception):
|
||||
|
|
@ -103,39 +104,39 @@ class ModuleError(Exception):
|
|||
|
||||
|
||||
def init_layman(config=None):
|
||||
'''Returns the initialized ``LaymanAPI``.
|
||||
"""Returns the initialized ``LaymanAPI``.
|
||||
|
||||
:param config: the layman's configuration to use (optional)
|
||||
'''
|
||||
"""
|
||||
if config is None:
|
||||
config = BareConfig(read_configfile=True, quietness=1)
|
||||
return LaymanAPI(config)
|
||||
|
||||
|
||||
def download_url(module, url, dest):
|
||||
'''
|
||||
"""
|
||||
:param url: the URL to download
|
||||
:param dest: the absolute path of where to save the downloaded content to;
|
||||
it must be writable and not a directory
|
||||
|
||||
:raises ModuleError
|
||||
'''
|
||||
"""
|
||||
|
||||
# Hack to add params in the form that fetch_url expects
|
||||
module.params['http_agent'] = USERAGENT
|
||||
module.params["http_agent"] = USERAGENT
|
||||
response, info = fetch_url(module, url)
|
||||
if info['status'] != 200:
|
||||
if info["status"] != 200:
|
||||
raise ModuleError(f"Failed to get {url}: {info['msg']}")
|
||||
|
||||
try:
|
||||
with open(dest, 'w') as f:
|
||||
with open(dest, "w") as f:
|
||||
shutil.copyfileobj(response, f)
|
||||
except IOError as e:
|
||||
raise ModuleError(f"Failed to write: {e}")
|
||||
|
||||
|
||||
def install_overlay(module, name, list_url=None):
|
||||
'''Installs the overlay repository. If not on the central overlays list,
|
||||
"""Installs the overlay repository. If not on the central overlays list,
|
||||
then :list_url of an alternative list must be provided. The list will be
|
||||
fetched and saved under ``%(overlay_defs)/%(name.xml)`` (location of the
|
||||
``overlay_defs`` is read from the Layman's configuration).
|
||||
|
|
@ -147,7 +148,7 @@ def install_overlay(module, name, list_url=None):
|
|||
:returns: True if the overlay was installed, or False if already exists
|
||||
(i.e. nothing has changed)
|
||||
:raises ModuleError
|
||||
'''
|
||||
"""
|
||||
# read Layman configuration
|
||||
layman_conf = BareConfig(read_configfile=True)
|
||||
layman = init_layman(layman_conf)
|
||||
|
|
@ -161,9 +162,11 @@ def install_overlay(module, name, list_url=None):
|
|||
|
||||
if not layman.is_repo(name):
|
||||
if not list_url:
|
||||
raise ModuleError(f"Overlay '{name}' is not on the list of known overlays and URL of the remote list was not provided.")
|
||||
raise ModuleError(
|
||||
f"Overlay '{name}' is not on the list of known overlays and URL of the remote list was not provided."
|
||||
)
|
||||
|
||||
overlay_defs = layman_conf.get_option('overlay_defs')
|
||||
overlay_defs = layman_conf.get_option("overlay_defs")
|
||||
dest = path.join(overlay_defs, f"{name}.xml")
|
||||
|
||||
download_url(module, list_url, dest)
|
||||
|
|
@ -178,14 +181,14 @@ def install_overlay(module, name, list_url=None):
|
|||
|
||||
|
||||
def uninstall_overlay(module, name):
|
||||
'''Uninstalls the given overlay repository from the system.
|
||||
"""Uninstalls the given overlay repository from the system.
|
||||
|
||||
:param name: the overlay id to uninstall
|
||||
|
||||
:returns: True if the overlay was uninstalled, or False if doesn't exist
|
||||
(i.e. nothing has changed)
|
||||
:raises ModuleError
|
||||
'''
|
||||
"""
|
||||
layman = init_layman()
|
||||
|
||||
if not layman.is_installed(name):
|
||||
|
|
@ -203,11 +206,11 @@ def uninstall_overlay(module, name):
|
|||
|
||||
|
||||
def sync_overlay(name):
|
||||
'''Synchronizes the specified overlay repository.
|
||||
"""Synchronizes the specified overlay repository.
|
||||
|
||||
:param name: the overlay repository id to sync
|
||||
:raises ModuleError
|
||||
'''
|
||||
"""
|
||||
layman = init_layman()
|
||||
|
||||
if not layman.sync(name):
|
||||
|
|
@ -216,10 +219,10 @@ def sync_overlay(name):
|
|||
|
||||
|
||||
def sync_overlays():
|
||||
'''Synchronize all of the installed overlays.
|
||||
"""Synchronize all of the installed overlays.
|
||||
|
||||
:raises ModuleError
|
||||
'''
|
||||
"""
|
||||
layman = init_layman()
|
||||
|
||||
for name in layman.get_installed():
|
||||
|
|
@ -231,25 +234,25 @@ def main():
|
|||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
name=dict(required=True),
|
||||
list_url=dict(aliases=['url']),
|
||||
state=dict(default="present", choices=['present', 'absent', 'updated']),
|
||||
validate_certs=dict(default=True, type='bool'),
|
||||
list_url=dict(aliases=["url"]),
|
||||
state=dict(default="present", choices=["present", "absent", "updated"]),
|
||||
validate_certs=dict(default=True, type="bool"),
|
||||
),
|
||||
supports_check_mode=True
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
if not HAS_LAYMAN_API:
|
||||
module.fail_json(msg=missing_required_lib('Layman'), exception=LAYMAN_IMP_ERR)
|
||||
module.fail_json(msg=missing_required_lib("Layman"), exception=LAYMAN_IMP_ERR)
|
||||
|
||||
state, name, url = (module.params[key] for key in ['state', 'name', 'list_url'])
|
||||
state, name, url = (module.params[key] for key in ["state", "name", "list_url"])
|
||||
|
||||
changed = False
|
||||
try:
|
||||
if state == 'present':
|
||||
if state == "present":
|
||||
changed = install_overlay(module, name, url)
|
||||
|
||||
elif state == 'updated':
|
||||
if name == 'ALL':
|
||||
elif state == "updated":
|
||||
if name == "ALL":
|
||||
sync_overlays()
|
||||
elif install_overlay(module, name, url):
|
||||
changed = True
|
||||
|
|
@ -264,5 +267,5 @@ def main():
|
|||
module.exit_json(changed=changed, name=name)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue