Merge lp:~mvo/ubuntu-release-upgrader/fix-component-ordering into lp:ubuntu-release-upgrader

Proposed by Michael Vogt on 2012-12-14
Status: Merged
Merged at revision: 2600
Proposed branch: lp:~mvo/ubuntu-release-upgrader/fix-component-ordering
Merge into: lp:ubuntu-release-upgrader
Diff against target: 94 lines (+50/-2)
2 files modified
DistUpgrade/DistUpgradeController.py (+15/-1)
tests/test_sources_list.py (+35/-1)
To merge this branch: bzr merge lp:~mvo/ubuntu-release-upgrader/fix-component-ordering
Reviewer Review Type Date Requested Status
Martin Pitt 2012-12-14 Approve on 2012-12-14
Review via email: mp+139862@code.launchpad.net

Description of the Change

Fix the compoent ordering stuff once and for all!

To post a comment you must log in.
2601. By Michael Vogt on 2012-12-14

DistUpgrade/DistUpgradeController.py: remove unneeded functools, thanks to jtaylor

2602. By Michael Vogt on 2012-12-14

add comment that sort order for non "official" components is not stable

Martin Pitt (pitti) wrote :

Looks good to me now, thanks Michael!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'DistUpgrade/DistUpgradeController.py'
2--- DistUpgrade/DistUpgradeController.py 2012-12-13 16:42:43 +0000
3+++ DistUpgrade/DistUpgradeController.py 2012-12-14 10:59:23 +0000
4@@ -88,6 +88,18 @@
5
6 REBOOT_REQUIRED_FILE = "/var/run/reboot-required"
7
8+
9+def component_ordering_key(a):
10+ """ key() function for sorted to ensure "correct" component ordering """
11+ ordering = ["main", "restricted", "universe", "multiverse"]
12+ try:
13+ return ordering.index(a)
14+ except ValueError:
15+ # ensure to sort behind the "official" components, order is not
16+ # really important for those
17+ return len(ordering)+1
18+
19+
20 class NoBackportsFoundException(Exception):
21 pass
22
23@@ -725,7 +737,9 @@
24 component_diff = self.found_components[self.toDist]-self.found_components[entry.dist]
25 if component_diff:
26 logging.info("fixing components inconsistency from '%s'" % get_string_with_no_auth_from_source_entry(entry))
27- entry.comps.extend(list(component_diff))
28+ # extend and make sure to keep order
29+ entry.comps.extend(
30+ sorted(component_diff, key=component_ordering_key))
31 logging.info("to new entry '%s'" % get_string_with_no_auth_from_source_entry(entry))
32 del self.found_components[entry.dist]
33 return foundToDist
34
35=== modified file 'tests/test_sources_list.py'
36--- tests/test_sources_list.py 2012-11-06 21:31:47 +0000
37+++ tests/test_sources_list.py 2012-12-14 10:59:23 +0000
38@@ -9,7 +9,10 @@
39 import subprocess
40 import apt_pkg
41 import unittest
42-from DistUpgrade.DistUpgradeController import DistUpgradeController
43+from DistUpgrade.DistUpgradeController import (
44+ DistUpgradeController,
45+ component_ordering_key,
46+)
47 from DistUpgrade.DistUpgradeViewNonInteractive import DistUpgradeViewNonInteractive
48 from DistUpgrade import DistUpgradeConfigParser
49 from DistUpgrade.utils import url_downloadable
50@@ -20,6 +23,36 @@
51 CURDIR = os.path.dirname(os.path.abspath(__file__))
52
53
54+class TestComponentOrdering(unittest.TestCase):
55+
56+ def test_component_ordering_key_from_set(self):
57+ self.assertEqual(
58+ sorted(set(["x", "restricted", "main"]),
59+ key=component_ordering_key),
60+ ["main", "restricted", "x"])
61+
62+ def test_component_ordering_key_from_list(self):
63+ self.assertEqual(
64+ sorted(["x", "main"], key=component_ordering_key),
65+ ["main", "x"])
66+ self.assertEqual(
67+ sorted(["restricted", "main"],
68+ key=component_ordering_key),
69+ ["main", "restricted"])
70+ self.assertEqual(
71+ sorted(["main", "restricted"],
72+ key=component_ordering_key),
73+ ["main", "restricted"])
74+ self.assertEqual(
75+ sorted(["main", "multiverse", "restricted", "universe"],
76+ key=component_ordering_key),
77+ ["main", "restricted", "universe", "multiverse"])
78+ self.assertEqual(
79+ sorted(["a", "main", "multiverse", "restricted", "universe"],
80+ key=component_ordering_key),
81+ ["main", "restricted", "universe", "multiverse", "a"])
82+
83+
84 class TestSourcesListUpdate(unittest.TestCase):
85
86 testdir = os.path.abspath(CURDIR + "/data-sources-list-test/")
87@@ -378,6 +411,7 @@
88 "expected entry '%s' in sources.list missing. got:\n'''%s'''" %
89 (l, sources_list))
90
91+
92 if __name__ == "__main__":
93 import sys
94 for e in sys.argv:

Subscribers

People subscribed via source and target branches