From 5bd42f18d1fe7cfca35dabdf22a2a14f11a3b353 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 29 Aug 2006 15:54:13 +0200 Subject: * DistUpgrade/DistUpgradeControler.py: - if run in CDROM mode and the cd fails to mount, fail * UpdateManager/Common/aptsources.py: - from DistInfo import DistInfo (relative now instead of absolute) --- UpdateManager/Common/aptsources.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'UpdateManager/Common') diff --git a/UpdateManager/Common/aptsources.py b/UpdateManager/Common/aptsources.py index 80781cb0..38b1bd92 100644 --- a/UpdateManager/Common/aptsources.py +++ b/UpdateManager/Common/aptsources.py @@ -32,8 +32,8 @@ import os.path #import pdb -from UpdateManager.Common.DistInfo import DistInfo - +#from UpdateManager.Common.DistInfo import DistInfo +from DistInfo import DistInfo # some global helpers def is_mirror(master_uri, compare_uri): -- cgit v1.2.3 From dd6de6768890b0aaf21ceac12f835f9157e438a9 Mon Sep 17 00:00:00 2001 From: "glatzor@ubuntu.com" <> Date: Sat, 2 Sep 2006 13:34:15 +0200 Subject: * Fix #58453: handle disabled child sources correctly --- SoftwareProperties/SoftwareProperties.py | 39 +++++++++++++++++++++++++++++++- UpdateManager/Common/aptsources.py | 11 +++++---- software-properties | 7 ++++++ 3 files changed, 52 insertions(+), 5 deletions(-) (limited to 'UpdateManager/Common') diff --git a/SoftwareProperties/SoftwareProperties.py b/SoftwareProperties/SoftwareProperties.py index 38b55ef5..042a0c4c 100644 --- a/SoftwareProperties/SoftwareProperties.py +++ b/SoftwareProperties/SoftwareProperties.py @@ -377,6 +377,42 @@ class SoftwareProperties(SimpleGladeApp): else: self.treeview_cdroms.set_sensitive(True) + if self.options.debug == True or self.options.massive_debug == True: + print "ENABLED COMPS: %s" % self.distro.enabled_comps + print "INTERNET COMPS: %s" % self.distro.download_comps + print "MAIN SOURCES" + for source in self.distro.main_sources: + self.print_source_entry(source) + print "CHILD SOURCES" + for source in self.distro.child_sources: + self.print_source_entry(source) + print "CDROM SOURCES" + for source in self.distro.cdrom_sources: + self.print_source_entry(source) + print "SOURCE CODE SOURCES" + for source in self.distro.source_code_sources: + self.print_source_entry(source) + print "DISABLED SOURCES" + for source in self.distro.disabled_sources: + self.print_source_entry(source) + print "ISV" + for source in self.sourceslist_visible: + self.print_source_entry(source) + + def print_source_entry(self, source): + """Print the data of a source entry to the command line""" + print source.dist + for (label, value) in [("URI:", source.uri), + ("Comps:", source.comps), + ("Enabled:", not source.disabled), + ("Valid:", not source.invalid)]: + print " %s %s" % (label, value) + if source.template: + for (label, value) in [("MatchURI:", source.template.match_uri), + ("BaseURI:", source.template.base_uri)]: + print " %s %s" % (label, value) + print "\n" + def on_combobox_server_changed(self, combobox): """ Replace the servers used by the main and update sources with @@ -629,7 +665,8 @@ class SoftwareProperties(SimpleGladeApp): def modified_sourceslist(self): """The sources list was changed and now needs to be saved and reloaded""" - self.massive_debug_output() + if self.options.massive_debug == True: + self.massive_debug_output() self.modified = True self.button_revert.set_sensitive(True) self.save_sourceslist() diff --git a/UpdateManager/Common/aptsources.py b/UpdateManager/Common/aptsources.py index 80781cb0..1554ad61 100644 --- a/UpdateManager/Common/aptsources.py +++ b/UpdateManager/Common/aptsources.py @@ -537,12 +537,15 @@ class Distribution: self.source_code_sources.append(source) elif source.type.endswith("-src") and source.disabled == True: self.disabled_sources.append(source) - if source.template in self.source_template.children: - #print "yeah! child found: %s" % source.template.name - if source.type == "deb": + if source.invalid == False and\ + source.template in self.source_template.children: + if source.disabled == False and source.type == "deb": self.child_sources.append(source) - elif source.type == "deb-src": + elif source.disabled == False and source.type == "deb-src": self.source_code_sources.append(source) + else: + self.disabled_sources.append(source) + self.download_comps = set(comps) self.cdrom_comps = set(cdrom_comps) enabled_comps.extend(comps) diff --git a/software-properties b/software-properties index 129c3085..af1f80ff 100644 --- a/software-properties +++ b/software-properties @@ -45,6 +45,13 @@ if __name__ == "__main__": # Begin parsing of options parser = OptionParser() + parser.add_option ("-d", "--debug", action="store_true", + dest="debug", default=False, + help="Print some debug information to the command line") + parser.add_option ("-m", "--massive-debug", action="store_true", + dest="massive_debug", default=False, + help="Print a lot of debug information to the " + "command line") parser.add_option ("-n", "--no-update", action="store_true", dest="no_update", default=False, help="No update on repository change (usefull if called "\ -- cgit v1.2.3 From 9ee11257a37b71187f326b166837150b95a802a9 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 5 Sep 2006 21:08:44 +0200 Subject: * tests/test_aptsources.py: - added unittest code and implement some basic tests for the aptsources.py code * UpdateManager/Common/aptsources.py: - added __eq__ method to SourceEntry --- UpdateManager/Common/aptsources.py | 8 ++++ tests/data/sources.list | 6 +++ tests/test_aptsources.py | 85 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 tests/data/sources.list create mode 100644 tests/test_aptsources.py (limited to 'UpdateManager/Common') diff --git a/UpdateManager/Common/aptsources.py b/UpdateManager/Common/aptsources.py index 1fa080da..b5fa050d 100644 --- a/UpdateManager/Common/aptsources.py +++ b/UpdateManager/Common/aptsources.py @@ -90,6 +90,14 @@ class SourceEntry: self.template = None self.children = [] + def __eq__(self, other): + return (self.disabled == other.disabled and + self.type == other.type and + self.uri == other.uri and + self.dist == other.dist and + self.comps == other.comps) + + # works mostely like split but takes [] into account def mysplit(self, line): line = string.strip(line) diff --git a/tests/data/sources.list b/tests/data/sources.list new file mode 100644 index 00000000..5481d4f0 --- /dev/null +++ b/tests/data/sources.list @@ -0,0 +1,6 @@ +# comment 1 +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 diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py new file mode 100644 index 00000000..4d7e6a0b --- /dev/null +++ b/tests/test_aptsources.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python + +import UpdateManager.Common.aptsources as aptsources +import unittest +import apt_pkg +import os +import copy + +class TestAptSources(unittest.TestCase): + def __init__(self, methodName): + unittest.TestCase.__init__(self, methodName) + apt_pkg.init() + + def testAddComponent(self): + pass + + def testIsMirror(self): + self.assertTrue(aptsources.is_mirror("http://archive.ubuntu.com", + "http://de.archive.ubuntu.com")) + self.assertFalse(aptsources.is_mirror("http://archive.ubuntu.com", + "http://ftp.debian.org")) + + def testSourcesListReading(self): + sources = aptsources.SourcesList() + # test refresh + apt_pkg.Config.Set("Dir::Etc", os.getcwd()) + apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list") + apt_pkg.Config.Set("Dir::Etc::sourceparts",".") + sources.refresh() + self.assertEqual(len(sources.list), 6) + # test load + sources.list = [] + sources.load("data/sources.list") + self.assertEqual(len(sources.list), 6) + # test to add something that is already there (main) + before = copy.deepcopy(sources) + sources.add("deb","http://de.archive.ubuntu.com/ubuntu/", + "edgy", + ["main"]) + self.assertTrue(sources.list == before.list) + # test to add something that is already there (restricted) + before = copy.deepcopy(sources) + sources.add("deb","http://de.archive.ubuntu.com/ubuntu/", + "edgy", + ["restricted"]) + self.assertTrue(sources.list == before.list) + # test to add something new: universe + before = copy.deepcopy(sources) + sources.add("deb","http://de.archive.ubuntu.com/ubuntu/", + "edgy", + ["multiverse"]) + found = False + for entry in sources: + if (entry.type == "deb" and + entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and + entry.dist == "edgy" and + "multiverse" in entry.comps): + found = True + self.assertTrue(found) + # test to add something new: multiverse *and* + # something that is already there + before = copy.deepcopy(sources) + sources.add("deb","http://de.archive.ubuntu.com/ubuntu/", + "edgy", + ["universe", "something"]) + found_universe = 0 + found_something = 0 + for entry in sources: + if (entry.type == "deb" and + entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and + entry.dist == "edgy"): + for c in entry.comps: + print c + if c == "universe": + found_universe += 1 + if c == "something": + found_something += 1 + self.assertEqual(found_something, 1) + self.assertEqual(found_universe, 1) + + + + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3 From eafcfb0385b7183f8ad02b4d258549975ed5e350 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 6 Sep 2006 13:09:26 +0200 Subject: * UpdateManager/Common/aptsources.py, tests/test_aptsources.py: - fix test-case-failure in aptsources.py when compents are added --- UpdateManager/Common/aptsources.py | 12 ++++++++++++ tests/test_aptsources.py | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'UpdateManager/Common') diff --git a/UpdateManager/Common/aptsources.py b/UpdateManager/Common/aptsources.py index b5fa050d..f8ce474b 100644 --- a/UpdateManager/Common/aptsources.py +++ b/UpdateManager/Common/aptsources.py @@ -252,6 +252,18 @@ class SourcesList: The method will search for existing matching repos and will try to reuse them as far as possible """ + # check if we have this source already in the sources.list + for source in self.list: + if source.disabled == False and source.invalid == False and \ + source.type == type and uri == source.uri and \ + source.dist == dist: + for new_comp in comps: + if new_comp in source.comps: + # we have this component already, delete it from the new_comps + # list + del comps[comps.index(new_comp)] + if len(comps) == 0: + return source for source in self.list: # if there is a repo with the same (type, uri, dist) just add the # components diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index 4d7e6a0b..e8b97263 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -44,8 +44,7 @@ class TestAptSources(unittest.TestCase): "edgy", ["restricted"]) self.assertTrue(sources.list == before.list) - # test to add something new: universe - before = copy.deepcopy(sources) + # test to add something new: multiverse sources.add("deb","http://de.archive.ubuntu.com/ubuntu/", "edgy", ["multiverse"]) @@ -75,6 +74,7 @@ class TestAptSources(unittest.TestCase): found_universe += 1 if c == "something": found_something += 1 + #print "\n".join([s.str() for s in sources]) self.assertEqual(found_something, 1) self.assertEqual(found_universe, 1) -- cgit v1.2.3 From d754e704d6e42bff9f1f8485e134fd4d04cb3a24 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 6 Sep 2006 13:37:56 +0200 Subject: * tests/test_aptsources.py: - added another test for the "Distribution()" class --- UpdateManager/Common/aptsources.py | 5 ++++- tests/data/sources.list.testDistribution | 14 +++++++++++++ tests/test_aptsources.py | 34 ++++++++++++++++++++++---------- 3 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 tests/data/sources.list.testDistribution (limited to 'UpdateManager/Common') diff --git a/UpdateManager/Common/aptsources.py b/UpdateManager/Common/aptsources.py index f8ce474b..8963fd15 100644 --- a/UpdateManager/Common/aptsources.py +++ b/UpdateManager/Common/aptsources.py @@ -635,12 +635,15 @@ class Distribution: def enable_component(self, sourceslist, comp): """ - Disable a component in all main, child and source code sources + Enable a component in all main, child and source code sources (excluding cdrom based sources) sourceslist: an aptsource.sources_list comp: the component that should be enabled """ + # FIXME: we can't just unconditionally add stuff to each line, + # otherwise we need up with multiple components for the + # same repository (see tests/test_aptsources.py for details) sources = [] sources.extend(self.main_sources) sources.extend(self.child_sources) diff --git a/tests/data/sources.list.testDistribution b/tests/data/sources.list.testDistribution new file mode 100644 index 00000000..dd900645 --- /dev/null +++ b/tests/data/sources.list.testDistribution @@ -0,0 +1,14 @@ +# comment 1 +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 +# comment 4 +deb http://de.archive.ubuntu.com/ubuntu/ edgy-updates universe multiverse +# comment 5 +deb http://de.archive.ubuntu.com/ubuntu/ edgy-security main +# comment 6 +deb http://ftp.debian.org/debian sid main +# comment 7 +deb http://de.archive.ubuntu.com/ubuntu/ breezy main \ No newline at end of file diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index e8b97263..0479076c 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -10,9 +10,8 @@ class TestAptSources(unittest.TestCase): def __init__(self, methodName): unittest.TestCase.__init__(self, methodName) apt_pkg.init() - - def testAddComponent(self): - pass + apt_pkg.Config.Set("Dir::Etc", os.getcwd()) + apt_pkg.Config.Set("Dir::Etc::sourceparts",".") def testIsMirror(self): self.assertTrue(aptsources.is_mirror("http://archive.ubuntu.com", @@ -21,17 +20,17 @@ class TestAptSources(unittest.TestCase): "http://ftp.debian.org")) def testSourcesListReading(self): - sources = aptsources.SourcesList() - # test refresh - apt_pkg.Config.Set("Dir::Etc", os.getcwd()) apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list") - apt_pkg.Config.Set("Dir::Etc::sourceparts",".") - sources.refresh() + sources = aptsources.SourcesList() self.assertEqual(len(sources.list), 6) # test load sources.list = [] sources.load("data/sources.list") self.assertEqual(len(sources.list), 6) + + def testSourcesListAdding(self): + apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list") + sources = aptsources.SourcesList() # test to add something that is already there (main) before = copy.deepcopy(sources) sources.add("deb","http://de.archive.ubuntu.com/ubuntu/", @@ -69,7 +68,6 @@ class TestAptSources(unittest.TestCase): entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and entry.dist == "edgy"): for c in entry.comps: - print c if c == "universe": found_universe += 1 if c == "something": @@ -78,7 +76,23 @@ class TestAptSources(unittest.TestCase): self.assertEqual(found_something, 1) self.assertEqual(found_universe, 1) - + def testDistribution(self): + apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list.testDistribution") + sources = aptsources.SourcesList() + distro = aptsources.Distribution() + distro.get_sources(sources) + comp = "restricted" + distro.enable_component(sources, comp) + found = 0 + for entry in sources: + if (entry.type == "deb" and + entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and + entry.dist == "edgy"): + for c in entry.comps: + if c == comp: + found += 1 + print "".join([s.str() for s in sources]) + assertEqual(found, 1) if __name__ == "__main__": -- cgit v1.2.3