urpmi: PEP8 compliancy and documentation changes (#33560)

This PR includes:
- PEP8 compliancy changes
- Documentation changes
This commit is contained in:
Dag Wieers 2017-12-05 09:32:58 +01:00 committed by ansibot
parent 95044d69c7
commit aec8e7784a
2 changed files with 42 additions and 47 deletions

View file

@ -1,21 +1,19 @@
#!/usr/bin/python -tt
# -*- coding: utf-8 -*-
# (c) 2013, Philippe Makowski
# Copyright: (c) 2013, Philippe Makowski
# Written by Philippe Makowski <philippem@mageia.org>
# Based on apt module written by Matthew Williams <matthew@flowroute.com>
#
# 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
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: urpmi
@ -26,77 +24,73 @@ version_added: "1.3.4"
options:
pkg:
description:
- name of package to install, upgrade or remove.
required: true
default: null
- Name of package to install, upgrade or remove.
required: yes
state:
description:
- Indicates the desired package state
required: false
- Indicates the desired package state.
choices: [ absent, present ]
default: present
choices: [ "absent", "present" ]
update_cache:
description:
- update the package database first C(urpmi.update -a).
required: false
default: no
choices: [ "yes", "no" ]
- Update the package database first C(urpmi.update -a).
type: bool
default: 'no'
no-recommends:
description:
- Corresponds to the C(--no-recommends) option for I(urpmi).
required: false
default: yes
choices: [ "yes", "no" ]
type: bool
default: 'yes'
force:
description:
- Assume "yes" is the answer to any question urpmi has to ask.
Corresponds to the C(--force) option for I(urpmi).
required: false
default: yes
choices: [ "yes", "no" ]
type: bool
default: 'yes'
root:
description:
- Specifies an alternative install root, relative to which all packages will be installed.
Corresponds to the C(--root) option for I(urpmi).
required: false
default: "/"
default: /
version_added: "2.4"
aliases: [ "installroot" ]
author: "Philippe Makowski (@pmakowski)"
notes: []
aliases: [ installroot ]
author:
- Philippe Makowski (@pmakowski)
'''
EXAMPLES = '''
# install package foo
- urpmi:
- name: Install package foo
urpmi:
pkg: foo
state: present
# remove package foo
- urpmi:
- name: Remove package foo
urpmi:
pkg: foo
state: absent
# description: remove packages foo and bar
- urpmi:
- name: Remove packages foo and bar
urpmi:
pkg: foo,bar
state: absent
# description: update the package database (urpmi.update -a -q) and install bar (bar will be the updated if a newer version exists)
- name: Update the package database (urpmi.update -a -q) and install bar (bar will be the updated if a newer version exists)
- urpmi:
name: bar
state: present
update_cache: yes
'''
import shlex
import os
import shlex
import sys
from ansible.module_utils.basic import AnsibleModule
URPMI_PATH = '/usr/sbin/urpmi'
URPME_PATH = '/usr/sbin/urpme'
def query_package(module, name, root):
# rpm -q returns 0 if the package is installed,
# 1 if it is not installed
@ -107,6 +101,7 @@ def query_package(module, name, root):
else:
return False
def query_package_provides(module, name, root):
# rpm -q returns 0 if the package is installed,
# 1 if it is not installed
@ -181,22 +176,25 @@ def install_packages(module, pkgspec, root, force=True, no_recommends=True):
else:
module.exit_json(changed=False)
def root_option(root):
if (root):
return "--root=%s" % (root)
else:
return ""
def main():
module = AnsibleModule(
argument_spec = dict(
state = dict(default='installed', choices=['installed', 'removed', 'absent', 'present']),
update_cache = dict(default=False, aliases=['update-cache'], type='bool'),
force = dict(default=True, type='bool'),
no_recommends = dict(default=True, aliases=['no-recommends'], type='bool'),
package = dict(aliases=['pkg', 'name'], required=True),
root = dict(aliases=['installroot'])))
argument_spec=dict(
state=dict(type='str', default='installed', choices=['absent', 'installed', 'present', 'removed']),
update_cache=dict(type='bool', default=False, aliases=['update-cache']),
force=dict(type='bool', default=True),
no_recommends=dict(type='bool', default=True, aliases=['no-recommends']),
package=dict(type='str', required=True, aliases=['name', 'pkg']),
root=dict(type='str', aliases=['installroot']),
),
)
if not os.path.exists(URPMI_PATH):
module.fail_json(msg="cannot find urpmi, looking for %s" % (URPMI_PATH))
@ -212,14 +210,12 @@ def main():
packages = p['package'].split(',')
if p['state'] in [ 'installed', 'present' ]:
if p['state'] in ['installed', 'present']:
install_packages(module, packages, root, force_yes, no_recommends_yes)
elif p['state'] in [ 'removed', 'absent' ]:
elif p['state'] in ['removed', 'absent']:
remove_packages(module, packages, root)
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()

View file

@ -273,7 +273,6 @@ lib/ansible/modules/packaging/os/portinstall.py
lib/ansible/modules/packaging/os/sorcery.py
lib/ansible/modules/packaging/os/svr4pkg.py
lib/ansible/modules/packaging/os/swdepot.py
lib/ansible/modules/packaging/os/urpmi.py
lib/ansible/modules/packaging/os/zypper.py
lib/ansible/modules/packaging/os/zypper_repository.py
lib/ansible/modules/storage/infinidat/infini_export.py