From 6f4cc51023476625d97ed657073b948e8390fa01 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 6 Apr 2011 16:57:01 +0200 Subject: cherry pick -r 504..505 http://bzr.debian.org/apt/python-apt/debian-experimental --- tests/test_aptsources.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'tests/test_aptsources.py') diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index 331df935..aeb2ce31 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -39,11 +39,11 @@ class TestAptSources(unittest.TestCase): apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" "sources.list") sources = aptsources.sourceslist.SourcesList(True, self.templates) - self.assertEqual(len(sources.list), 6) + self.assertEqual(len(sources.list), 9) # test load sources.list = [] sources.load("data/aptsources/sources.list") - self.assertEqual(len(sources.list), 6) + self.assertEqual(len(sources.list), 9) def testSourcesListAdding(self): """aptsources: Test additions to sources.list""" @@ -108,6 +108,21 @@ class TestAptSources(unittest.TestCase): if not s.template: self.fail("source entry '%s' has no matcher" % s) + def testMultiArch(self): + """aptsources: Test multi-arch parsing""" + + apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" + "sources.list") + sources = aptsources.sourceslist.SourcesList(True, self.templates) + + assert sources.list[8].invalid == False + assert sources.list[8].type == "deb" + assert sources.list[8].architectures == ["amd64", "i386"] + assert sources.list[8].uri == "http://de.archive.ubuntu.com/ubuntu/" + assert sources.list[8].dist == "natty" + assert sources.list[8].comps == ["main"] + assert sources.list[8].line.strip() == str(sources.list[8]) + def testDistribution(self): """aptsources: Test distribution detection.""" apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" -- cgit v1.2.3 From b2a0eb7ca6d8db6c8e4ac1875fa41f9466c78384 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 6 Apr 2011 16:58:03 +0200 Subject: cherry pick -r 505..506 http://bzr.debian.org/apt/python-apt/debian-experimental --- aptsources/sourceslist.py | 17 +++++++++++++---- debian/changelog | 1 + tests/test_aptsources.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) (limited to 'tests/test_aptsources.py') diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py index 3cfe1791..85db2de9 100644 --- a/aptsources/sourceslist.py +++ b/aptsources/sourceslist.py @@ -275,12 +275,14 @@ class SourcesList(object): yield entry raise StopIteration - def add(self, type, uri, dist, orig_comps, comment="", pos=-1, file=None): + def add(self, type, uri, dist, orig_comps, comment="", pos=-1, file=None, architectures=[]): """ Add a new source to the sources.list. The method will search for existing matching repos and will try to reuse them as far as possible """ + + architectures = set(architectures) # create a working copy of the component list so that # we can modify it later comps = orig_comps[:] @@ -288,7 +290,8 @@ class SourcesList(object): for source in self.list: if not source.disabled and not source.invalid and \ source.type == type and uri == source.uri and \ - source.dist == dist: + source.dist == dist and \ + set(source.architectures) == architectures: for new_comp in comps: if new_comp in source.comps: # we have this component already, delete it @@ -301,19 +304,25 @@ class SourcesList(object): # components if not source.disabled and not source.invalid and \ source.type == type and uri == source.uri and \ - source.dist == dist: + source.dist == dist and \ + set(source.architectures) == architectures: comps = uniq(source.comps + comps) source.comps = comps return source # if there is a corresponding repo which is disabled, enable it elif source.disabled and not source.invalid and \ source.type == type and uri == source.uri and \ + set(source.architectures) == architectures and \ source.dist == dist and \ len(set(source.comps) & set(comps)) == len(comps): source.disabled = False return source # there isn't any matching source, so create a new line and parse it - line = "%s %s %s" % (type, uri, dist) + + line = type + if architectures: + line += " [arch=%s]" % ",".join(architectures) + line += " %s %s" % (uri, dist) for c in comps: line = line + " " + c if comment != "": diff --git a/debian/changelog b/debian/changelog index 060299e5..cd9c8251 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ python-apt (0.8.0~exp2) UNRELEASED; urgency=low * aptsources: Parse multi-arch sources.list files correctly + * aptsources: Allow insertion of new multi-arch entries -- Julian Andres Klode Wed, 06 Apr 2011 09:46:52 +0200 diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index aeb2ce31..1597674e 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -62,6 +62,14 @@ class TestAptSources(unittest.TestCase): "edgy", ["restricted"]) self.assertTrue(sources.list == before.list) + + before = copy.deepcopy(sources) + sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", + "natty", + ["main"], architectures=["amd64", "i386"]) + self.assertTrue(sources.list == before.list) + + # test to add something new: multiverse sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", "edgy", @@ -74,6 +82,34 @@ class TestAptSources(unittest.TestCase): "multiverse" in entry.comps): found = True self.assertTrue(found) + + # add a new natty entry without architecture specification + sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", + "natty", + ["multiverse"]) + found = False + for entry in sources: + if (entry.type == "deb" and + entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and + entry.dist == "natty" and + entry.architectures == [] and + "multiverse" in entry.comps): + found = True + self.assertTrue(found) + + # Add universe to existing multi-arch line + sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", + "natty", + ["universe"], architectures=["i386", "amd64"]) + found = False + for entry in sources: + if (entry.type == "deb" and + entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and + entry.dist == "natty" and + set(entry.architectures) == set(["amd64", "i386"]) and + set(entry.comps) == set(["main", "universe"])): + found = True + self.assertTrue(found) # test to add something new: multiverse *and* # something that is already there before = copy.deepcopy(sources) -- cgit v1.2.3