mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* portage: drop dependency on gentoolkit (provides equery)
Portage installs a Python module, which is available anywhere that
Portage itself is available. We can use that instead of calling a
shell command.
Signed-off-by: John Helmert III <ajak@gentoo.org>
* portage: add knob for emerge's --backtrack flag
Signed-off-by: John Helmert III <ajak@gentoo.org>
* portage: add knob for portage's --with-bdeps option
Also, this option does not accept "True" like other options. Instead,
it only uses 'y' and 'n', so parse booleans properly into these chars.
Signed-off-by: John Helmert III <ajak@gentoo.org>
* Add changelog entry for #5349
Signed-off-by: John Helmert III <ajak@gentoo.org>
Signed-off-by: John Helmert III <ajak@gentoo.org>
(cherry picked from commit 2a54644cfa
)
Co-authored-by: ajakk <jchelmert3@posteo.net>
This commit is contained in:
parent
3751e188ca
commit
22e0a6dac7
2 changed files with 50 additions and 7 deletions
3
changelogs/fragments/5349-drop-gentoolkit-more-knobs.yml
Normal file
3
changelogs/fragments/5349-drop-gentoolkit-more-knobs.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
minor_changes:
|
||||||
|
- portage - use Portage's python module instead of calling gentoolkit-provided program in shell (https://github.com/ansible-collections/community.general/pull/5349).
|
||||||
|
- portage - add knobs for Portage's ``--backtrack`` and ``--with-bdeps`` options (https://github.com/ansible-collections/community.general/pull/5349).
|
|
@ -42,6 +42,12 @@ options:
|
||||||
type: bool
|
type: bool
|
||||||
default: false
|
default: false
|
||||||
|
|
||||||
|
backtrack:
|
||||||
|
description:
|
||||||
|
- Set backtrack value (C(--backtrack)).
|
||||||
|
type: int
|
||||||
|
version_added: 5.8.0
|
||||||
|
|
||||||
deep:
|
deep:
|
||||||
description:
|
description:
|
||||||
- Consider the entire dependency tree of packages (--deep)
|
- Consider the entire dependency tree of packages (--deep)
|
||||||
|
@ -160,6 +166,12 @@ options:
|
||||||
- --load-average setting values
|
- --load-average setting values
|
||||||
type: float
|
type: float
|
||||||
|
|
||||||
|
withbdeps:
|
||||||
|
description:
|
||||||
|
- Specifies that build time dependencies should be installed.
|
||||||
|
type: bool
|
||||||
|
version_added: 5.8.0
|
||||||
|
|
||||||
quietbuild:
|
quietbuild:
|
||||||
description:
|
description:
|
||||||
- Redirect all build output to logs alone, and do not display it
|
- Redirect all build output to logs alone, and do not display it
|
||||||
|
@ -228,11 +240,24 @@ EXAMPLES = '''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||||
|
from ansible.module_utils.common.respawn import has_respawned, respawn_module
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from portage.dbapi import vartree
|
||||||
|
from portage.exception import InvalidAtom
|
||||||
|
HAS_PORTAGE = True
|
||||||
|
PORTAGE_IMPORT_ERROR = None
|
||||||
|
except ImportError:
|
||||||
|
HAS_PORTAGE = False
|
||||||
|
PORTAGE_IMPORT_ERROR = traceback.format_exc()
|
||||||
|
|
||||||
|
|
||||||
def query_package(module, package, action):
|
def query_package(module, package, action):
|
||||||
if package.startswith('@'):
|
if package.startswith('@'):
|
||||||
return query_set(module, package, action)
|
return query_set(module, package, action)
|
||||||
|
@ -240,10 +265,12 @@ def query_package(module, package, action):
|
||||||
|
|
||||||
|
|
||||||
def query_atom(module, atom, action):
|
def query_atom(module, atom, action):
|
||||||
cmd = '%s list %s' % (module.equery_path, atom)
|
vdb = vartree.vardbapi()
|
||||||
|
try:
|
||||||
rc, out, err = module.run_command(cmd)
|
exists = vdb.match(atom)
|
||||||
return rc == 0
|
except InvalidAtom:
|
||||||
|
return False
|
||||||
|
return bool(exists)
|
||||||
|
|
||||||
|
|
||||||
def query_set(module, set, action):
|
def query_set(module, set, action):
|
||||||
|
@ -336,6 +363,8 @@ def emerge_packages(module, packages):
|
||||||
emerge_flags = {
|
emerge_flags = {
|
||||||
'jobs': '--jobs',
|
'jobs': '--jobs',
|
||||||
'loadavg': '--load-average',
|
'loadavg': '--load-average',
|
||||||
|
'backtrack': '--backtrack',
|
||||||
|
'withbdeps': '--with-bdeps',
|
||||||
}
|
}
|
||||||
|
|
||||||
for flag, arg in emerge_flags.items():
|
for flag, arg in emerge_flags.items():
|
||||||
|
@ -351,6 +380,9 @@ def emerge_packages(module, packages):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
"""Add the --flag=value pair."""
|
"""Add the --flag=value pair."""
|
||||||
|
if isinstance(p[flag], bool):
|
||||||
|
args.extend((arg, to_native('y' if flag_val else 'n')))
|
||||||
|
else:
|
||||||
args.extend((arg, to_native(flag_val)))
|
args.extend((arg, to_native(flag_val)))
|
||||||
|
|
||||||
cmd, (rc, out, err) = run_emerge(module, packages, *args)
|
cmd, (rc, out, err) = run_emerge(module, packages, *args)
|
||||||
|
@ -475,6 +507,7 @@ def main():
|
||||||
choices=portage_present_states + portage_absent_states,
|
choices=portage_present_states + portage_absent_states,
|
||||||
),
|
),
|
||||||
update=dict(default=False, type='bool'),
|
update=dict(default=False, type='bool'),
|
||||||
|
backtrack=dict(default=None, type='int'),
|
||||||
deep=dict(default=False, type='bool'),
|
deep=dict(default=False, type='bool'),
|
||||||
newuse=dict(default=False, type='bool'),
|
newuse=dict(default=False, type='bool'),
|
||||||
changed_use=dict(default=False, type='bool'),
|
changed_use=dict(default=False, type='bool'),
|
||||||
|
@ -493,6 +526,7 @@ def main():
|
||||||
keepgoing=dict(default=False, type='bool'),
|
keepgoing=dict(default=False, type='bool'),
|
||||||
jobs=dict(default=None, type='int'),
|
jobs=dict(default=None, type='int'),
|
||||||
loadavg=dict(default=None, type='float'),
|
loadavg=dict(default=None, type='float'),
|
||||||
|
withbdeps=dict(default=None, type='bool'),
|
||||||
quietbuild=dict(default=False, type='bool'),
|
quietbuild=dict(default=False, type='bool'),
|
||||||
quietfail=dict(default=False, type='bool'),
|
quietfail=dict(default=False, type='bool'),
|
||||||
),
|
),
|
||||||
|
@ -506,8 +540,14 @@ def main():
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not HAS_PORTAGE:
|
||||||
|
if sys.executable != '/usr/bin/python' and not has_respawned():
|
||||||
|
respawn_module('/usr/bin/python')
|
||||||
|
else:
|
||||||
|
module.fail_json(msg=missing_required_lib('portage'),
|
||||||
|
exception=PORTAGE_IMPORT_ERROR)
|
||||||
|
|
||||||
module.emerge_path = module.get_bin_path('emerge', required=True)
|
module.emerge_path = module.get_bin_path('emerge', required=True)
|
||||||
module.equery_path = module.get_bin_path('equery', required=True)
|
|
||||||
|
|
||||||
p = module.params
|
p = module.params
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue