Make skip_installed an enum instead of boolean

With these changes skip_installed allows you to skip 'all', 'versioned' (non-vcs) or 'none'

Fixes #9
pull/10/head
Jamie Magee 2018-07-06 14:52:37 +02:00
parent 2df576955a
commit 7be9a67264
2 changed files with 19 additions and 14 deletions

View File

@ -12,13 +12,13 @@ makepkg will be used if no helper was found or if it's specified explicitly.
- [makepkg](https://wiki.archlinux.org/index.php/makepkg) - [makepkg](https://wiki.archlinux.org/index.php/makepkg)
## Options ## Options
|parameter |required |default |choices |comments| |parameter |required |default |choices |comments|
|--- |--- |--- |--- |---| |--- |--- |--- |--- |---|
|name |no | | |Name or list of names of the package(s) to install or upgrade.| |name |no | | |Name or list of names of the package(s) to install or upgrade.|
|upgrade |no |no |yes, no |Whether or not to upgrade whole system.| |upgrade |no |no |yes, no |Whether or not to upgrade whole system.|
|use |no |auto |auto, aurman, pacaur, trizen, pikaur, yay, makepkg |The helper to use, 'auto' uses the first known helper found and makepkg as a fallback.| |use |no |auto |auto, aurman, pacaur, trizen, pikaur, yay, makepkg |The helper to use, 'auto' uses the first known helper found and makepkg as a fallback.|
|skip_installed |no |no |yes, no |Skip operations if the package is present.| |skip_installed |no |versioned|all, versioned, none |Skip operations if the package is present. Choosing versioned will all you to skip non-VCS (-git, -hg, etc.) packages.|
|skip_pgp_check |no |no |yes, no |Skip verification of PGP signatures. This is useful when installing packages on a host without GnuPG (properly) configured. Only valid with makepkg.| |skip_pgp_check |no |no |yes, no |Skip verification of PGP signatures. This is useful when installing packages on a host without GnuPG (properly) configured. Only valid with makepkg.|
### Note ### Note
* Either *name* or *upgrade* is required, both cannot be used together. * Either *name* or *upgrade* is required, both cannot be used together.
@ -45,7 +45,7 @@ git clone https://github.com/kewlfft/ansible-aur.git ~/.ansible/plugins/modules/
Use it in a task, as in the following examples: Use it in a task, as in the following examples:
``` ```
# Install trizen using makepkg, skip if trizen is already installed # Install trizen using makepkg, skip if trizen is already installed
- aur: name=trizen use=makepkg skip_installed=true - aur: name=trizen use=makepkg skip_installed=all
become: yes become: yes
become_user: aur_builder become_user: aur_builder

17
aur.py
View File

@ -39,8 +39,9 @@ options:
skip_installed: skip_installed:
description: description:
- Skip operations if the package is present. - Skip operations if the package is present.
type: bool Choosing versioned will all you to skip non-VCS (-git, -hg, etc.) packages.
default: no default: no
choices: [ all, versioned, none]
skip_pgp_check: skip_pgp_check:
description: description:
@ -81,6 +82,8 @@ use_cmd = {
} }
# optional: aurman, pacaur, trizen have a --aur option, do things only for aur # optional: aurman, pacaur, trizen have a --aur option, do things only for aur
# From https://wiki.archlinux.org/index.php/VCS_package_guidelines
vcs_suffixes = ('-git', '-bzr', '-darcs', '-hg', '-svn', '-cvs')
def package_installed(module, package): def package_installed(module, package):
""" """
@ -167,10 +170,12 @@ def install_packages(module, packages, use, skip_installed):
changed_iter = False changed_iter = False
for package in packages: for package in packages:
if skip_installed: if skip_installed in ('all', 'versioned'):
if package_installed(module, package): if package_installed(module, package):
rc = 0 vcs = package.endswith(vcs_suffixes)
continue if skip_installed == 'all' or (skip_installed == 'versioned' and not vcs):
rc = 0
continue
if use == 'makepkg': if use == 'makepkg':
rc, out, err = install_with_makepkg(module, package) rc, out, err = install_with_makepkg(module, package)
else: else:
@ -206,8 +211,8 @@ def main():
'choices': ['auto', 'aurman', 'pacaur', 'trizen', 'pikaur', 'yaourt', 'yay', 'makepkg'], 'choices': ['auto', 'aurman', 'pacaur', 'trizen', 'pikaur', 'yaourt', 'yay', 'makepkg'],
}, },
'skip_installed': { 'skip_installed': {
'default': False, 'default': 'versioned',
'type': 'bool', 'choices': ['all', 'versioned', 'none'],
}, },
'skip_pgp_check': { 'skip_pgp_check': {
'default': False, 'default': False,