Merge lp:~james-w/linaro-image-tools/architectures-from-config into lp:linaro-image-tools/11.11

Proposed by James Westby
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: 108
Merged at revision: 66
Proposed branch: lp:~james-w/linaro-image-tools/architectures-from-config
Merge into: lp:linaro-image-tools/11.11
Prerequisite: lp:~james-w/linaro-image-tools/architecture-support
Diff against target: 178 lines (+108/-6)
2 files modified
hwpack/config.py (+47/-1)
hwpack/tests/test_config.py (+61/-5)
To merge this branch: bzr merge lp:~james-w/linaro-image-tools/architectures-from-config
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle (community) Approve
Review via email: mp+34467@code.launchpad.net

Description of the change

Hi,

Here's a small branch that adds architectures to the configuration file.

I decided that we want the configuration to at least state which
architecture(s) it is intended for. We can add ways to limit/expand this
list at build time later if we want.

Firstly this branch adds the code and tests to ensure that the architectures
list is present and has at least one entry.

Then it adds a property for getting the list of architectures.

Lastly it also adds a property to get the sources. I folded this in as it is
very small, and along the same lines. There are already tests for the validity
of the sources specification.

Thanks,

James

To post a comment you must log in.
108. By James Westby

Merged architecture-support into architectures-from-config.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

It all looks fine.

I'm not sure of the motivation for filtering out duplicates in the accessor methods -- wouldn't complaining during validation make just as much sense?

review: Approve
Revision history for this message
James Westby (james-w) wrote :

On Fri, 03 Sep 2010 05:05:54 -0000, Michael Hudson <email address hidden> wrote:
> Review: Approve
> It all looks fine.
>
> I'm not sure of the motivation for filtering out duplicates in the
> accessor methods -- wouldn't complaining during validation make just
> as much sense?

Yes, it would, but I figured that we should just accept the data as it's
understandable, if wrong. I can make the change if you want.

Thanks,

James

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

On Sat, 04 Sep 2010 10:36:44 -0000, James Westby <email address hidden> wrote:
> On Fri, 03 Sep 2010 05:05:54 -0000, Michael Hudson <email address hidden> wrote:
> > Review: Approve
> > It all looks fine.
> >
> > I'm not sure of the motivation for filtering out duplicates in the
> > accessor methods -- wouldn't complaining during validation make just
> > as much sense?
>
> Yes, it would, but I figured that we should just accept the data as it's
> understandable, if wrong. I can make the change if you want.

No, that sounds fair enough.

