diff options
| author | Julian Andres Klode <jak@debian.org> | 2011-04-06 10:09:19 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2011-04-06 10:09:19 +0200 |
| commit | 82bd14484ffa3fbe0b68777402cb31000bd7dd22 (patch) | |
| tree | 70da06b97b1827a86883ef5e1d87842ebb23b1e9 | |
| parent | ef797f74a1948be2231a28786d2c40d047f9c49d (diff) | |
| download | python-apt-82bd14484ffa3fbe0b68777402cb31000bd7dd22.tar.gz | |
aptsources: Parse multi-arch sources.list files correctly
| -rw-r--r-- | aptsources/sourceslist.py | 24 | ||||
| -rw-r--r-- | debian/changelog | 6 | ||||
| -rw-r--r-- | tests/data/aptsources/sources.list | 5 | ||||
| -rw-r--r-- | tests/test_aptsources.py | 19 |
4 files changed, 49 insertions, 5 deletions
diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py index 76bea43a..3cfe1791 100644 --- a/aptsources/sourceslist.py +++ b/aptsources/sourceslist.py @@ -81,6 +81,7 @@ class SourceEntry(object): self.invalid = False # is the source entry valid self.disabled = False # is it disabled ('#' in front) self.type = "" # what type (deb, deb-src) + self.architectures = [] # architectures self.uri = "" # base-uri self.dist = "" # distribution (dapper, edgy, etc) self.comps = [] # list of available componetns @@ -113,7 +114,7 @@ class SourceEntry(object): p_found = False space_found = False for i in range(len(line)): - if line[i] == "[": + if line[i] == "[" and not space_found: p_found=True tmp += line[i] elif line[i] == "]": @@ -169,6 +170,20 @@ class SourceEntry(object): if self.type not in ("deb", "deb-src", "rpm", "rpm-src"): self.invalid = True return + + if pieces[1].strip()[0] == "[": + options = pieces.pop(1).strip("[]").split(";") + for option in options: + try: + key, value = option.split("=", 1) + except Exception: + self.invalid = True + else: + if key == "arch": + self.architectures = value.split(",") + else: + self.invalid = True + # URI self.uri = pieces[1].strip() if len(self.uri) < 1: @@ -204,7 +219,12 @@ class SourceEntry(object): line = "" if self.disabled: line = "# " - line += "%s %s %s" % (self.type, self.uri, self.dist) + + line += self.type + + if self.architectures: + line += " [arch=%s]" % ",".join(self.architectures) + line += " %s %s" % (self.uri, self.dist) if len(self.comps) > 0: line += " " + " ".join(self.comps) if self.comment != "": diff --git a/debian/changelog b/debian/changelog index 6cad29e2..c942278d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +python-apt (0.8.0~exp2) UNRELEASED; urgency=low + + * aptsources: Parse multi-arch sources.list files correctly + + -- Julian Andres Klode <jak@debian.org> Wed, 06 Apr 2011 09:46:52 +0200 + python-apt (0.8.0~exp1) experimental; urgency=low * Disable the old-style API, and break all packages using it diff --git a/tests/data/aptsources/sources.list b/tests/data/aptsources/sources.list index 5481d4f0..376d6961 100644 --- a/tests/data/aptsources/sources.list +++ b/tests/data/aptsources/sources.list @@ -3,4 +3,7 @@ deb http://de.archive.ubuntu.com/ubuntu/ edgy main # comment 2 deb http://de.archive.ubuntu.com/ubuntu/ edgy restricted # comment 3 -deb http://de.archive.ubuntu.com/ubuntu/ edgy universe
\ No newline at end of file +deb http://de.archive.ubuntu.com/ubuntu/ edgy universe + +# multi-arch +deb [arch=amd64,i386] http://de.archive.ubuntu.com/ubuntu/ natty main 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/" |
