summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2012-06-25 14:23:10 +0200
committerJulian Andres Klode <jak@debian.org>2012-06-25 14:23:10 +0200
commitb50494275b8235e5c8a53e13fd56e3cea1c8d5b3 (patch)
treede758f4c2a59db946b0e524bd9757fe9be277cc2
parent0b90448722f7d00f01186267ba247117caf406ec (diff)
downloadpython-apt-b50494275b8235e5c8a53e13fd56e3cea1c8d5b3.tar.gz
* apt/auth.py:
- Use tempfile.NamedTemporaryFile to create temporary file
-rw-r--r--apt/auth.py52
-rw-r--r--debian/changelog4
2 files changed, 31 insertions, 25 deletions
diff --git a/apt/auth.py b/apt/auth.py
index 38c4bdc6..1a81d3b0 100644
--- a/apt/auth.py
+++ b/apt/auth.py
@@ -51,38 +51,40 @@ class TrustedKey(object):
def _call_apt_key_script(*args, **kwargs):
"""Run the apt-key script with the given arguments."""
+ conf = None
cmd = [apt_pkg.config.find_file("Dir::Bin::Apt-Key", "/usr/bin/apt-key")]
cmd.extend(args)
env = os.environ.copy()
env["LANG"] = "C"
- if apt_pkg.config.find_dir("Dir") != "/":
- # If the key is to be installed into a chroot we have to export the
- # configuration from the chroot to the apt-key script by using
- # a temporary APT_CONFIG file. The apt-key script uses apt-config shell
- # internally
- conf_fd, conf_name = tempfile.mkstemp(prefix="apt-key", suffix="conf")
- atexit.register(os.remove, conf_name)
+ try:
+ if apt_pkg.config.find_dir("Dir") != "/":
+ # If the key is to be installed into a chroot we have to export the
+ # configuration from the chroot to the apt-key script by using
+ # a temporary APT_CONFIG file. The apt-key script uses apt-config
+ # shell internally
+ conf = tempfile.NamedTemporaryFile(prefix="apt-key", suffix=".conf")
+ conf.write(apt_pkg.config.dump().encode("UTF-8"))
+ conf.flush()
+ env["APT_CONFIG"] = conf.name
+ proc = subprocess.Popen(cmd, env=env, universal_newlines=True,
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
try:
- os.write(conf_fd, apt_pkg.config.dump().encode("UTF-8"))
+ proc.stdin.write(kwargs["stdin"])
+ except KeyError:
+ pass
finally:
- os.close(conf_fd)
- env["APT_CONFIG"] = conf_name
- proc = subprocess.Popen(cmd, env=env, universal_newlines=True,
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
- try:
- proc.stdin.write(kwargs["stdin"])
- except KeyError:
- pass
+ proc.stdin.close()
+ return_code = proc.wait()
+ output = proc.stdout.read()
+ if return_code:
+ raise SystemError("The apt-key script failed with return code %s:\n"
+ "%s\n%s" % (return_code, " ".join(cmd), output))
+ return output.strip()
finally:
- proc.stdin.close()
- return_code = proc.wait()
- output = proc.stdout.read()
- if return_code:
- raise SystemError("The apt-key script failed with return code %s:\n"
- "%s\n%s" % (return_code, " ".join(cmd), output))
- return output.strip()
+ if conf is not None:
+ conf.close()
def add_key_from_file(filename):
"""Import a GnuPG key file to trust repositores signed by it.
diff --git a/debian/changelog b/debian/changelog
index ffb6a2b4..e6d6d648 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,10 @@ python-apt (0.8.6) UNRELEASED; urgency=low
- add build-dep for apt (>= 0.9.6) to make test_auth.py test
work reliable
+ [ Julian Andres Klode ]
+ * apt/auth.py:
+ - Use tempfile.NamedTemporaryFile to create temporary file
+
-- Michael Vogt <mvo@debian.org> Mon, 25 Jun 2012 13:41:02 +0200
python-apt (0.8.5) unstable; urgency=low