Merge lp:~milo/linaro-image-tools/hwpack-read into lp:linaro-image-tools/11.11
- hwpack-read
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | James Tunnicliffe |
Approved revision: | 544 |
Merged at revision: | 546 |
Proposed branch: | lp:~milo/linaro-image-tools/hwpack-read |
Merge into: | lp:linaro-image-tools/11.11 |
Diff against target: |
459 lines (+360/-9) 6 files modified
linaro-media-create (+30/-7) linaro_image_tools/hwpack/hwpack_reader.py (+192/-0) linaro_image_tools/hwpack/tests/__init__.py (+1/-0) linaro_image_tools/hwpack/tests/test_hwpack_reader.py (+114/-0) linaro_image_tools/media_create/__init__.py (+6/-2) linaro_image_tools/utils.py (+17/-0) |
To merge this branch: | bzr merge lp:~milo/linaro-image-tools/hwpack-read |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Tunnicliffe (community) | Approve | ||
Linaro Infrastructure | Pending | ||
Review via email: mp+116606@code.launchpad.net |
Commit message
Description of the change
With this merge, there is the initial support for hwpack metadata reading, before creating an image with l-m-c.
What has been added here is:
- A new class for reading hwpack, that makes use of the HwpackHandler to open the tarball files
- New tests for the class
- New command line option --read-hwpack that reads the hwpack metadata and prints out information about the supported boards and bootlaoders
I also fixed a couple of PEP8 issues.
Notes:
- There is one test that will fail, and is related to pyflakes, looks like it is bug 812958 (I used getter and setter)
- Some of the required command line options have been set to False, since if we want to just read the hwpack and see what is supported, we should not require all the information. Since there is still work in progress on this, the bits handling the necessary command line options is still missing.
- 542. By Milo Casagrande
-
Added option check.
- 543. By Milo Casagrande
-
Fixed PEP8 warning.
- 544. By Milo Casagrande
-
Fixed tests and imports.
- 545. By Milo Casagrande
-
Fixed annoying pyflakes warnings.
- 546. By Milo Casagrande
-
Fixed assertEqual tests.
Preview Diff
1 | === modified file 'linaro-media-create' | |||
2 | --- linaro-media-create 2012-04-19 01:12:10 +0000 | |||
3 | +++ linaro-media-create 2012-07-25 13:08:18 +0000 | |||
4 | @@ -33,6 +33,10 @@ | |||
5 | 33 | install_hwpacks, | 33 | install_hwpacks, |
6 | 34 | install_packages, | 34 | install_packages, |
7 | 35 | ) | 35 | ) |
8 | 36 | from linaro_image_tools.hwpack.hwpack_reader import ( | ||
9 | 37 | HwpackReader, | ||
10 | 38 | HwpackReaderError, | ||
11 | 39 | ) | ||
12 | 36 | from linaro_image_tools.media_create.partitions import ( | 40 | from linaro_image_tools.media_create.partitions import ( |
13 | 37 | Media, | 41 | Media, |
14 | 38 | setup_partitions, | 42 | setup_partitions, |
15 | @@ -44,13 +48,15 @@ | |||
16 | 44 | ) | 48 | ) |
17 | 45 | from linaro_image_tools.media_create import get_args_parser | 49 | from linaro_image_tools.media_create import get_args_parser |
18 | 46 | from linaro_image_tools.utils import ( | 50 | from linaro_image_tools.utils import ( |
19 | 51 | additional_option_checks, | ||
20 | 52 | check_file_integrity_and_log_errors, | ||
21 | 53 | check_required_args, | ||
22 | 47 | ensure_command, | 54 | ensure_command, |
23 | 55 | IncompatibleOptions, | ||
24 | 48 | is_arm_host, | 56 | is_arm_host, |
26 | 49 | check_file_integrity_and_log_errors, | 57 | MissingRequiredOption, |
27 | 50 | path_in_tarfile_exists, | 58 | path_in_tarfile_exists, |
28 | 51 | IncompatibleOptions, | ||
29 | 52 | prep_media_path, | 59 | prep_media_path, |
30 | 53 | additional_option_checks, | ||
31 | 54 | ) | 60 | ) |
32 | 55 | 61 | ||
33 | 56 | # Just define the global variables | 62 | # Just define the global variables |
34 | @@ -107,6 +113,22 @@ | |||
35 | 107 | print >> sys.stderr, "\nError:", e.value | 113 | print >> sys.stderr, "\nError:", e.value |
36 | 108 | sys.exit(1) | 114 | sys.exit(1) |
37 | 109 | 115 | ||
38 | 116 | if args.readhwpack: | ||
39 | 117 | try: | ||
40 | 118 | reader = HwpackReader(args.hwpacks) | ||
41 | 119 | print reader.get_supported_boards() | ||
42 | 120 | sys.exit(0) | ||
43 | 121 | except HwpackReaderError as e: | ||
44 | 122 | print >> sys.stderr, "\nError:", e.value | ||
45 | 123 | sys.exit(1) | ||
46 | 124 | |||
47 | 125 | try: | ||
48 | 126 | check_required_args(args) | ||
49 | 127 | except MissingRequiredOption as e: | ||
50 | 128 | parser.print_help() | ||
51 | 129 | print >> sys.stderr, "\nError:", e.value | ||
52 | 130 | sys.exit(1) | ||
53 | 131 | |||
54 | 110 | board_config = board_configs[args.board] | 132 | board_config = board_configs[args.board] |
55 | 111 | board_config.set_metadata(args.hwpacks) | 133 | board_config.set_metadata(args.hwpacks) |
56 | 112 | board_config.set_board(args.board) | 134 | board_config.set_board(args.board) |
57 | @@ -117,11 +139,12 @@ | |||
58 | 117 | 139 | ||
59 | 118 | if media.is_block_device: | 140 | if media.is_block_device: |
60 | 119 | if not board_config.supports_writing_to_mmc: | 141 | if not board_config.supports_writing_to_mmc: |
63 | 120 | print "The board '%s' does not support the --mmc option. Please use "\ | 142 | print ("The board '%s' does not support the --mmc option. " |
64 | 121 | "--image_file to create an image file for this board." % args.board | 143 | "Please use --image_file to create an image file for this " |
65 | 144 | "board." % args.board) | ||
66 | 122 | sys.exit(1) | 145 | sys.exit(1) |
69 | 123 | if not confirm_device_selection_and_ensure_it_is_ready(args.device, | 146 | if not confirm_device_selection_and_ensure_it_is_ready( |
70 | 124 | args.nocheck_mmc): | 147 | args.device, args.nocheck_mmc): |
71 | 125 | sys.exit(1) | 148 | sys.exit(1) |
72 | 126 | elif not args.should_format_rootfs or not args.should_format_bootfs: | 149 | elif not args.should_format_rootfs or not args.should_format_bootfs: |
73 | 127 | print ("Do not use --no-boot or --no-part in conjunction with " | 150 | print ("Do not use --no-boot or --no-part in conjunction with " |
74 | 128 | 151 | ||
75 | === added file 'linaro_image_tools/hwpack/hwpack_reader.py' | |||
76 | --- linaro_image_tools/hwpack/hwpack_reader.py 1970-01-01 00:00:00 +0000 | |||
77 | +++ linaro_image_tools/hwpack/hwpack_reader.py 2012-07-25 13:08:18 +0000 | |||
78 | @@ -0,0 +1,192 @@ | |||
79 | 1 | # Copyright (C) 2012 Linaro | ||
80 | 2 | # | ||
81 | 3 | # Author: Milo Casagrande <milo.casagrande@linaro.org> | ||
82 | 4 | # | ||
83 | 5 | # This file is part of Linaro Image Tools. | ||
84 | 6 | # | ||
85 | 7 | # Linaro Image Tools is free software: you can redistribute it and/or modify | ||
86 | 8 | # it under the terms of the GNU General Public License as published by | ||
87 | 9 | # the Free Software Foundation, either version 3 of the License, or | ||
88 | 10 | # (at your option) any later version. | ||
89 | 11 | # | ||
90 | 12 | # Linaro Image Tools is distributed in the hope that it will be useful, | ||
91 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
92 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
93 | 15 | # GNU General Public License for more details. | ||
94 | 16 | # | ||
95 | 17 | # You should have received a copy of the GNU General Public License | ||
96 | 18 | # along with Linaro Image Tools. If not, see <http://www.gnu.org/licenses/>. | ||
97 | 19 | |||
98 | 20 | from linaro_image_tools.media_create.boards import HardwarepackHandler | ||
99 | 21 | from linaro_image_tools.hwpack.hwpack_fields import ( | ||
100 | 22 | FORMAT_FIELD, | ||
101 | 23 | NAME_FIELD, | ||
102 | 24 | BOARDS_FIELD, | ||
103 | 25 | BOOTLOADERS_FIELD, | ||
104 | 26 | ) | ||
105 | 27 | |||
106 | 28 | from os import linesep as LINE_SEP | ||
107 | 29 | |||
108 | 30 | # Fields necessary for the string representation of the hardware pack supported | ||
109 | 31 | # boards and bootlaoders. | ||
110 | 32 | HALF_SEPARATOR = '+--------------------------------------' | ||
111 | 33 | ENDING = '+' | ||
112 | 34 | SEPARATOR = HALF_SEPARATOR * 2 + ENDING | ||
113 | 35 | FORMAT = '{:<80}' | ||
114 | 36 | CENTER_ALIGN = '{:^80}' | ||
115 | 37 | ELEMENT_FORMAT = '{:<39}| {:<39}' | ||
116 | 38 | |||
117 | 39 | |||
118 | 40 | class HwpackReaderError(Exception): | ||
119 | 41 | """General error raised by HwpackReader.""" | ||
120 | 42 | def __init__(self, value): | ||
121 | 43 | self.value = value | ||
122 | 44 | |||
123 | 45 | def __str__(self): | ||
124 | 46 | return repr(self.value) | ||
125 | 47 | |||
126 | 48 | |||
127 | 49 | class Hwpack(object): | ||
128 | 50 | """A simple representation of an hardware pack and its value.""" | ||
129 | 51 | def __init__(self): | ||
130 | 52 | self._hwpack = None | ||
131 | 53 | self._boards = None | ||
132 | 54 | self._bootloaders = None | ||
133 | 55 | self._name = None | ||
134 | 56 | |||
135 | 57 | @property | ||
136 | 58 | def hwpack(self): | ||
137 | 59 | """The hardware pack it refers to.""" | ||
138 | 60 | return self._hwpack | ||
139 | 61 | |||
140 | 62 | def sethwpack(self, value): | ||
141 | 63 | """Sets the hwpack field.""" | ||
142 | 64 | self._hwpack = value | ||
143 | 65 | |||
144 | 66 | @property | ||
145 | 67 | def boards(self): | ||
146 | 68 | """The boards field of this hardware pack.""" | ||
147 | 69 | return self._boards | ||
148 | 70 | |||
149 | 71 | def setboards(self, value): | ||
150 | 72 | """Sets the boards field.""" | ||
151 | 73 | self._boards = value | ||
152 | 74 | |||
153 | 75 | @property | ||
154 | 76 | def name(self): | ||
155 | 77 | """The name field of this hardware pack.""" | ||
156 | 78 | return self._name | ||
157 | 79 | |||
158 | 80 | def setname(self, value): | ||
159 | 81 | """Sets the name field.""" | ||
160 | 82 | self._name = value | ||
161 | 83 | |||
162 | 84 | @property | ||
163 | 85 | def bootloaders(self): | ||
164 | 86 | """The bootlaoders field of this hardware pack.""" | ||
165 | 87 | return self._bootloaders | ||
166 | 88 | |||
167 | 89 | def setbootloaders(self, value): | ||
168 | 90 | """Sets the bootlaoders field.""" | ||
169 | 91 | self._bootloaders = value | ||
170 | 92 | |||
171 | 93 | def __eq__(self, other): | ||
172 | 94 | """Equality method.""" | ||
173 | 95 | equal = False | ||
174 | 96 | if isinstance(other, Hwpack): | ||
175 | 97 | equal = (self.name == other.name and | ||
176 | 98 | self.boards == other.boards and | ||
177 | 99 | self.hwpack == other.hwpack and | ||
178 | 100 | self.bootloaders == other.bootloaders) | ||
179 | 101 | return equal | ||
180 | 102 | |||
181 | 103 | def __hash__(self): | ||
182 | 104 | return hash(frozenset(self.bootloaders), frozenset(self.boards), | ||
183 | 105 | self.name, self.hwpack) | ||
184 | 106 | |||
185 | 107 | def __str__(self): | ||
186 | 108 | """String representation of this hwapack supported elements.""" | ||
187 | 109 | string = FORMAT.format("Read hardware pack: %s" % self.hwpack) | ||
188 | 110 | string += LINE_SEP | ||
189 | 111 | string += FORMAT.format(SEPARATOR) | ||
190 | 112 | string += LINE_SEP | ||
191 | 113 | string += ELEMENT_FORMAT.format("Supported boards", | ||
192 | 114 | "Supported bootloaders") | ||
193 | 115 | string += LINE_SEP | ||
194 | 116 | string += FORMAT.format(SEPARATOR) | ||
195 | 117 | string += LINE_SEP | ||
196 | 118 | |||
197 | 119 | if self.boards: | ||
198 | 120 | for key, value in self.boards.iteritems(): | ||
199 | 121 | if value.get(BOOTLOADERS_FIELD, None) is not None: | ||
200 | 122 | bootloaders = value.get(BOOTLOADERS_FIELD) | ||
201 | 123 | supported_bootloaders = bootloaders.keys() | ||
202 | 124 | else: | ||
203 | 125 | supported_bootloaders = self.bootloaders.keys() | ||
204 | 126 | string += ELEMENT_FORMAT.format(key, | ||
205 | 127 | ",".join(supported_bootloaders)) | ||
206 | 128 | string += LINE_SEP | ||
207 | 129 | else: | ||
208 | 130 | # If we pass a converted file with just a single board, we do not | ||
209 | 131 | # have the boards section, and we default to the name of the hwpack | ||
210 | 132 | if self.bootloaders: | ||
211 | 133 | supported_bootloaders = self.bootloaders.keys() | ||
212 | 134 | string += ELEMENT_FORMAT.format(self.name, | ||
213 | 135 | ",".join(supported_bootloaders)) | ||
214 | 136 | string += LINE_SEP | ||
215 | 137 | else: | ||
216 | 138 | string += CENTER_ALIGN.format("No supported boards and " | ||
217 | 139 | "bootloaders") | ||
218 | 140 | string += LINE_SEP | ||
219 | 141 | string += FORMAT.format(SEPARATOR) | ||
220 | 142 | return string + LINE_SEP | ||
221 | 143 | |||
222 | 144 | |||
223 | 145 | class HwpackReader(object): | ||
224 | 146 | """Reads the information contained in a hwpack """ | ||
225 | 147 | def __init__(self, hwpacks): | ||
226 | 148 | """Create a new instance. | ||
227 | 149 | |||
228 | 150 | :param hwpacks: The list of hardware packs to read from.""" | ||
229 | 151 | self.hwpacks = hwpacks | ||
230 | 152 | # Where we store all the info from the hwpack. | ||
231 | 153 | self._supported_elements = [] | ||
232 | 154 | |||
233 | 155 | @property | ||
234 | 156 | def supported_elements(self): | ||
235 | 157 | """Gets the supported elements of by all the hardwapare packs.""" | ||
236 | 158 | return self._supported_elements | ||
237 | 159 | |||
238 | 160 | def _read_hwpacks_metadata(self): | ||
239 | 161 | """Reads the hardware pack metadata file, and prints information about | ||
240 | 162 | the supported boards and bootloaders.""" | ||
241 | 163 | for tarball in self.hwpacks: | ||
242 | 164 | with HardwarepackHandler([tarball]) as handler: | ||
243 | 165 | hwpack_format = handler.get_field(FORMAT_FIELD)[0] | ||
244 | 166 | if hwpack_format.format_as_string == "3.0": | ||
245 | 167 | local_hwpack = Hwpack() | ||
246 | 168 | local_hwpack.sethwpack(tarball) | ||
247 | 169 | local_hwpack.setname(handler.get_field(NAME_FIELD)[0]) | ||
248 | 170 | local_hwpack.setboards(handler.get_field(BOARDS_FIELD)[0]) | ||
249 | 171 | local_hwpack.setbootloaders( | ||
250 | 172 | handler.get_field(BOOTLOADERS_FIELD)[0]) | ||
251 | 173 | self.supported_elements.append(local_hwpack) | ||
252 | 174 | else: | ||
253 | 175 | raise HwpackReaderError("Hardwarepack '%s' cannot be " | ||
254 | 176 | "read, unsupported format." % | ||
255 | 177 | (tarball)) | ||
256 | 178 | |||
257 | 179 | def get_supported_boards(self): | ||
258 | 180 | """Prints the necessary information. | ||
259 | 181 | |||
260 | 182 | :return A string representation of the information.""" | ||
261 | 183 | self._read_hwpacks_metadata() | ||
262 | 184 | return str(self) | ||
263 | 185 | |||
264 | 186 | def __str__(self): | ||
265 | 187 | """The string representation of this reader. It is a printable | ||
266 | 188 | representation of the necessary information.""" | ||
267 | 189 | hwpack_reader = "" | ||
268 | 190 | for element in self.supported_elements: | ||
269 | 191 | hwpack_reader += str(element) | ||
270 | 192 | return hwpack_reader | ||
271 | 0 | 193 | ||
272 | === modified file 'linaro_image_tools/hwpack/tests/__init__.py' | |||
273 | --- linaro_image_tools/hwpack/tests/__init__.py 2012-07-19 17:57:24 +0000 | |||
274 | +++ linaro_image_tools/hwpack/tests/__init__.py 2012-07-25 13:08:18 +0000 | |||
275 | @@ -30,6 +30,7 @@ | |||
276 | 30 | 'linaro_image_tools.hwpack.tests.test_config_v3', | 30 | 'linaro_image_tools.hwpack.tests.test_config_v3', |
277 | 31 | 'linaro_image_tools.hwpack.tests.test_hardwarepack', | 31 | 'linaro_image_tools.hwpack.tests.test_hardwarepack', |
278 | 32 | 'linaro_image_tools.hwpack.tests.test_hwpack_converter', | 32 | 'linaro_image_tools.hwpack.tests.test_hwpack_converter', |
279 | 33 | 'linaro_image_tools.hwpack.tests.test_hwpack_reader', | ||
280 | 33 | 'linaro_image_tools.hwpack.tests.test_packages', | 34 | 'linaro_image_tools.hwpack.tests.test_packages', |
281 | 34 | 'linaro_image_tools.hwpack.tests.test_script', | 35 | 'linaro_image_tools.hwpack.tests.test_script', |
282 | 35 | 'linaro_image_tools.hwpack.tests.test_tarfile_matchers', | 36 | 'linaro_image_tools.hwpack.tests.test_tarfile_matchers', |
283 | 36 | 37 | ||
284 | === added file 'linaro_image_tools/hwpack/tests/test_hwpack_reader.py' | |||
285 | --- linaro_image_tools/hwpack/tests/test_hwpack_reader.py 1970-01-01 00:00:00 +0000 | |||
286 | +++ linaro_image_tools/hwpack/tests/test_hwpack_reader.py 2012-07-25 13:08:18 +0000 | |||
287 | @@ -0,0 +1,114 @@ | |||
288 | 1 | # Copyright (C) 2012 Linaro | ||
289 | 2 | # | ||
290 | 3 | # Author: Milo Casagrande <milo.casagrande@linaro.org> | ||
291 | 4 | # | ||
292 | 5 | # This file is part of Linaro Image Tools. | ||
293 | 6 | # | ||
294 | 7 | # Linaro Image Tools is free software: you can redistribute it and/or modify | ||
295 | 8 | # it under the terms of the GNU General Public License as published by | ||
296 | 9 | # the Free Software Foundation, either version 3 of the License, or | ||
297 | 10 | # (at your option) any later version. | ||
298 | 11 | # | ||
299 | 12 | # Linaro Image Tools is distributed in the hope that it will be useful, | ||
300 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
301 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
302 | 15 | # GNU General Public License for more details. | ||
303 | 16 | # | ||
304 | 17 | # You should have received a copy of the GNU General Public License | ||
305 | 18 | # along with Linaro Image Tools. If not, see <http://www.gnu.org/licenses/>. | ||
306 | 19 | |||
307 | 20 | import tarfile | ||
308 | 21 | from StringIO import StringIO | ||
309 | 22 | from linaro_image_tools.testing import TestCaseWithFixtures | ||
310 | 23 | from linaro_image_tools.tests.fixtures import ( | ||
311 | 24 | CreateTempDirFixture, | ||
312 | 25 | ) | ||
313 | 26 | |||
314 | 27 | from linaro_image_tools.media_create.tests.fixtures import ( | ||
315 | 28 | CreateTarballFixture, | ||
316 | 29 | ) | ||
317 | 30 | |||
318 | 31 | from linaro_image_tools.hwpack.hwpack_reader import ( | ||
319 | 32 | Hwpack, | ||
320 | 33 | HwpackReader, | ||
321 | 34 | HwpackReaderError, | ||
322 | 35 | ) | ||
323 | 36 | |||
324 | 37 | |||
325 | 38 | class HwpackReaderTests(TestCaseWithFixtures): | ||
326 | 39 | """Test class for the hwpack reader.""" | ||
327 | 40 | |||
328 | 41 | def setUp(self): | ||
329 | 42 | super(HwpackReaderTests, self).setUp() | ||
330 | 43 | self.metadata = ("format: 3.0\nversion: '1'\nname: test-hwpack\n" | ||
331 | 44 | "architecture: armel\norigin: Linaro") | ||
332 | 45 | self.hwpack = Hwpack() | ||
333 | 46 | self.hwpack.setname('test-hwpack') | ||
334 | 47 | self.tar_dir_fixture = CreateTempDirFixture() | ||
335 | 48 | self.useFixture(self.tar_dir_fixture) | ||
336 | 49 | self.tarball_fixture = CreateTarballFixture( | ||
337 | 50 | self.tar_dir_fixture.get_temp_dir()) | ||
338 | 51 | self.useFixture(self.tarball_fixture) | ||
339 | 52 | |||
340 | 53 | def tearDown(self): | ||
341 | 54 | super(HwpackReaderTests, self).tearDown() | ||
342 | 55 | self.hwpack = None | ||
343 | 56 | self.metadata = "" | ||
344 | 57 | |||
345 | 58 | def add_to_tarball(self, files, tarball=None): | ||
346 | 59 | if tarball is None: | ||
347 | 60 | tarball = self.tarball_fixture.get_tarball() | ||
348 | 61 | tar_file = tarfile.open(tarball, mode='w:gz') | ||
349 | 62 | for filename, data in files: | ||
350 | 63 | tarinfo = tarfile.TarInfo(filename) | ||
351 | 64 | tarinfo.size = len(data) | ||
352 | 65 | tar_file.addfile(tarinfo, StringIO(data)) | ||
353 | 66 | tar_file.close() | ||
354 | 67 | return tarball | ||
355 | 68 | |||
356 | 69 | def test_hwpack_class(self): | ||
357 | 70 | hwpack = Hwpack() | ||
358 | 71 | hwpack.setname('test-hwpack') | ||
359 | 72 | hwpack.sethwpack('a_hwpack') | ||
360 | 73 | self.hwpack.sethwpack('a_hwpack') | ||
361 | 74 | self.assertEqual(self.hwpack, hwpack) | ||
362 | 75 | |||
363 | 76 | def test_hwpack_class_not_equal(self): | ||
364 | 77 | hwpack = Hwpack() | ||
365 | 78 | hwpack.setname('test-hwpack') | ||
366 | 79 | hwpack.sethwpack('a_hwpack') | ||
367 | 80 | self.hwpack.sethwpack('b_hwpack') | ||
368 | 81 | self.assertNotEqual(self.hwpack, hwpack) | ||
369 | 82 | |||
370 | 83 | def test_hwpack_metadata_read(self): | ||
371 | 84 | tarball = self.add_to_tarball([('metadata', self.metadata)]) | ||
372 | 85 | reader = HwpackReader([tarball]) | ||
373 | 86 | reader._read_hwpacks_metadata() | ||
374 | 87 | self.hwpack.sethwpack(tarball) | ||
375 | 88 | self.assertEqual(self.hwpack, reader.supported_elements[0]) | ||
376 | 89 | |||
377 | 90 | def test_raise_exception(self): | ||
378 | 91 | new_metadata = ("format=2.0\nversion=4") | ||
379 | 92 | tarball = self.add_to_tarball([('metadata', new_metadata)]) | ||
380 | 93 | reader = HwpackReader([tarball]) | ||
381 | 94 | self.assertRaises(HwpackReaderError, reader._read_hwpacks_metadata) | ||
382 | 95 | |||
383 | 96 | def test_hwpack_metadata_read_with_boards(self): | ||
384 | 97 | self.metadata += "\nboards:\n panda:\n support: supported\n" | ||
385 | 98 | tarball = self.add_to_tarball([('metadata', self.metadata)]) | ||
386 | 99 | reader = HwpackReader([tarball]) | ||
387 | 100 | reader._read_hwpacks_metadata() | ||
388 | 101 | self.hwpack.sethwpack(tarball) | ||
389 | 102 | self.hwpack.setboards({'panda': {'support': 'supported'}}) | ||
390 | 103 | self.assertEqual(self.hwpack, reader.supported_elements[0]) | ||
391 | 104 | |||
392 | 105 | def test_hwpack_metadata_read_with_bootloaders(self): | ||
393 | 106 | self.metadata += ("\nboards:\n panda:\n support: supported\n " | ||
394 | 107 | "bootloaders:\n u_boot:\n file: a_file\n") | ||
395 | 108 | tarball = self.add_to_tarball([('metadata', self.metadata)]) | ||
396 | 109 | reader = HwpackReader([tarball]) | ||
397 | 110 | reader._read_hwpacks_metadata() | ||
398 | 111 | self.hwpack.sethwpack(tarball) | ||
399 | 112 | self.hwpack.setboards({'panda': {'support': 'supported', 'bootloaders': | ||
400 | 113 | {'u_boot': {'file': 'a_file'}}}}) | ||
401 | 114 | self.assertEqual(self.hwpack, reader.supported_elements[0]) | ||
402 | 0 | 115 | ||
403 | === modified file 'linaro_image_tools/media_create/__init__.py' | |||
404 | --- linaro_image_tools/media_create/__init__.py 2012-06-13 14:43:59 +0000 | |||
405 | +++ linaro_image_tools/media_create/__init__.py 2012-07-25 13:08:18 +0000 | |||
406 | @@ -92,7 +92,11 @@ | |||
407 | 92 | '--output-directory', dest='directory', | 92 | '--output-directory', dest='directory', |
408 | 93 | help='Directory where image and accessories should be written to.') | 93 | help='Directory where image and accessories should be written to.') |
409 | 94 | parser.add_argument( | 94 | parser.add_argument( |
411 | 95 | '--dev', required=True, dest='board', choices=KNOWN_BOARDS, | 95 | '--read-hwpack', dest='readhwpack', action='store_true', |
412 | 96 | help=('Read the hardware pack and print information about the ' | ||
413 | 97 | 'supported boards and bootloaders.')) | ||
414 | 98 | parser.add_argument( | ||
415 | 99 | '--dev', dest='board', choices=KNOWN_BOARDS, | ||
416 | 96 | help='Generate an SD card or image for the given board.') | 100 | help='Generate an SD card or image for the given board.') |
417 | 97 | parser.add_argument( | 101 | parser.add_argument( |
418 | 98 | '--rootfs', default='ext4', choices=['ext2', 'ext3', 'ext4', 'btrfs'], | 102 | '--rootfs', default='ext4', choices=['ext2', 'ext3', 'ext4', 'btrfs'], |
419 | @@ -137,7 +141,7 @@ | |||
420 | 137 | help=('The image size, specified in mega/giga bytes (e.g. 3000M or ' | 141 | help=('The image size, specified in mega/giga bytes (e.g. 3000M or ' |
421 | 138 | '3G); use with --image_file only')) | 142 | '3G); use with --image_file only')) |
422 | 139 | parser.add_argument( | 143 | parser.add_argument( |
424 | 140 | '--binary', default='binary-tar.tar.gz', required=True, | 144 | '--binary', default='binary-tar.tar.gz', required=False, |
425 | 141 | help=('The tarball containing the rootfs used to create the bootable ' | 145 | help=('The tarball containing the rootfs used to create the bootable ' |
426 | 142 | 'system.')) | 146 | 'system.')) |
427 | 143 | parser.add_argument( | 147 | parser.add_argument( |
428 | 144 | 148 | ||
429 | === modified file 'linaro_image_tools/utils.py' | |||
430 | --- linaro_image_tools/utils.py 2012-06-13 14:55:34 +0000 | |||
431 | +++ linaro_image_tools/utils.py 2012-07-25 13:08:18 +0000 | |||
432 | @@ -306,6 +306,15 @@ | |||
433 | 306 | """The hwpack parameter is not a regular file.""" | 306 | """The hwpack parameter is not a regular file.""" |
434 | 307 | 307 | ||
435 | 308 | 308 | ||
436 | 309 | class MissingRequiredOption(Exception): | ||
437 | 310 | """A required option from the command line is missing.""" | ||
438 | 311 | def __init__(self, value): | ||
439 | 312 | self.value = value | ||
440 | 313 | |||
441 | 314 | def __str__(self): | ||
442 | 315 | return repr(self.value) | ||
443 | 316 | |||
444 | 317 | |||
445 | 309 | class IncompatibleOptions(Exception): | 318 | class IncompatibleOptions(Exception): |
446 | 310 | def __init__(self, value): | 319 | def __init__(self, value): |
447 | 311 | self.value = value | 320 | self.value = value |
448 | @@ -331,3 +340,11 @@ | |||
449 | 331 | if not os.path.isfile(hwpack): | 340 | if not os.path.isfile(hwpack): |
450 | 332 | raise InvalidHwpackFile( | 341 | raise InvalidHwpackFile( |
451 | 333 | "--hwpack argument (%s) is not a regular file" % hwpack) | 342 | "--hwpack argument (%s) is not a regular file" % hwpack) |
452 | 343 | |||
453 | 344 | |||
454 | 345 | def check_required_args(args): | ||
455 | 346 | """Check that the required args are passed.""" | ||
456 | 347 | if args.board is None: | ||
457 | 348 | raise MissingRequiredOption("--dev option is required") | ||
458 | 349 | if args.binary is None: | ||
459 | 350 | raise MissingRequiredOption("--binary option is required") |
Looks fine now. Thanks for the changes.