summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-04-06 16:59:49 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2011-04-06 16:59:49 +0200
commitd00bb4ccfcb4042f88a9bb8327a5ce4f4a02e057 (patch)
tree60b03a295d0c07edbfb576ca21816fa13beb4c4e
parent52475d3ddc835c3b543d98ee1c16df4989a4112d (diff)
parentb2a0eb7ca6d8db6c8e4ac1875fa41f9466c78384 (diff)
downloadpython-apt-d00bb4ccfcb4042f88a9bb8327a5ce4f4a02e057.tar.gz
* cherry pick multiarch support for aptsources from debian
* aptsources: Parse multi-arch sources.list files correctly * aptsources: Allow insertion of new multi-arch entries
-rw-r--r--aptsources/sourceslist.py41
-rw-r--r--debian/changelog11
-rw-r--r--tests/data/aptsources/sources.list5
-rw-r--r--tests/test_aptsources.py55
4 files changed, 103 insertions, 9 deletions
diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py
index 0c4335ec..83d2c8b9 100644
--- a/aptsources/sourceslist.py
+++ b/aptsources/sourceslist.py
@@ -82,6 +82,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
@@ -114,7 +115,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] == "]":
@@ -170,6 +171,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:
@@ -205,7 +220,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 != "":
@@ -256,12 +276,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[:]
@@ -269,7 +291,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
@@ -282,19 +305,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 235a38da..6f22ad9f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,14 @@
+python-apt (0.7.100.3ubuntu2) UNRELEASED; urgency=low
+
+ [ Michael Vogt ]
+ * cherry pick multiarch support for aptsources from debian
+
+ [ Julian Andres Klode ]
+ * aptsources: Parse multi-arch sources.list files correctly
+ * aptsources: Allow insertion of new multi-arch entries
+
+ -- Michael Vogt <michael.vogt@ubuntu.com> Wed, 06 Apr 2011 16:59:07 +0200
+
python-apt (0.7.100.3ubuntu1) natty; urgency=low
* merge fixes from debian-sid, most notably the fixes
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..1597674e 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"""
@@ -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)
@@ -108,6 +144,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/"