Skip to content

Commit

Permalink
add check_mode for upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
kewlfft committed Aug 8, 2020
1 parent 5aebeda commit c2fd7b3
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions library/aur.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ def install_with_makepkg(module, package, extra_args, skip_pgp_check, ignore_arc
return (rc, out, err)


def check_upgrade(module, use):
"""
Inform user how many packages would be upgraded
"""
rc, stdout, stderr = module.run_command([use, '-Qu'], check_rc=True)
data = stdout.split('\n')
data.remove('')
module.exit_json(
changed=len(data) > 0,
msg="{} package(s) would be upgraded".format(len(data)),
helper=use,
)


def upgrade(module, use, extra_args, aur_only):
"""
Upgrade the whole system
Expand Down Expand Up @@ -296,12 +310,16 @@ def make_module():
def apply_module(module, use):
params = module.params

if module.check_mode:
check_packages(module, params['name'])
elif params.get('upgrade', False):
upgrade(module, use, params['extra_args'], params['aur_only'])
if params.get('upgrade', False):
if module.check_mode:
check_upgrade(module, use)
else:
upgrade(module, use, params['extra_args'], params['aur_only'])
else:
install_packages(module, params['name'], use, params['extra_args'], params['state'], params['skip_pgp_check'], params['ignore_arch'], params['aur_only'])
if module.check_mode:
check_packages(module, params['name'])
else:
install_packages(module, params['name'], use, params['extra_args'], params['state'], params['skip_pgp_check'], params['ignore_arch'], params['aur_only'])


def main():
Expand Down

0 comments on commit c2fd7b3

Please sign in to comment.