From 08c4dd6fbdfe44516d7e516f33b244b39a94ebd9 Mon Sep 17 00:00:00 2001 From: kewl fft Date: Sat, 23 May 2020 22:28:10 -0400 Subject: [PATCH] replace skip_installed by state --- README.md | 5 ++--- library/aur.py | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 3500a2a..fdd380b 100644 --- a/README.md +++ b/README.md @@ -15,16 +15,15 @@ The following helpers are supported and automatically selected, if present, in t |parameter |required |default |choices |comments| |--- |--- |--- |--- |---| |name |no | | |Name or list of names of the package(s) to install or upgrade.| +|state |no |present |present, latest |Present skips operations if the package is present.| |upgrade |no |no |yes, no |Whether or not to upgrade whole system.| |use |no |auto |auto, yay, pacaur, trizen, pikaur, aurman, 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.| |aur_only |no |no |yes, no |Limit operation to the AUR. Compatible with yay, pacaur, aurman and trizen.| |skip_pgp_check |no |no |yes, no |Only valid with makepkg. Skip PGP signatures verification of source file, useful when installing packages without GnuPG properly configured.| |ignore_arch |no |no |yes, no |Only valid with makepkg. Ignore a missing or incomplete arch field, useful when the PKGBUILD does not have the arch=('yourarch') field.| ### Note * Either *name* or *upgrade* is required, both cannot be used together. -* *skip_installed* cannot be used with *upgrade*. * In the *use*=*auto* mode, makepkg is used as a fallback if no known helper is found. ## Installing @@ -75,7 +74,7 @@ dependencies: 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 state=present become: yes become_user: aur_builder diff --git a/library/aur.py b/library/aur.py index da99f91..fa5a3d6 100644 --- a/library/aur.py +++ b/library/aur.py @@ -25,6 +25,12 @@ options: description: - Name or list of names of the package(s) to install or upgrade. + state: + description: + - Desired state of the package. + default: present + choices: [ present, latest ] + upgrade: description: - Whether or not to upgrade whole system. @@ -37,12 +43,6 @@ options: default: auto choices: [ auto, yay, pacaur, trizen, pikaur, aurman, makepkg ] - skip_installed: - description: - - Skip operations if the package is present. - type: bool - default: no - skip_pgp_check: description: - Only valid with makepkg. @@ -75,7 +75,7 @@ helper: EXAMPLES = ''' - name: Install trizen using makepkg, skip if trizen is already installed - aur: name=trizen use=makepkg skip_installed=true + aur: name=trizen use=makepkg state=present become: yes become_user: aur_builder ''' @@ -173,7 +173,7 @@ def upgrade(module, use, aur_only): ) -def install_packages(module, packages, use, skip_installed, aur_only): +def install_packages(module, packages, use, state, aur_only): """ Install the specified packages """ @@ -182,7 +182,7 @@ def install_packages(module, packages, use, skip_installed, aur_only): changed_iter = False for package in packages: - if skip_installed: + if state == "present": if package_installed(module, package): rc = 0 continue @@ -209,6 +209,10 @@ def main(): 'name': { 'type': 'list', }, + 'state': { + 'default': 'present', + 'choices': ['present', 'latest'], + }, 'ignore_arch': { 'default': False, 'type': 'bool', @@ -221,10 +225,6 @@ def main(): 'default': 'auto', 'choices': ['auto'] + list(use_cmd.keys()), }, - 'skip_installed': { - 'default': False, - 'type': 'bool', - }, 'skip_pgp_check': { 'default': False, 'type': 'bool', @@ -253,13 +253,13 @@ def main(): else: use = params['use'] - if params['upgrade'] and (params['name'] or params['skip_installed'] or use == 'makepkg'): + if params['upgrade'] and (params['name'] or use == 'makepkg'): module.fail_json(msg="Upgrade cannot be used with this option.") else: if params['upgrade']: upgrade(module, use, params['aur_only']) else: - install_packages(module, params['name'], use, params['skip_installed'], params['aur_only']) + install_packages(module, params['name'], use, params['state'], params['aur_only']) if __name__ == '__main__':