Cheers,
mwh

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hwpack/config.py'
2--- hwpack/config.py 2010-08-31 20:51:40 +0000
3+++ hwpack/config.py 2010-09-02 23:07:47 +0000
4@@ -19,6 +19,7 @@
5 PACKAGE_REGEX = NAME_REGEX
6 ORIGIN_KEY = "origin"
7 MAINTAINER_KEY = "maintainer"
8+ ARCHITECTURES_KEY = "architectures"
9
10 def __init__(self, fp):
11 """Create a Config.
12@@ -39,6 +40,7 @@
13 self._validate_include_debs()
14 self._validate_support()
15 self._validate_packages()
16+ self._validate_architectures()
17 self._validate_sections()
18
19 @property
20@@ -109,7 +111,44 @@
21 if raw_packages is None:
22 return []
23 packages = re.split("\s+", raw_packages)
24- return packages
25+ filtered_packages = []
26+ for package in packages:
27+ if package not in filtered_packages:
28+ filtered_packages.append(package)
29+ return filtered_packages
30+
31+ @property
32+ def architectures(self):
33+ """The architectures to build the hwpack for.
34+
35+ A list of str.
36+ """
37+ raw_architectures = self._get_option_from_main_section(
38+ self.ARCHITECTURES_KEY)
39+ if raw_architectures is None:
40+ return []
41+ architectures = re.split("\s+", raw_architectures)
42+ filtered_architectures = []
43+ for architecture in architectures:
44+ if architecture not in filtered_architectures:
45+ filtered_architectures.append(architecture)
46+ return filtered_architectures
47+
48+ @property
49+ def sources(self):
50+ """The sources defined in the configuration.
51+
52+ A dict mapping source identifiers to sources entries.
53+ """
54+ sources = {}
55+ sections = self.parser.sections()
56+ found = False
57+ for section_name in sections:
58+ if section_name == self.MAIN_SECTION:
59+ continue
60+ sources[section_name] = self.parser.get(
61+ section_name, self.SOURCES_ENTRY_KEY)
62+ return sources
63
64 def _validate_name(self):
65 try:
66@@ -148,6 +187,13 @@
67 "Invalid value in %s in the [%s] section: %s"
68 % (self.PACKAGES_KEY, self.MAIN_SECTION, package))
69
70+ def _validate_architectures(self):
71+ architectures = self.architectures
72+ if not architectures:
73+ raise HwpackConfigError(
74+ "No %s in the [%s] section"
75+ % (self.ARCHITECTURES_KEY, self.MAIN_SECTION))
76+
77 def _validate_section_sources_entry(self, section_name):
78 try:
79 sources_entry = self.parser.get(
80
81=== modified file 'hwpack/tests/test_config.py'
82--- hwpack/tests/test_config.py 2010-08-31 20:51:40 +0000
83+++ hwpack/tests/test_config.py 2010-09-02 23:07:47 +0000
84@@ -7,7 +7,8 @@
85
86 class ConfigTests(TestCase):
87
88- valid_start = "[hwpack]\nname = ahwpack\npackages = foo\n"
89+ valid_start = (
90+ "[hwpack]\nname = ahwpack\npackages = foo\narchitectures = armel\n")
91
92 def test_create(self):
93 config = Config(StringIO())
94@@ -70,6 +71,19 @@
95 "Invalid value in packages in the [hwpack] section: ~~",
96 config)
97
98+ def test_validate_no_architectures(self):
99+ config = self.get_config(
100+ "[hwpack]\nname = ahwpack\npackages = foo\n")
101+ self.assertValidationError(
102+ "No architectures in the [hwpack] section", config)
103+
104+ def test_validate_empty_architectures(self):
105+ config = self.get_config(
106+ "[hwpack]\nname = ahwpack\npackages = foo\n"
107+ "architectures = \n")
108+ self.assertValidationError(
109+ "No architectures in the [hwpack] section", config)
110+
111 def test_validate_no_other_sections(self):
112 config = self.get_config(self.valid_start + "\n")
113 self.assertValidationError(
114@@ -119,7 +133,9 @@
115 self.assertEqual(None, config.validate())
116
117 def test_name(self):
118- config = self.get_config("[hwpack]\nname = ahwpack\npackages = foo\n")
119+ config = self.get_config(
120+ "[hwpack]\nname = ahwpack\npackages = foo\n"
121+ "architectures = armel\n")
122 self.assertEqual("ahwpack", config.name)
123
124 def test_include_debs(self):
125@@ -179,10 +195,50 @@
126
127 def test_packages(self):
128 config = self.get_config(
129- "[hwpack]\nname=ahwpack\npackages=foo bar\n")
130+ "[hwpack]\nname=ahwpack\npackages=foo bar\n"
131+ "architectures=armel\n")
132 self.assertEqual(["foo", "bar"], config.packages)
133
134 def test_packages_with_newline(self):
135 config = self.get_config(
136- "[hwpack]\nname=ahwpack\npackages=foo\n bar\n")
137- self.assertEqual(["foo", "bar"], config.packages)
138+ "[hwpack]\nname=ahwpack\npackages=foo\n bar\n"
139+ "architectures=armel\n")
140+ self.assertEqual(["foo", "bar"], config.packages)
141+
142+ def test_packages_filters_duplicates(self):
143+ config = self.get_config(
144+ "[hwpack]\nname=ahwpack\npackages=foo bar foo\n"
145+ "architectures=armel\n")
146+ self.assertEqual(["foo", "bar"], config.packages)
147+
148+ def test_sources_single(self):
149+ config = self.get_config(
150+ self.valid_start
151+ + "\n[ubuntu]\nsources-entry = http://example.org foo\n")
152+ self.assertEqual({"ubuntu": "http://example.org foo"}, config.sources)
153+
154+ def test_sources_multiple(self):
155+ config = self.get_config(
156+ self.valid_start
157+ + "\n[ubuntu]\nsources-entry = http://example.org foo\n"
158+ + "\n[linaro]\nsources-entry = http://example.org bar\n")
159+ self.assertEqual(
160+ {"ubuntu": "http://example.org foo",
161+ "linaro": "http://example.org bar"},
162+ config.sources)
163+
164+ def test_architectures(self):
165+ config = self.get_config(
166+ "[hwpack]\nname=ahwpack\npackages=foo\narchitectures=foo bar\n")
167+ self.assertEqual(["foo", "bar"], config.architectures)
168+
169+ def test_architectures_with_newline(self):
170+ config = self.get_config(
171+ "[hwpack]\nname=ahwpack\npackages=foo\narchitectures=foo\n bar\n")
172+ self.assertEqual(["foo", "bar"], config.architectures)
173+
174+ def test_architectures_filters_duplicates(self):
175+ config = self.get_config(
176+ "[hwpack]\nname=ahwpack\npackages=foo\n"
177+ "architectures=foo bar foo\n")
178+ self.assertEqual(["foo", "bar"], config.architectures)

Subscribers

People subscribed via source and target branches