mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-29 08:01:24 -07:00
pacman: PEP8 compliancy and doc fixes (#30913)
This PR includes: - PEP8 compliancy fixes - Documentation fixes
This commit is contained in:
parent
c7760f3ea8
commit
fd91da7297
2 changed files with 52 additions and 60 deletions
|
@ -1,21 +1,18 @@
|
||||||
#!/usr/bin/python -tt
|
#!/usr/bin/python -tt
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2012, Afterburn <http://github.com/afterburn>
|
# Copyright: (c) 2012, Afterburn <http://github.com/afterburn>
|
||||||
# (c) 2013, Aaron Bull Schaefer <aaron@elasticdog.com>
|
# Copyright: (c) 2013, Aaron Bull Schaefer <aaron@elasticdog.com>
|
||||||
# (c) 2015, Indrajit Raychaudhuri <irc+code@indrajit.com>
|
# Copyright: (c) 2015, Indrajit Raychaudhuri <irc+code@indrajit.com>
|
||||||
#
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: pacman
|
module: pacman
|
||||||
|
@ -25,34 +22,28 @@ description:
|
||||||
Arch Linux and its variants.
|
Arch Linux and its variants.
|
||||||
version_added: "1.0"
|
version_added: "1.0"
|
||||||
author:
|
author:
|
||||||
- "Indrajit Raychaudhuri (@indrajitr)"
|
- Indrajit Raychaudhuri (@indrajitr)
|
||||||
- "'Aaron Bull Schaefer (@elasticdog)' <aaron@elasticdog.com>"
|
- Aaron Bull Schaefer (@elasticdog) <aaron@elasticdog.com>
|
||||||
- "Afterburn"
|
- Afterburn
|
||||||
notes: []
|
|
||||||
requirements: []
|
|
||||||
options:
|
options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Name of the package to install, upgrade, or remove.
|
- Name of the package to install, upgrade, or remove.
|
||||||
required: false
|
aliases: [ package, pkg ]
|
||||||
default: null
|
|
||||||
aliases: [ 'pkg', 'package' ]
|
|
||||||
|
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Desired state of the package.
|
- Desired state of the package.
|
||||||
required: false
|
default: present
|
||||||
default: "present"
|
choices: [ absent, latest, present ]
|
||||||
choices: ["present", "absent", "latest"]
|
|
||||||
|
|
||||||
recurse:
|
recurse:
|
||||||
description:
|
description:
|
||||||
- When removing a package, also remove its dependencies, provided
|
- When removing a package, also remove its dependencies, provided
|
||||||
that they are not required by other packages and were not
|
that they are not required by other packages and were not
|
||||||
explicitly installed by a user.
|
explicitly installed by a user.
|
||||||
required: false
|
type: bool
|
||||||
default: no
|
default: no
|
||||||
choices: ["yes", "no"]
|
|
||||||
version_added: "1.3"
|
version_added: "1.3"
|
||||||
|
|
||||||
force:
|
force:
|
||||||
|
@ -60,26 +51,23 @@ options:
|
||||||
- When removing package - force remove package, without any
|
- When removing package - force remove package, without any
|
||||||
checks. When update_cache - force redownload repo
|
checks. When update_cache - force redownload repo
|
||||||
databases.
|
databases.
|
||||||
required: false
|
type: bool
|
||||||
default: no
|
default: no
|
||||||
choices: ["yes", "no"]
|
|
||||||
version_added: "2.0"
|
version_added: "2.0"
|
||||||
|
|
||||||
update_cache:
|
update_cache:
|
||||||
description:
|
description:
|
||||||
- Whether or not to refresh the master package lists. This can be
|
- Whether or not to refresh the master package lists. This can be
|
||||||
run as part of a package installation or as a separate step.
|
run as part of a package installation or as a separate step.
|
||||||
required: false
|
type: bool
|
||||||
default: no
|
default: no
|
||||||
choices: ["yes", "no"]
|
aliases: [ update-cache ]
|
||||||
aliases: [ 'update-cache' ]
|
|
||||||
|
|
||||||
upgrade:
|
upgrade:
|
||||||
description:
|
description:
|
||||||
- Whether or not to upgrade whole system
|
- Whether or not to upgrade whole system.
|
||||||
required: false
|
type: bool
|
||||||
default: no
|
default: no
|
||||||
choices: ["yes", "no"]
|
|
||||||
version_added: "2.0"
|
version_added: "2.0"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -88,47 +76,47 @@ packages:
|
||||||
description: a list of packages that have been changed
|
description: a list of packages that have been changed
|
||||||
returned: when upgrade is set to yes
|
returned: when upgrade is set to yes
|
||||||
type: list
|
type: list
|
||||||
sample: ['package', 'other-package']
|
sample: [ package, other-package ]
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Install package foo
|
- name: Install package foo
|
||||||
- pacman:
|
pacman:
|
||||||
name: foo
|
name: foo
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
# Upgrade package foo
|
- name: Upgrade package foo
|
||||||
- pacman:
|
pacman:
|
||||||
name: foo
|
name: foo
|
||||||
state: latest
|
state: latest
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
|
||||||
# Remove packages foo and bar
|
- name: Remove packages foo and bar
|
||||||
- pacman:
|
pacman:
|
||||||
name: foo,bar
|
name: foo,bar
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
# Recursively remove package baz
|
- name: Recursively remove package baz
|
||||||
- pacman:
|
pacman:
|
||||||
name: baz
|
name: baz
|
||||||
state: absent
|
state: absent
|
||||||
recurse: yes
|
recurse: yes
|
||||||
|
|
||||||
# Run the equivalent of "pacman -Sy" as a separate step
|
- name: Run the equivalent of "pacman -Sy" as a separate step
|
||||||
- pacman:
|
pacman:
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
|
||||||
# Run the equivalent of "pacman -Su" as a separate step
|
- name: Run the equivalent of "pacman -Su" as a separate step
|
||||||
- pacman:
|
pacman:
|
||||||
upgrade: yes
|
upgrade: yes
|
||||||
|
|
||||||
# Run the equivalent of "pacman -Syu" as a separate step
|
- name: Run the equivalent of "pacman -Syu" as a separate step
|
||||||
- pacman:
|
pacman:
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
upgrade: yes
|
upgrade: yes
|
||||||
|
|
||||||
# Run the equivalent of "pacman -Rdd", force remove package baz
|
- name: Run the equivalent of "pacman -Rdd", force remove package baz
|
||||||
- pacman:
|
pacman:
|
||||||
name: baz
|
name: baz
|
||||||
state: absent
|
state: absent
|
||||||
force: yes
|
force: yes
|
||||||
|
@ -136,6 +124,9 @@ EXAMPLES = '''
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
def get_version(pacman_output):
|
def get_version(pacman_output):
|
||||||
"""Take pacman -Qi or pacman -Si output and get the Version"""
|
"""Take pacman -Qi or pacman -Si output and get the Version"""
|
||||||
lines = pacman_output.split('\n')
|
lines = pacman_output.split('\n')
|
||||||
|
@ -144,6 +135,7 @@ def get_version(pacman_output):
|
||||||
return line.split(':')[1].strip()
|
return line.split(':')[1].strip()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def query_package(module, pacman_path, name, state="present"):
|
def query_package(module, pacman_path, name, state="present"):
|
||||||
"""Query the package status in both the local system and the repository. Returns a boolean to indicate if the package is installed, a second
|
"""Query the package status in both the local system and the repository. Returns a boolean to indicate if the package is installed, a second
|
||||||
boolean to indicate if the package is up-to-date and a third boolean to indicate whether online information were available
|
boolean to indicate if the package is up-to-date and a third boolean to indicate whether online information were available
|
||||||
|
@ -186,6 +178,7 @@ def update_package_db(module, pacman_path):
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="could not update package db")
|
module.fail_json(msg="could not update package db")
|
||||||
|
|
||||||
|
|
||||||
def upgrade(module, pacman_path):
|
def upgrade(module, pacman_path):
|
||||||
cmdupgrade = "%s -Suq --noconfirm" % (pacman_path)
|
cmdupgrade = "%s -Suq --noconfirm" % (pacman_path)
|
||||||
cmdneedrefresh = "%s -Qu" % (pacman_path)
|
cmdneedrefresh = "%s -Qu" % (pacman_path)
|
||||||
|
@ -216,6 +209,7 @@ def upgrade(module, pacman_path):
|
||||||
else:
|
else:
|
||||||
module.exit_json(changed=False, msg='Nothing to upgrade', packages=packages)
|
module.exit_json(changed=False, msg='Nothing to upgrade', packages=packages)
|
||||||
|
|
||||||
|
|
||||||
def remove_packages(module, pacman_path, packages):
|
def remove_packages(module, pacman_path, packages):
|
||||||
data = []
|
data = []
|
||||||
diff = {
|
diff = {
|
||||||
|
@ -296,7 +290,7 @@ def install_packages(module, pacman_path, state, packages, package_files):
|
||||||
module.fail_json(msg="failed to install %s: %s" % (" ".join(to_install_repos), stderr))
|
module.fail_json(msg="failed to install %s: %s" % (" ".join(to_install_repos), stderr))
|
||||||
|
|
||||||
data = stdout.split('\n')[3].split(' ')[2:]
|
data = stdout.split('\n')[3].split(' ')[2:]
|
||||||
data = [ i for i in data if i != '' ]
|
data = [i for i in data if i != '']
|
||||||
for i, pkg in enumerate(data):
|
for i, pkg in enumerate(data):
|
||||||
data[i] = re.sub('-[0-9].*$', '', data[i].split('/')[-1])
|
data[i] = re.sub('-[0-9].*$', '', data[i].split('/')[-1])
|
||||||
if module._diff:
|
if module._diff:
|
||||||
|
@ -312,7 +306,7 @@ def install_packages(module, pacman_path, state, packages, package_files):
|
||||||
module.fail_json(msg="failed to install %s: %s" % (" ".join(to_install_files), stderr))
|
module.fail_json(msg="failed to install %s: %s" % (" ".join(to_install_files), stderr))
|
||||||
|
|
||||||
data = stdout.split('\n')[3].split(' ')[2:]
|
data = stdout.split('\n')[3].split(' ')[2:]
|
||||||
data = [ i for i in data if i != '' ]
|
data = [i for i in data if i != '']
|
||||||
for i, pkg in enumerate(data):
|
for i, pkg in enumerate(data):
|
||||||
data[i] = re.sub('-[0-9].*$', '', data[i].split('/')[-1])
|
data[i] = re.sub('-[0-9].*$', '', data[i].split('/')[-1])
|
||||||
if module._diff:
|
if module._diff:
|
||||||
|
@ -328,6 +322,7 @@ def install_packages(module, pacman_path, state, packages, package_files):
|
||||||
|
|
||||||
module.exit_json(changed=False, msg="package(s) already installed. %s" % (message), diff=diff)
|
module.exit_json(changed=False, msg="package(s) already installed. %s" % (message), diff=diff)
|
||||||
|
|
||||||
|
|
||||||
def check_packages(module, pacman_path, packages, state):
|
def check_packages(module, pacman_path, packages, state):
|
||||||
would_be_changed = []
|
would_be_changed = []
|
||||||
diff = {
|
diff = {
|
||||||
|
@ -364,7 +359,7 @@ def expand_package_groups(module, pacman_path, pkgs):
|
||||||
expanded = []
|
expanded = []
|
||||||
|
|
||||||
for pkg in pkgs:
|
for pkg in pkgs:
|
||||||
if pkg: # avoid empty strings
|
if pkg: # avoid empty strings
|
||||||
cmd = "%s -Sgq %s" % (pacman_path, pkg)
|
cmd = "%s -Sgq %s" % (pacman_path, pkg)
|
||||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||||
|
|
||||||
|
@ -382,16 +377,16 @@ def expand_package_groups(module, pacman_path, pkgs):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec=dict(
|
||||||
name = dict(aliases=['pkg', 'package'], type='list'),
|
name=dict(type='list', aliases=['package', 'pkg']),
|
||||||
state = dict(default='present', choices=['present', 'installed', "latest", 'absent', 'removed']),
|
state=dict(type='str', default='present', choices=['absent', 'installed', 'latest', 'present', 'removed']),
|
||||||
recurse = dict(default=False, type='bool'),
|
recurse=dict(type='bool', default=False),
|
||||||
force = dict(default=False, type='bool'),
|
force=dict(type='bool', default=False),
|
||||||
upgrade = dict(default=False, type='bool'),
|
upgrade=dict(type='bool', default=False),
|
||||||
update_cache = dict(default=False, aliases=['update-cache'], type='bool')
|
update_cache=dict(type='bool', default=False, aliases=['update-cache']),
|
||||||
),
|
),
|
||||||
required_one_of = [['name', 'update_cache', 'upgrade']],
|
required_one_of=[['name', 'update_cache', 'upgrade']],
|
||||||
supports_check_mode = True)
|
supports_check_mode=True),
|
||||||
|
|
||||||
pacman_path = module.get_bin_path('pacman', True)
|
pacman_path = module.get_bin_path('pacman', True)
|
||||||
|
|
||||||
|
@ -419,7 +414,7 @@ def main():
|
||||||
|
|
||||||
pkg_files = []
|
pkg_files = []
|
||||||
for i, pkg in enumerate(pkgs):
|
for i, pkg in enumerate(pkgs):
|
||||||
if not pkg: # avoid empty strings
|
if not pkg: # avoid empty strings
|
||||||
continue
|
continue
|
||||||
elif re.match(".*\.pkg\.tar(\.(gz|bz2|xz|lrz|lzo|Z))?$", pkg):
|
elif re.match(".*\.pkg\.tar(\.(gz|bz2|xz|lrz|lzo|Z))?$", pkg):
|
||||||
# The package given is a filename, extract the raw pkg name from
|
# The package given is a filename, extract the raw pkg name from
|
||||||
|
@ -437,8 +432,6 @@ def main():
|
||||||
elif p['state'] == 'absent':
|
elif p['state'] == 'absent':
|
||||||
remove_packages(module, pacman_path, pkgs)
|
remove_packages(module, pacman_path, pkgs)
|
||||||
|
|
||||||
# import module snippets
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -362,7 +362,6 @@ lib/ansible/modules/packaging/os/homebrew_cask.py
|
||||||
lib/ansible/modules/packaging/os/layman.py
|
lib/ansible/modules/packaging/os/layman.py
|
||||||
lib/ansible/modules/packaging/os/macports.py
|
lib/ansible/modules/packaging/os/macports.py
|
||||||
lib/ansible/modules/packaging/os/opkg.py
|
lib/ansible/modules/packaging/os/opkg.py
|
||||||
lib/ansible/modules/packaging/os/pacman.py
|
|
||||||
lib/ansible/modules/packaging/os/pkg5.py
|
lib/ansible/modules/packaging/os/pkg5.py
|
||||||
lib/ansible/modules/packaging/os/pkgin.py
|
lib/ansible/modules/packaging/os/pkgin.py
|
||||||
lib/ansible/modules/packaging/os/pkgng.py
|
lib/ansible/modules/packaging/os/pkgng.py
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue