diff --git a/packaging/os/apt.py b/packaging/os/apt.py index cafe57eaf15..9b8389ea011 100755 --- a/packaging/os/apt.py +++ b/packaging/os/apt.py @@ -181,9 +181,14 @@ import itertools # APT related constants APT_ENV_VARS = dict( - DEBIAN_FRONTEND = 'noninteractive', - DEBIAN_PRIORITY = 'critical', - LANG = 'C' + DEBIAN_FRONTEND = 'noninteractive', + DEBIAN_PRIORITY = 'critical', + # We screenscrape apt-get and aptitude output for information so we need + # to make sure we use the C locale when running commands + LANG = 'C', + LC_ALL = 'C', + LC_MESSAGES = 'C', + LC_CTYPE = 'C', ) DPKG_OPTIONS = 'force-confdef,force-confold' @@ -388,9 +393,6 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None, else: autoremove = '' - for (k,v) in APT_ENV_VARS.iteritems(): - os.environ[k] = v - if build_dep: cmd = "%s -y %s %s %s build-dep %s" % (APT_GET_CMD, dpkg_options, force_yes, check_arg, packages) else: @@ -455,9 +457,6 @@ def install_deb(m, debs, cache, force, install_recommends, dpkg_options): if force: options += " --force-all" - for (k,v) in APT_ENV_VARS.iteritems(): - os.environ[k] = v - cmd = "dpkg %s -i %s" % (options, " ".join(pkgs_to_install)) rc, out, err = m.run_command(cmd) if "stdout" in retvals: @@ -495,9 +494,6 @@ def remove(m, pkgspec, cache, purge=False, else: purge = '' - for (k,v) in APT_ENV_VARS.iteritems(): - os.environ[k] = v - if autoremove: autoremove = '--auto-remove' else: @@ -546,9 +542,6 @@ def upgrade(m, mode="yes", force=False, default_release=None, apt_cmd_path = m.get_bin_path(apt_cmd, required=True) - for (k,v) in APT_ENV_VARS.iteritems(): - os.environ[k] = v - cmd = '%s -y %s %s %s %s' % (apt_cmd_path, dpkg_options, force_yes, check_arg, upgrade_command) @@ -583,6 +576,8 @@ def main(): supports_check_mode = True ) + module.run_command_environ_update = APT_ENV_VARS + if not HAS_PYTHON_APT: try: module.run_command('apt-get update && apt-get install python-apt -y -q --force-yes', use_unsafe_shell=True, check_rc=True)