Merge lp:~milo/linaro-image-tools/bug1073973 into lp:linaro-image-tools/11.11

Proposed by Milo Casagrande
Status: Merged
Approved by: Stevan Radaković
Approved revision: 602
Merged at revision: 604
Proposed branch: lp:~milo/linaro-image-tools/bug1073973
Merge into: lp:linaro-image-tools/11.11
Diff against target: 185 lines (+33/-31)
5 files modified
linaro_image_tools/hwpack/builder.py (+4/-4)
linaro_image_tools/hwpack/config.py (+18/-16)
linaro_image_tools/hwpack/handler.py (+2/-2)
linaro_image_tools/hwpack/tests/test_config_v3.py (+8/-8)
linaro_image_tools/hwpack/tests/test_script.py (+1/-1)
To merge this branch: bzr merge lp:~milo/linaro-image-tools/bug1073973
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Review via email: mp+143142@code.launchpad.net

Description of the change

The proposed branch fixes the duplicate error shown: the bootloader attribute setter and getter have been reworked. Instead of performing the lookup of the bootloader during the setter operation, now it is done during the getter one, setting the internal bootloader
variable if it is none.

Some other minor refactorings have been performed.

To post a comment you must log in.
602. By Milo Casagrande

Merged from trunk.

Revision history for this message
Stevan Radaković (stevanr) wrote :

Hey Milo, this looks good,

The diff part with method removal of set_board confused me a bit, didn't see anything about it in the description

One question regarding

86 +
87 + bootloader = property(_get_bootloader, _set_bootloader)

Shouldn't we put this property definition on the top of the class? it really looks strange being in the middle of method definition...

Revision history for this message
Milo Casagrande (milo) wrote :

Thanks Stevan for looking into it!

On Tue, Feb 12, 2013 at 10:04 AM, Stevan Radaković
<email address hidden> wrote:
> Hey Milo, this looks good,
>
> The diff part with method removal of set_board confused me a bit, didn't see anything about it in the description

Yeah... for me that was part of the minor refactorings, could have
marked that more promptly though. :-/
I removed it because it was not strictly necessary, since there is not
real data hiding and the property was not "internal" to the class, it
can be easily accessed without the function.

> One question regarding
>
> 86 +
> 87 + bootloader = property(_get_bootloader, _set_bootloader)
>
> Shouldn't we put this property definition on the top of the class? it really looks strange being in the middle of method definition...

I'm not following here... the property definition is after the
__init__ and after the two property methods (_get and _set). I cannot
move it before those or at the top of the class, or when accessing it
Python will complain that the methods are not defined.
We would have to move everything, the property and the methods, before
the __init__, but from a logical point of view I would say to keep
them after the __init__.

Ciao.

--
Milo Casagrande | Infrastructure Team
Linaro.org <www.linaro.org> │ Open source software for ARM SoCs

Revision history for this message
Stevan Radaković (stevanr) wrote :

> Thanks Stevan for looking into it!
>
> On Tue, Feb 12, 2013 at 10:04 AM, Stevan Radaković
> <email address hidden> wrote:
> > Hey Milo, this looks good,
> >
> > The diff part with method removal of set_board confused me a bit, didn't see
> anything about it in the description
>
> Yeah... for me that was part of the minor refactorings, could have
> marked that more promptly though. :-/
> I removed it because it was not strictly necessary, since there is not
> real data hiding and the property was not "internal" to the class, it
> can be easily accessed without the function.

Cool, clear..

>
> > One question regarding
> >
> > 86 +
> > 87 + bootloader = property(_get_bootloader, _set_bootloader)
> >
> > Shouldn't we put this property definition on the top of the class? it really
> looks strange being in the middle of method definition...
>
> I'm not following here... the property definition is after the
> __init__ and after the two property methods (_get and _set). I cannot
> move it before those or at the top of the class, or when accessing it
> Python will complain that the methods are not defined.
> We would have to move everything, the property and the methods, before
> the __init__, but from a logical point of view I would say to keep
> them after the __init__.
>

Oh ok I wasn't aware of this, thought you can define property first and then methods later.
Thanks for explaining.

Anyway, long overdue, approve +1 :)

