diff options
| author | Sebastian Heinlein <devel@glatzor.de> | 2012-06-05 15:07:49 +0200 |
|---|---|---|
| committer | Sebastian Heinlein <devel@glatzor.de> | 2012-06-05 15:07:49 +0200 |
| commit | 6dede8b69926de6c72ff9d21e39570081cba7b41 (patch) | |
| tree | f0314c312e3428fe63180de588f59e7bb9552a72 | |
| parent | 56be4293b0e639b58904d1d86dd46f8767d36728 (diff) | |
| parent | a8ec7c4c6430e69953ea8f8f3925d1b0fb4ac63a (diff) | |
| download | python-apt-6dede8b69926de6c72ff9d21e39570081cba7b41.tar.gz | |
Merge mvos enhancements
| -rw-r--r-- | apt/auth.py | 21 | ||||
| -rw-r--r-- | tests/test_auth.py | 6 |
2 files changed, 19 insertions, 8 deletions
diff --git a/apt/auth.py b/apt/auth.py index 024f01da..d8c602fa 100644 --- a/apt/auth.py +++ b/apt/auth.py @@ -7,11 +7,11 @@ # Author: Michael Vogt <mvo@debian.org> # Sebastian Heinlein <devel@glatzor.de> # -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -36,8 +36,7 @@ from apt_pkg import gettext as _ # Create a temporary dir to store secret keying and trust database. # APT doesn't use a secrect key ring but GnuPG fails without it. -_TMPDIR = tempfile.mkdtemp() -atexit.register(shutil.rmtree, _TMPDIR) +_TMPDIR = None class TrustedKey(object): @@ -57,6 +56,10 @@ class TrustedKey(object): def _get_gpg_command(keyring=None): """Return the gpg command""" + global _TMPDIR + if _TMPDIR is None: + _TMPDIR = tempfile.mkdtemp() + atexit.register(shutil.rmtree, _TMPDIR) cmd = [apt_pkg.config.find_file("Dir::Bin::Gpg", "/usr/bin/gpg"), "--ignore-time-conflict", "--no-default-keyring", @@ -84,6 +87,7 @@ def _get_gpg_command(keyring=None): "--trustdb-name", os.path.join(_TMPDIR, "trustdb.gpg")]) return cmd + def _wait_and_raise(proc): """Wait until the given subprocess is completed and raise a SystemError if it failed. @@ -92,6 +96,7 @@ def _wait_and_raise(proc): output = proc.stdout.read() raise SystemError("GnuPG command failed: %s" % output) + def add_key_from_file(filename, wait=True): """Import a GnuPG key file to trust repositores signed by it. @@ -115,6 +120,7 @@ def add_key_from_file(filename, wait=True): else: return proc + def add_key_from_keyserver(keyid, keyserver, wait=True): """Import a GnuPG key file to trust repositores signed by it. @@ -137,6 +143,7 @@ def add_key_from_keyserver(keyid, keyserver, wait=True): else: return proc + def add_key(content, wait=True): """Import a GnuPG key to trust repositores signed by it. @@ -159,6 +166,7 @@ def add_key(content, wait=True): else: return proc + def remove_key(fingerprint, wait=True): """Remove a GnuPG key to no longer trust repositores signed by it. @@ -178,6 +186,7 @@ def remove_key(fingerprint, wait=True): else: return proc + def export_key(fingerprint, wait=True): """Return the GnuPG key in text format. @@ -198,6 +207,7 @@ def export_key(fingerprint, wait=True): else: return proc + def list_keys(): """Returns a list of TrustedKey instances for each key which is used to trust repositories. @@ -216,6 +226,7 @@ def list_keys(): res.append(key) return res + if __name__ == "__main__": # Add some known keys we would like to see translated so that they get # picked up by gettext diff --git a/tests/test_auth.py b/tests/test_auth.py index e9906f56..7ecebb7b 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -125,9 +125,9 @@ class TestAuthKeys(unittest.TestCase): os.makedirs(trustedparts_dir) def _restore_apt_config(self, cnf): - """Restore previous apt configuration.""" - for item in cnf: - apt_pkg.config.set(item, cnf[item]) + """Restore previous apt configuration.""" + for item in cnf: + apt_pkg.config.set(item, cnf[item]) def testAddAndExportKey(self): """Add an example key.""" |
