1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-01 09:56:18 +00:00

Fix linting errors; fix some real bugs (#5111)

* Fix linting errors.

* Fix bugs.

* Another linter error ignored.

* More fixes.

* Ignore sanity errors with older versions.

ci_complete

* Forgot to commit more changes.
This commit is contained in:
Felix Fontein 2022-08-12 11:07:30 +02:00 committed by GitHub
parent 0338eb7a7c
commit a54af8909c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 115 additions and 94 deletions

View file

@ -98,13 +98,13 @@ from ansible.module_utils.facts.packages import CLIMgr
class PIP(CLIMgr):
def __init__(self, pip):
def __init__(self, pip, module):
self.CLI = pip
self.module = module
def list_installed(self):
global module
rc, out, err = module.run_command([self._cli, 'list', '-l', '--format=json'])
rc, out, err = self.module.run_command([self._cli, 'list', '-l', '--format=json'])
if rc != 0:
raise Exception("Unable to list packages rc=%s : %s" % (rc, err))
return json.loads(out)
@ -117,7 +117,6 @@ class PIP(CLIMgr):
def main():
# start work
global module
module = AnsibleModule(
argument_spec=dict(
clients=dict(type='list', elements='path', default=['pip']),
@ -134,7 +133,7 @@ def main():
module.warn('Skipping invalid pip client: %s' % (pip))
continue
try:
pip_mgr = PIP(pip)
pip_mgr = PIP(pip, module)
if pip_mgr.is_available():
found += 1
packages[pip] = pip_mgr.get_packages()

View file

@ -222,7 +222,7 @@ class Yarn(object):
rc, out, err = self.module.run_command(cmd, check_rc=check_rc, cwd=cwd)
return out, err
return(None, None)
return None, None
def list(self):
cmd = ['list', '--depth=0', '--json']

View file

@ -85,6 +85,7 @@ try:
import dnf.repodict
from dnf.conf import Conf
HAS_DNF_PACKAGES = True
DNF_IMP_ERR = None
except ImportError:
DNF_IMP_ERR = traceback.format_exc()
HAS_DNF_PACKAGES = False

View file

@ -163,7 +163,7 @@ OUTDATED_FLATPAK_VERSION_ERROR_MESSAGE = "Unknown option --columns=application"
def install_flat(module, binary, remote, names, method, no_dependencies):
"""Add new flatpaks."""
global result
global result # pylint: disable=global-variable-not-assigned
uri_names = []
id_names = []
for name in names:
@ -190,7 +190,7 @@ def install_flat(module, binary, remote, names, method, no_dependencies):
def uninstall_flat(module, binary, names, method):
"""Remove existing flatpaks."""
global result
global result # pylint: disable=global-variable-not-assigned
installed_flat_names = [
_match_installed_flat_name(module, binary, name, method)
for name in names
@ -225,7 +225,7 @@ def _match_installed_flat_name(module, binary, name, method):
# This is a difficult function, since if the user supplies a flatpakref url,
# we have to rely on a naming convention:
# The flatpakref file name needs to match the flatpak name
global result
global result # pylint: disable=global-variable-not-assigned
parsed_name = _parse_flatpak_name(name)
# Try running flatpak list with columns feature
command = [binary, "list", "--{0}".format(method), "--app", "--columns=application"]
@ -249,7 +249,7 @@ def _match_installed_flat_name(module, binary, name, method):
def _match_flat_using_outdated_flatpak_format(module, binary, parsed_name, method):
global result
global result # pylint: disable=global-variable-not-assigned
command = [binary, "list", "--{0}".format(method), "--app", "--columns=application"]
output = _flatpak_command(module, False, command)
for row in output.split('\n'):
@ -258,7 +258,7 @@ def _match_flat_using_outdated_flatpak_format(module, binary, parsed_name, metho
def _match_flat_using_flatpak_column_feature(module, binary, parsed_name, method):
global result
global result # pylint: disable=global-variable-not-assigned
command = [binary, "list", "--{0}".format(method), "--app"]
output = _flatpak_command(module, False, command)
for row in output.split('\n'):
@ -277,7 +277,7 @@ def _parse_flatpak_name(name):
def _flatpak_version(module, binary):
global result
global result # pylint: disable=global-variable-not-assigned
command = [binary, "--version"]
output = _flatpak_command(module, False, command)
version_number = output.split()[1]
@ -285,7 +285,7 @@ def _flatpak_version(module, binary):
def _flatpak_command(module, noop, command, ignore_failure=False):
global result
global result # pylint: disable=global-variable-not-assigned
result['command'] = ' '.join(command)
if noop:
result['rc'] = 0

View file

@ -125,7 +125,7 @@ from ansible.module_utils.common.text.converters import to_bytes, to_native
def add_remote(module, binary, name, flatpakrepo_url, method):
"""Add a new remote."""
global result
global result # pylint: disable=global-variable-not-assigned
command = [binary, "remote-add", "--{0}".format(method), name, flatpakrepo_url]
_flatpak_command(module, module.check_mode, command)
result['changed'] = True
@ -133,7 +133,7 @@ def add_remote(module, binary, name, flatpakrepo_url, method):
def remove_remote(module, binary, name, method):
"""Remove an existing remote."""
global result
global result # pylint: disable=global-variable-not-assigned
command = [binary, "remote-delete", "--{0}".format(method), "--force", name]
_flatpak_command(module, module.check_mode, command)
result['changed'] = True
@ -154,7 +154,7 @@ def remote_exists(module, binary, name, method):
def _flatpak_command(module, noop, command):
global result
global result # pylint: disable=global-variable-not-assigned
result['command'] = ' '.join(command)
if noop:
result['rc'] = 0

View file

@ -159,7 +159,7 @@ def upgrade(module, xbps_path):
rc, stdout, stderr = module.run_command(cmdneedupgrade, check_rc=False)
if rc == 0:
if(len(stdout.splitlines()) == 0):
if len(stdout.splitlines()) == 0:
module.exit_json(changed=False, msg='Nothing to upgrade')
elif module.check_mode:
module.exit_json(changed=True, msg='Would have performed upgrade')