mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Use common functions for handling import errors (#51851)
* Use common functions for handling import errors * use refactored version of gitlab modules
This commit is contained in:
parent
28dcfa985f
commit
c1e51ef486
39 changed files with 233 additions and 93 deletions
|
@ -161,20 +161,25 @@ import posixpath
|
|||
import shutil
|
||||
import io
|
||||
import tempfile
|
||||
import traceback
|
||||
|
||||
LXML_ETREE_IMP_ERR = None
|
||||
try:
|
||||
from lxml import etree
|
||||
HAS_LXML_ETREE = True
|
||||
except ImportError:
|
||||
LXML_ETREE_IMP_ERR = traceback.format_exc()
|
||||
HAS_LXML_ETREE = False
|
||||
|
||||
BOTO_IMP_ERR = None
|
||||
try:
|
||||
import boto3
|
||||
HAS_BOTO = True
|
||||
except ImportError:
|
||||
BOTO_IMP_ERR = traceback.format_exc()
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
from ansible.module_utils._text import to_bytes, to_native, to_text
|
||||
|
@ -463,7 +468,7 @@ def main():
|
|||
)
|
||||
|
||||
if not HAS_LXML_ETREE:
|
||||
module.fail_json(msg='module requires the lxml python library installed on the managed machine')
|
||||
module.fail_json(msg=missing_required_lib('lxml'), exception=LXML_ETREE_IMP_ERR)
|
||||
|
||||
repository_url = module.params["repository_url"]
|
||||
if not repository_url:
|
||||
|
@ -476,7 +481,8 @@ def main():
|
|||
local = parsed_url.scheme == "file"
|
||||
|
||||
if parsed_url.scheme == 's3' and not HAS_BOTO:
|
||||
module.fail_json(msg='boto3 required for this module, when using s3:// repository URLs')
|
||||
module.fail_json(msg=missing_required_lib('boto3', reason='when using s3:// repository URLs'),
|
||||
exception=BOTO_IMP_ERR)
|
||||
|
||||
group_id = module.params["group_id"]
|
||||
artifact_id = module.params["artifact_id"]
|
||||
|
|
|
@ -80,17 +80,20 @@ EXAMPLES = '''
|
|||
'''
|
||||
|
||||
import shutil
|
||||
import traceback
|
||||
|
||||
from os import path
|
||||
|
||||
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()
|
||||
HAS_LAYMAN_API = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
|
||||
|
||||
|
@ -239,7 +242,7 @@ def main():
|
|||
)
|
||||
|
||||
if not HAS_LAYMAN_API:
|
||||
module.fail_json(msg='Layman is not installed')
|
||||
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'])
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue