diff options
| author | Julian Andres Klode <jak@debian.org> | 2013-10-21 20:20:22 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2013-10-21 20:20:33 +0200 |
| commit | 8a67219266605b39a522aee08bf7cd3b0b6c3a8c (patch) | |
| tree | fe6fcb3ca511d9573e9c2e4320af72c7e1d70734 | |
| parent | abc9feb18b268cbc4ddb79aabb30ce352e31b44a (diff) | |
| download | python-apt-8a67219266605b39a522aee08bf7cd3b0b6c3a8c.tar.gz | |
aptsources: Correctly parse multiple options (LP: #1103200)
It's still not optimal and we do not support the arch+ and arch-
options, but it's a beginning.
| -rw-r--r-- | aptsources/sourceslist.py | 23 | ||||
| -rw-r--r-- | debian/changelog | 1 | ||||
| -rw-r--r-- | tests/data/aptsources/sources.list | 1 | ||||
| -rw-r--r-- | tests/test_aptsources.py | 21 |
4 files changed, 39 insertions, 7 deletions
diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py index 43729246..69e7e107 100644 --- a/aptsources/sourceslist.py +++ b/aptsources/sourceslist.py @@ -91,6 +91,7 @@ class SourceEntry(object): self.disabled = False # is it disabled ('#' in front) self.type = "" # what type (deb, deb-src) self.architectures = [] # architectures + self.trusted = None # Trusted self.uri = "" # base-uri self.dist = "" # distribution (dapper, edgy, etc) self.comps = [] # list of available componetns @@ -123,9 +124,15 @@ class SourceEntry(object): p_found = False space_found = False for i in range(len(line)): - if line[i] == "[" and not space_found: - p_found=True - tmp += line[i] + if line[i] == "[": + if space_found: + space_found = False + p_found = True + pieces.append(tmp) + tmp = line[i] + else: + p_found=True + tmp += line[i] elif line[i] == "]": p_found=False tmp += line[i] @@ -181,7 +188,7 @@ class SourceEntry(object): return if pieces[1].strip()[0] == "[": - options = pieces.pop(1).strip("[]").split(";") + options = pieces.pop(1).strip("[]").split() for option in options: try: key, value = option.split("=", 1) @@ -190,6 +197,8 @@ class SourceEntry(object): else: if key == "arch": self.architectures = value.split(",") + elif key == "trusted": + self.trusted = apt_pkg.string_to_bool(value) else: self.invalid = True @@ -231,7 +240,11 @@ class SourceEntry(object): line += self.type - if self.architectures: + if self.architectures and self.trusted is not None: + line += " [arch=%s trusted=%s]" % (",".join(self.architectures), "yes" if self.trusted else "no") + elif self.trusted is not None: + line += " [trusted=%s]" % ("yes" if self.trusted else "no") + elif self.architectures: line += " [arch=%s]" % ",".join(self.architectures) line += " %s %s" % (self.uri, self.dist) if len(self.comps) > 0: diff --git a/debian/changelog b/debian/changelog index f1e40039..51f2b8b7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,7 @@ python-apt (0.9.0) UNRELEASED; urgency=low * Accept bytes object for file names (Closes: #680971) * aptsources/sourceslist.py - Document correct use of uniq and hide it using __all__ (Closes: #723815) + - Correctly parse multiple options (LP: #1103200) * python/apt_pkgmodule.cc: - Fix documentation of version_compare (Closes: #680891) * python/cache.cc: diff --git a/tests/data/aptsources/sources.list b/tests/data/aptsources/sources.list index 376d6961..8ca68075 100644 --- a/tests/data/aptsources/sources.list +++ b/tests/data/aptsources/sources.list @@ -7,3 +7,4 @@ deb http://de.archive.ubuntu.com/ubuntu/ edgy universe # multi-arch deb [arch=amd64,i386] http://de.archive.ubuntu.com/ubuntu/ natty main +deb [arch=amd64,i386 trusted=yes] http://de.archive.ubuntu.com/ubuntu/ natty main diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index 75dd91c1..5a174f3b 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -40,11 +40,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), 9) + self.assertEqual(len(sources.list), 10) # test load sources.list = [] sources.load("data/aptsources/sources.list") - self.assertEqual(len(sources.list), 9) + self.assertEqual(len(sources.list), 10) def testSourcesListAdding(self): """aptsources: Test additions to sources.list""" @@ -159,6 +159,23 @@ class TestAptSources(unittest.TestCase): assert sources.list[8].dist == "natty" assert sources.list[8].comps == ["main"] assert sources.list[8].line.strip() == str(sources.list[8]) + assert sources.list[8].trusted is None + + def testMultipleOptions(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[9].invalid == False + assert sources.list[9].type == "deb" + assert sources.list[9].architectures == ["amd64", "i386"] + self.assertEqual( sources.list[9].uri, "http://de.archive.ubuntu.com/ubuntu/") + assert sources.list[9].dist == "natty" + assert sources.list[9].comps == ["main"] + assert sources.list[9].trusted + assert sources.list[9].line.strip() == str(sources.list[9]) def test_enable_component(self): from subprocess import Popen, PIPE |
