summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2010-09-07 13:37:20 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2010-09-07 13:37:20 +0200
commit5498a3d94354732d215e23beeb9c07a47616cabb (patch)
tree1736eb4aa18d8025b688b08be843a8a0338725dc
parentbc301a8f07e50c7a14973b10fa4cb95f7a2beff2 (diff)
parent3aaf50270475e0a2a5fc8e7783e2f8917f8ac327 (diff)
downloadpython-apt-5498a3d94354732d215e23beeb9c07a47616cabb.tar.gz
* add "provides" property to the apt.Version objects
* apt/debfile.py: - fix error when reading binary content and add regresion test * merged patch from Samuel Lidén Borell to fix crash if there utf8 in the control file (LP: #624290) and add test * apt/cache.py: - add "sources_list" parameter to cache.update() to force updating a single sources.list entry only * debian/control: - add missing build-depends on python-debian (needed to run the tests for apt.debfile.DebPackage()
-rw-r--r--apt/cache.py22
-rw-r--r--apt/debfile.py2
-rw-r--r--apt/package.py5
-rw-r--r--debian/changelog17
-rw-r--r--python/cache.cc5
-rw-r--r--tests/data/test-repo/Packages.gzbin0 -> 675 bytes
-rw-r--r--tests/data/test-repo2/Packages.gzbin0 -> 675 bytes
-rw-r--r--tests/data/test_debs/utf8-package_1.0-1_all.debbin0 -> 1150 bytes
-rw-r--r--tests/test_apt_cache.py67
-rw-r--r--tests/test_debfile.py7
10 files changed, 117 insertions, 8 deletions
diff --git a/apt/cache.py b/apt/cache.py
index f64b489a..586df366 100644
--- a/apt/cache.py
+++ b/apt/cache.py
@@ -327,12 +327,14 @@ class Cache(object):
@deprecated_args
def update(self, fetch_progress=None, pulse_interval=0,
- raise_on_error=True):
+ raise_on_error=True, sources_list=None):
"""Run the equivalent of apt-get update.
The first parameter *fetch_progress* may be set to an instance of
apt.progress.FetchProgress, the default is apt.progress.FetchProgress()
.
+ sources_list -- Update a alternative sources.list than the default.
+ Note that the sources.list.d directory is ignored in this case
"""
lockfile = apt_pkg.config.find_dir("Dir::State::Lists") + "lock"
lock = apt_pkg.get_lock(lockfile)
@@ -340,11 +342,23 @@ class Cache(object):
if lock < 0:
raise LockFailedException("Failed to lock %s" % lockfile)
+ if sources_list:
+ old_sources_list = apt_pkg.config.find("Dir::Etc::sourcelist")
+ old_sources_list_d = apt_pkg.config.find("Dir::Etc::sourceparts")
+ old_cleanup = apt_pkg.config.find("APT::List-Cleanup")
+ apt_pkg.config.set("Dir::Etc::sourcelist", os.path.abspath(sources_list))
+ apt_pkg.config.set("Dir::Etc::sourceparts", "xxx")
+ apt_pkg.config.set("APT::List-Cleanup", "0")
+ slist = apt_pkg.SourceList()
+ slist.read_main_list()
+ else:
+ slist = self._list
+
try:
if fetch_progress is None:
fetch_progress = apt.progress.base.AcquireProgress()
try:
- res = self._cache.update(fetch_progress, self._list,
+ res = self._cache.update(fetch_progress, slist,
pulse_interval)
except SystemError, e:
raise FetchFailedException(e)
@@ -354,6 +368,10 @@ class Cache(object):
return res
finally:
os.close(lock)
+ if sources_list:
+ apt_pkg.config.set("Dir::Etc::sourcelist", old_sources_list)
+ apt_pkg.config.set("Dir::Etc::sourceparts", old_sources_list_d)
+ apt_pkg.config.set("APT::List-Cleanup", old_cleanup)
@deprecated_args
def install_archives(self, pm, install_progress):
diff --git a/apt/debfile.py b/apt/debfile.py
index d8159546..7728ed21 100644
--- a/apt/debfile.py
+++ b/apt/debfile.py
@@ -66,7 +66,7 @@ class DebPackage(object):
self._debfile = apt_inst.DebFile(open(self.filename))
control = self._debfile.control.extractdata("control")
# hm, 'replace' is probably better but python2.6 test fail with that
- self._sections = apt_pkg.TagSection(control.decode("UTF-8", 'ignore'))
+ self._sections = apt_pkg.TagSection(control)
self.pkgname = self._sections["Package"]
def __getitem__(self, key):
diff --git a/apt/package.py b/apt/package.py
index 228a3385..871c1e16 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -415,6 +415,11 @@ class Version(object):
return depends_list
@property
+ def provides(self):
+ """ Return a list of names that this version provides."""
+ return [p[0] for p in self._cand.provides_list]
+
+ @property
def enhances(self):
"""Return the list of enhances for the package version."""
return self.get_dependencies("Enhances")
diff --git a/debian/changelog b/debian/changelog
index 44be9f23..afd31ff5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,10 +1,23 @@
-python-apt (0.7.97.2) UNRELEASED; urgency=low
+python-apt (0.7.96ubuntu9) UNRELEASED; urgency=low
[ Kiwinote ]
* apt/debfile:
- don't fail if we conflict with the pkgs we are reinstalling
- -- Michael Vogt <mvo@debian.org> Fri, 27 Aug 2010 11:22:23 +0200
+ [ Michael Vogt ]
+ * add "provides" property to the apt.Version objects
+ * apt/debfile.py:
+ - fix error when reading binary content and add regresion test
+ * merged patch from Samuel Lidén Borell to fix crash if there utf8
+ in the control file (LP: #624290) and add test
+ * apt/cache.py:
+ - add "sources_list" parameter to cache.update() to force updating
+ a single sources.list entry only
+ * debian/control:
+ - add missing build-depends on python-debian (needed to run the
+ tests for apt.debfile.DebPackage()
+
+ -- Michael Vogt <michael.vogt@ubuntu.com> Tue, 07 Sep 2010 13:36:18 +0200
python-apt (0.7.96.1ubuntu8) maverick; urgency=low
diff --git a/python/cache.cc b/python/cache.cc
index e31f6a65..cd51fcc3 100644
--- a/python/cache.cc
+++ b/python/cache.cc
@@ -979,8 +979,9 @@ static PyGetSetDef VersionGetSet[] = {
{"priority_str",VersionGetPriorityStr,0,
"The priority of the package, as a string."},
{"provides_list",VersionGetProvidesList,0,
- "A list of all packages provided by this version. See\n"
- "Package.provides_list for a description of the format."},
+ "A list of all packages provided by this version. The list contains\n"
+ "tuples in the format (providesname, providesver, version)\n"
+ "where 'version' is an apt_pkg.Version object."},
{"section",VersionGetSection,0,
"The section of this package version."},
{"size",VersionGetSize,0,
diff --git a/tests/data/test-repo/Packages.gz b/tests/data/test-repo/Packages.gz
new file mode 100644
index 00000000..81daf2bb
--- /dev/null
+++ b/tests/data/test-repo/Packages.gz
Binary files differ
diff --git a/tests/data/test-repo2/Packages.gz b/tests/data/test-repo2/Packages.gz
new file mode 100644
index 00000000..81daf2bb
--- /dev/null
+++ b/tests/data/test-repo2/Packages.gz
Binary files differ
diff --git a/tests/data/test_debs/utf8-package_1.0-1_all.deb b/tests/data/test_debs/utf8-package_1.0-1_all.deb
new file mode 100644
index 00000000..e0339c2e
--- /dev/null
+++ b/tests/data/test_debs/utf8-package_1.0-1_all.deb
Binary files differ
diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py
index a43e92d2..428060f3 100644
--- a/tests/test_apt_cache.py
+++ b/tests/test_apt_cache.py
@@ -1,6 +1,7 @@
#!/usr/bin/python
#
# Copyright (C) 2010 Julian Andres Klode <jak@debian.org>
+# 2010 Michael Vogt <mvo@ubuntu.com>
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
@@ -15,7 +16,7 @@ sys.path.insert(0, "..")
import apt
import apt_pkg
-
+import shutil
class TestAptCache(unittest.TestCase):
""" test the apt cache """
@@ -50,6 +51,7 @@ class TestAptCache(unittest.TestCase):
# a true virtual pkg
l = cache.get_providing_packages("mail-transport-agent")
self.assertTrue(len(l) > 0)
+ self.assertTrue("postfix" in [p.name for p in l])
# this is a not virtual (transitional) package provided by another
l = cache.get_providing_packages("scrollkeeper")
self.assertEqual(l, [])
@@ -58,6 +60,7 @@ class TestAptCache(unittest.TestCase):
l = cache.get_providing_packages("scrollkeeper",
include_nonvirtual=True)
self.assertTrue(len(l), 1)
+ self.assertTrue("mail-transport-agent" in cache["postfix"].candidate.provides)
def test_dpkg_journal_dirty(self):
@@ -81,7 +84,69 @@ class TestAptCache(unittest.TestCase):
self.assertTrue(cache.dpkg_journal_dirty)
# reset config value
apt_pkg.config.set("Dir::State::status", old_status)
+
+ def test_apt_update(self):
+ rootdir = "./data/tmp"
+ shutil.rmtree(rootdir)
+ try:
+ os.makedirs(os.path.join(rootdir, "var/lib/apt/lists/partial"))
+ except OSError, e:
+ pass
+ state_dir = os.path.join(rootdir, "var/lib/apt")
+ lists_dir = os.path.join(rootdir, "var/lib/apt/lists")
+ apt_pkg.config.set("dir::state", state_dir)
+ # set a local sources.list that does not need the network
+ base_sources = os.path.abspath(os.path.join(rootdir, "sources.list"))
+ apt_pkg.config.set("dir::etc::sourcelist", base_sources)
+ apt_pkg.config.set("dir::etc::sourceparts", "xxx")
+ # main sources.list
+ sources_list = base_sources
+ f=open(sources_list, "w")
+ repo = os.path.abspath("./data/test-repo2")
+ f.write("deb copy:%s /\n" % repo)
+ f.close()
+
+ # test single sources.list fetching
+ sources_list = os.path.join(rootdir, "test.list")
+ f=open(sources_list, "w")
+ repo_dir = os.path.abspath("./data/test-repo")
+ f.write("deb copy:%s /\n" % repo_dir)
+ f.close()
+ self.assertTrue(os.path.exists(sources_list))
+ # write marker to ensure listcleaner is not run
+ open("./data/tmp/var/lib/apt/lists/marker", "w")
+
+ # update a single sources.list
+ cache = apt.Cache()
+ cache.update(sources_list=sources_list)
+ # verify we just got the excpected package file
+ needle_packages = [f for f in os.listdir(lists_dir)
+ if f.endswith("tests_data_test-repo_Packages")]
+ self.assertEqual(len(needle_packages), 1)
+ # verify that we *only* got the Packages file from a single source
+ all_packages = [f for f in os.listdir(lists_dir)
+ if f.endswith("_Packages")]
+ self.assertEqual(needle_packages, all_packages)
+ # verify that the listcleaner was not run and the marker file is
+ # still there
+ self.assertTrue("marker" in os.listdir(lists_dir))
+ # now run update again (without the "normal" sources.list that
+ # contains test-repo2 and verify that we got the normal sources.list
+ cache.update()
+ needle_packages = [f for f in os.listdir(lists_dir)
+ if f.endswith("tests_data_test-repo2_Packages")]
+ self.assertEqual(len(needle_packages), 1)
+ all_packages = [f for f in os.listdir(lists_dir)
+ if f.endswith("_Packages")]
+ self.assertEqual(needle_packages, all_packages)
+
+ # and another update with a single source only
+ cache = apt.Cache()
+ cache.update(sources_list=sources_list)
+ all_packages = [f for f in os.listdir(lists_dir)
+ if f.endswith("_Packages")]
+ self.assertEqual(len(all_packages), 2)
if __name__ == "__main__":
unittest.main()
diff --git a/tests/test_debfile.py b/tests/test_debfile.py
index 42cda6f6..571c2ec9 100644
--- a/tests/test_debfile.py
+++ b/tests/test_debfile.py
@@ -1,4 +1,5 @@
#!/usr/bin/python
+# -*- coding: utf-8 -*-
#
# Copyright (C) 2010 Michael Vogt <mvo@ubuntu.com>
#
@@ -77,6 +78,12 @@ class TestDebfilee(unittest.TestCase):
"Unexpected result for package '%s' (got %s wanted %s)\n%s" % (
filename, res, expected_res, deb._failure_string))
+ def test_utf8_sections(self):
+ deb = apt.debfile.DebPackage(cache=self.cache)
+ deb.open(os.path.join("data","test_debs","utf8-package_1.0-1_all.deb"))
+ self.assertEqual(deb["Maintainer"],
+ "Samuel Lidén Borell <samuel@slbdata.se>")
+
def testContent(self):
# normal
deb = apt.debfile.DebPackage(cache=self.cache)