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)
## Options
|parameter |required |default |choices |comments|
|--- |--- |--- |--- |---|
|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.|
|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_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.|
|parameter |required |default |choices |comments|
|--- |--- |--- |--- |---|
|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.|
|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 |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.|
### Note
* 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:
```
# 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_user: aur_builder

17
aur.py
View File

@ -39,8 +39,9 @@ options:
skip_installed:
description:
- Skip operations if the package is present.
type: bool
Choosing versioned will all you to skip non-VCS (-git, -hg, etc.) packages.
default: no
choices: [ all, versioned, none]
skip_pgp_check:
description:
@ -81,6 +82,8 @@ use_cmd = {
}
# 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):
"""
@ -167,10 +170,12 @@ def install_packages(module, packages, use, skip_installed):
changed_iter = False
for package in packages:
if skip_installed:
if skip_installed in ('all', 'versioned'):
if package_installed(module, package):
rc = 0
continue
vcs = package.endswith(vcs_suffixes)
if skip_installed == 'all' or (skip_installed == 'versioned' and not vcs):
rc = 0
continue
if use == 'makepkg':
rc, out, err = install_with_makepkg(module, package)
else:
@ -206,8 +211,8 @@ def main():
'choices': ['auto', 'aurman', 'pacaur', 'trizen', 'pikaur', 'yaourt', 'yay', 'makepkg'],
},
'skip_installed': {
'default': False,
'type': 'bool',
'default': 'versioned',
'choices': ['all', 'versioned', 'none'],
},
'skip_pgp_check': {
'default': False,