> Ciao.
>
> --
> Milo Casagrande | Infrastructure Team
> Linaro.org <www.linaro.org> │ Open source software for ARM SoCs

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'linaro_image_tools/hwpack/builder.py'
--- linaro_image_tools/hwpack/builder.py 2012-10-18 13:09:21 +0000
+++ linaro_image_tools/hwpack/builder.py 2013-02-05 10:08:38 +0000
@@ -185,16 +185,16 @@
185 """Call function for each board + bootloader combination in metadata"""185 """Call function for each board + bootloader combination in metadata"""
186 if self.config.bootloaders is not None:186 if self.config.bootloaders is not None:
187 for bootloader in self.config.bootloaders:187 for bootloader in self.config.bootloaders:
188 self.config.set_board(None)188 self.config.board = None
189 self.config.set_bootloader(bootloader)189 self.config.bootloader = bootloader
190 function()190 function()
191191
192 if self.config.boards is not None:192 if self.config.boards is not None:
193 for board in self.config.boards:193 for board in self.config.boards:
194 if self.config.bootloaders is not None:194 if self.config.bootloaders is not None:
195 for bootloader in self.config.bootloaders:195 for bootloader in self.config.bootloaders:
196 self.config.set_board(board)196 self.config.board = board
197 self.config.set_bootloader(bootloader)197 self.config.bootloader = bootloader
198 function()198 function()
199199
200 def extract_files(self):200 def extract_files(self):
201201
=== modified file 'linaro_image_tools/hwpack/config.py'
--- linaro_image_tools/hwpack/config.py 2013-01-03 10:40:12 +0000
+++ linaro_image_tools/hwpack/config.py 2013-02-05 10:08:38 +0000
@@ -160,7 +160,8 @@
160 # self.allow_unset_bootloader allows for both modes of operation.160 # self.allow_unset_bootloader allows for both modes of operation.
161 self.logger = logging.getLogger('linaro_image_tools')161 self.logger = logging.getLogger('linaro_image_tools')
162 self.allow_unset_bootloader = allow_unset_bootloader162 self.allow_unset_bootloader = allow_unset_bootloader
163 self.bootloader = None163 self.board = board
164 self._bootloader = bootloader
164165
165 obfuscated_e = None166 obfuscated_e = None
166 obfuscated_yaml_e = ""167 obfuscated_yaml_e = ""
@@ -183,10 +184,6 @@
183 else:184 else:
184 # If YAML parsed OK, we don't have an error.185 # If YAML parsed OK, we don't have an error.
185 obfuscated_e = None186 obfuscated_e = None
186 if board:
187 self.set_board(board)
188 if bootloader:
189 self.set_bootloader(bootloader)
190187
191 if obfuscated_e:188 if obfuscated_e:
192 # If INI parsing from ConfigParser or YAML parsing failed,189 # If INI parsing from ConfigParser or YAML parsing failed,
@@ -198,12 +195,12 @@
198 obfuscated_yaml_e)195 obfuscated_yaml_e)
199 raise ConfigParser.Error(msg)196 raise ConfigParser.Error(msg)
200197
201 def set_bootloader(self, bootloader):198 def _get_bootloader(self):
202 """Set bootloader used to look up configuration in bootloader section.199 """Returns the bootloader associated with this config.
203200
204 If bootloader is None / empty and there is only one bootloader201 If bootloader is None / empty and there is only one bootloader
205 available, use that.202 available, use that."""
206 """203 bootloader = self._bootloader
207 if not bootloader:204 if not bootloader:
208 # Auto-detect bootloader. If there is a single bootloader specified205 # Auto-detect bootloader. If there is a single bootloader specified
209 # then use it, else, error.206 # then use it, else, error.
@@ -227,12 +224,17 @@
227 'found. Will try to use \'%s\'. '224 'found. Will try to use \'%s\'. '
228 'instead.' % (DEFAULT_BOOTLOADER,225 'instead.' % (DEFAULT_BOOTLOADER,
229 bootloader))226 bootloader))
230227 # bootloader is None: since we are here, set it so we do not
231 self.bootloader = bootloader228 # have to go through all the config retrieval again.
232229 self._bootloader = bootloader
233 def set_board(self, board):230 return bootloader
234 """Set board used to look up per-board configuration"""231
235 self.board = board232 def _set_bootloader(self, value):
233 """Set bootloader used to look up configuration in bootloader section.
234 """
235 self._bootloader = value
236
237 bootloader = property(_get_bootloader, _set_bootloader)
236238
237 def get_bootloader_list(self):239 def get_bootloader_list(self):
238 if isinstance(self.bootloaders, dict):240 if isinstance(self.bootloaders, dict):
@@ -272,7 +274,7 @@
272 # Check config for all bootloaders if one isn't specified.274 # Check config for all bootloaders if one isn't specified.
273 if not self.bootloader and self._is_v3:275 if not self.bootloader and self._is_v3:
274 for bootloader in self.get_bootloader_list():276 for bootloader in self.get_bootloader_list():
275 self.set_bootloader(bootloader)277 self.bootloader = bootloader
276 self.validate_bootloader_fields()278 self.validate_bootloader_fields()
277 else:279 else:
278 self.validate_bootloader_fields()280 self.validate_bootloader_fields()
279281
=== modified file 'linaro_image_tools/hwpack/handler.py'
--- linaro_image_tools/hwpack/handler.py 2012-12-07 09:37:42 +0000
+++ linaro_image_tools/hwpack/handler.py 2013-02-05 10:08:38 +0000
@@ -105,8 +105,8 @@
105 # Probably V2 hardware pack without [hwpack] on the first line105 # Probably V2 hardware pack without [hwpack] on the first line
106 lines = ["[hwpack]\n"] + lines106 lines = ["[hwpack]\n"] + lines
107 self.config = Config(StringIO("".join(lines)))107 self.config = Config(StringIO("".join(lines)))
108 self.config.set_board(self.board)108 self.config.board = self.board
109 self.config.set_bootloader(self.bootloader)109 self.config.bootloader = self.bootloader
110 return self.config110 return self.config
111111
112 def get_field(self, field, return_keys=False):112 def get_field(self, field, return_keys=False):
113113
=== modified file 'linaro_image_tools/hwpack/tests/test_config_v3.py'
--- linaro_image_tools/hwpack/tests/test_config_v3.py 2013-01-03 10:40:12 +0000
+++ linaro_image_tools/hwpack/tests/test_config_v3.py 2013-02-05 10:08:38 +0000
@@ -245,7 +245,7 @@
245 "bootloaders:\n"245 "bootloaders:\n"
246 " u_boot:\n"246 " u_boot:\n"
247 " spl_package: ~~\n")247 " spl_package: ~~\n")
248 config.set_board("panda")248 config.board = "panda"
249 self.assertValidationError(249 self.assertValidationError(
250 "Invalid value in spl_package in the metadata: ~~",250 "Invalid value in spl_package in the metadata: ~~",
251 config._validate_spl_package)251 config._validate_spl_package)
@@ -257,7 +257,7 @@
257 " bootloaders:\n"257 " bootloaders:\n"
258 " u_boot:\n"258 " u_boot:\n"
259 " spl_file: ~~\n")259 " spl_file: ~~\n")
260 config.set_board("panda")260 config.board = "panda"
261 self.assertValidationError("Invalid path: ~~",261 self.assertValidationError("Invalid path: ~~",
262 config._validate_spl_file)262 config._validate_spl_file)
263263
@@ -297,8 +297,8 @@
297 " u_boot:\n"297 " u_boot:\n"
298 " in_boot_part: Yes\n")298 " in_boot_part: Yes\n")
299299
300 config.set_bootloader("u_boot")300 config.bootloader = "u_boot"
301 config.set_board("panda")301 config.board = "panda"
302302
303 config._validate_bootloader_file_in_boot_part()303 config._validate_bootloader_file_in_boot_part()
304 self.assertEqual(config.bootloader_file_in_boot_part, "yes")304 self.assertEqual(config.bootloader_file_in_boot_part, "yes")
@@ -315,8 +315,8 @@
315 " u_boot:\n"315 " u_boot:\n"
316 " in_boot_part: Yes\n")316 " in_boot_part: Yes\n")
317317
318 config.set_bootloader("u_boot")318 config.bootloader = "u_boot"
319 config.set_board("panda")319 config.board = "panda"
320320
321 config._validate_bootloader_file_in_boot_part()321 config._validate_bootloader_file_in_boot_part()
322 self.assertEqual(config.bootloader_file_in_boot_part, "yes")322 self.assertEqual(config.bootloader_file_in_boot_part, "yes")
@@ -330,11 +330,11 @@
330 " anotherboot:\n"330 " anotherboot:\n"
331 " in_boot_part: Yes\n")331 " in_boot_part: Yes\n")
332332
333 config.set_bootloader("u_boot")333 config.bootloader = "u_boot"
334 config._validate_bootloader_file_in_boot_part()334 config._validate_bootloader_file_in_boot_part()
335 self.assertEqual(config.bootloader_file_in_boot_part, "no")335 self.assertEqual(config.bootloader_file_in_boot_part, "no")
336336
337 config.set_bootloader("anotherboot")337 config.bootloader = "anotherboot"
338 config._validate_bootloader_file_in_boot_part()338 config._validate_bootloader_file_in_boot_part()
339 self.assertEqual(config.bootloader_file_in_boot_part, "yes")339 self.assertEqual(config.bootloader_file_in_boot_part, "yes")
340340
341341
=== modified file 'linaro_image_tools/hwpack/tests/test_script.py'
--- linaro_image_tools/hwpack/tests/test_script.py 2012-08-29 15:01:41 +0000
+++ linaro_image_tools/hwpack/tests/test_script.py 2013-02-05 10:08:38 +0000
@@ -168,7 +168,7 @@
168 # We now need a real config object to test against the configuration168 # We now need a real config object to test against the configuration
169 # in the hardware pack we have created.169 # in the hardware pack we have created.
170 config = Config(StringIO(config_v3))170 config = Config(StringIO(config_v3))
171 config.set_bootloader("u_boot")171 config.bootloader = "u_boot"
172 metadata = Metadata.from_config(config, "1.0", "armel")172 metadata = Metadata.from_config(config, "1.0", "armel")
173 self.assertThat(173 self.assertThat(
174 "hwpack_ahwpack_1.0_armel.tar.gz",174 "hwpack_ahwpack_1.0_armel.tar.gz",

Subscribers

People subscribed via source and target branches