mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Python 3 fixes for apt_* modules. (#4754)
This commit is contained in:
parent
d339004437
commit
e8f70f25df
3 changed files with 7 additions and 5 deletions
|
@ -198,6 +198,8 @@ import datetime
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
# APT related constants
|
# APT related constants
|
||||||
APT_ENV_VARS = dict(
|
APT_ENV_VARS = dict(
|
||||||
DEBIAN_FRONTEND = 'noninteractive',
|
DEBIAN_FRONTEND = 'noninteractive',
|
||||||
|
@ -372,7 +374,7 @@ def expand_pkgspec_from_fnmatches(m, pkgspec, cache):
|
||||||
return new_pkgspec
|
return new_pkgspec
|
||||||
|
|
||||||
def parse_diff(output):
|
def parse_diff(output):
|
||||||
diff = output.splitlines()
|
diff = to_native(output).splitlines()
|
||||||
try:
|
try:
|
||||||
# check for start marker from aptitude
|
# check for start marker from aptitude
|
||||||
diff_start = diff.index('Resolving dependencies...')
|
diff_start = diff.index('Resolving dependencies...')
|
||||||
|
@ -385,7 +387,7 @@ def parse_diff(output):
|
||||||
diff_start = -1
|
diff_start = -1
|
||||||
try:
|
try:
|
||||||
# check for end marker line from both apt-get and aptitude
|
# check for end marker line from both apt-get and aptitude
|
||||||
diff_end = (i for i, item in enumerate(diff) if re.match('[0-9]+ (packages )?upgraded', item)).next()
|
diff_end = next(i for i, item in enumerate(diff) if re.match('[0-9]+ (packages )?upgraded', item))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
diff_end = len(diff)
|
diff_end = len(diff)
|
||||||
diff_start += 1
|
diff_start += 1
|
||||||
|
@ -475,7 +477,7 @@ def get_field_of_deb(m, deb_file, field="Version"):
|
||||||
rc, stdout, stderr = m.run_command(cmd)
|
rc, stdout, stderr = m.run_command(cmd)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
m.fail_json(msg="%s failed" % cmd, stdout=stdout, stderr=stderr)
|
m.fail_json(msg="%s failed" % cmd, stdout=stdout, stderr=stderr)
|
||||||
return stdout.strip('\n')
|
return to_native(stdout).strip('\n')
|
||||||
|
|
||||||
def install_deb(m, debs, cache, force, install_recommends, allow_unauthenticated, dpkg_options):
|
def install_deb(m, debs, cache, force, install_recommends, allow_unauthenticated, dpkg_options):
|
||||||
changed=False
|
changed=False
|
||||||
|
|
|
@ -130,7 +130,7 @@ def all_keys(module, keyring, short_format):
|
||||||
cmd = "apt-key adv --list-public-keys --keyid-format=long"
|
cmd = "apt-key adv --list-public-keys --keyid-format=long"
|
||||||
(rc, out, err) = module.run_command(cmd)
|
(rc, out, err) = module.run_command(cmd)
|
||||||
results = []
|
results = []
|
||||||
lines = out.split('\n')
|
lines = to_native(out).split('\n')
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith("pub") or line.startswith("sub"):
|
if line.startswith("pub") or line.startswith("sub"):
|
||||||
tokens = line.split()
|
tokens = line.split()
|
||||||
|
|
|
@ -374,7 +374,7 @@ class UbuntuSourcesList(SourcesList):
|
||||||
response, info = fetch_url(self.module, lp_api, headers=headers)
|
response, info = fetch_url(self.module, lp_api, headers=headers)
|
||||||
if info['status'] != 200:
|
if info['status'] != 200:
|
||||||
self.module.fail_json(msg="failed to fetch PPA information, error was: %s" % info['msg'])
|
self.module.fail_json(msg="failed to fetch PPA information, error was: %s" % info['msg'])
|
||||||
return json.load(response)
|
return json.loads(to_native(response.read()))
|
||||||
|
|
||||||
def _expand_ppa(self, path):
|
def _expand_ppa(self, path):
|
||||||
ppa = path.split(':')[1]
|
ppa = path.split(':')[1]
|
||||||
|
|
Loading…
Reference in a new issue