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
1=== modified file 'linaro_image_tools/hwpack/builder.py'
2--- linaro_image_tools/hwpack/builder.py 2012-10-18 13:09:21 +0000
3+++ linaro_image_tools/hwpack/builder.py 2013-02-05 10:08:38 +0000
4@@ -185,16 +185,16 @@
5 """Call function for each board + bootloader combination in metadata"""
6 if self.config.bootloaders is not None:
7 for bootloader in self.config.bootloaders:
8- self.config.set_board(None)
9- self.config.set_bootloader(bootloader)
10+ self.config.board = None
11+ self.config.bootloader = bootloader
12 function()
13
14 if self.config.boards is not None:
15 for board in self.config.boards:
16 if self.config.bootloaders is not None:
17 for bootloader in self.config.bootloaders:
18- self.config.set_board(board)
19- self.config.set_bootloader(bootloader)
20+ self.config.board = board
21+ self.config.bootloader = bootloader
22 function()
23
24 def extract_files(self):
25
26=== modified file 'linaro_image_tools/hwpack/config.py'
27--- linaro_image_tools/hwpack/config.py 2013-01-03 10:40:12 +0000
28+++ linaro_image_tools/hwpack/config.py 2013-02-05 10:08:38 +0000
29@@ -160,7 +160,8 @@
30 # self.allow_unset_bootloader allows for both modes of operation.
31 self.logger = logging.getLogger('linaro_image_tools')
32 self.allow_unset_bootloader = allow_unset_bootloader
33- self.bootloader = None
34+ self.board = board
35+ self._bootloader = bootloader
36
37 obfuscated_e = None
38 obfuscated_yaml_e = ""
39@@ -183,10 +184,6 @@
40 else:
41 # If YAML parsed OK, we don't have an error.
42 obfuscated_e = None
43- if board:
44- self.set_board(board)
45- if bootloader:
46- self.set_bootloader(bootloader)
47
48 if obfuscated_e:
49 # If INI parsing from ConfigParser or YAML parsing failed,
50@@ -198,12 +195,12 @@
51 obfuscated_yaml_e)
52 raise ConfigParser.Error(msg)
53
54- def set_bootloader(self, bootloader):
55- """Set bootloader used to look up configuration in bootloader section.
56+ def _get_bootloader(self):
57+ """Returns the bootloader associated with this config.
58
59 If bootloader is None / empty and there is only one bootloader
60- available, use that.
61- """
62+ available, use that."""
63+ bootloader = self._bootloader
64 if not bootloader:
65 # Auto-detect bootloader. If there is a single bootloader specified
66 # then use it, else, error.
67@@ -227,12 +224,17 @@
68 'found. Will try to use \'%s\'. '
69 'instead.' % (DEFAULT_BOOTLOADER,
70 bootloader))
71-
72- self.bootloader = bootloader
73-
74- def set_board(self, board):
75- """Set board used to look up per-board configuration"""
76- self.board = board
77+ # bootloader is None: since we are here, set it so we do not
78+ # have to go through all the config retrieval again.
79+ self._bootloader = bootloader
80+ return bootloader
81+
82+ def _set_bootloader(self, value):
83+ """Set bootloader used to look up configuration in bootloader section.
84+ """
85+ self._bootloader = value
86+
87+ bootloader = property(_get_bootloader, _set_bootloader)
88
89 def get_bootloader_list(self):
90 if isinstance(self.bootloaders, dict):
91@@ -272,7 +274,7 @@
92 # Check config for all bootloaders if one isn't specified.
93 if not self.bootloader and self._is_v3:
94 for bootloader in self.get_bootloader_list():
95- self.set_bootloader(bootloader)
96+ self.bootloader = bootloader
97 self.validate_bootloader_fields()
98 else:
99 self.validate_bootloader_fields()
100
101=== modified file 'linaro_image_tools/hwpack/handler.py'
102--- linaro_image_tools/hwpack/handler.py 2012-12-07 09:37:42 +0000
103+++ linaro_image_tools/hwpack/handler.py 2013-02-05 10:08:38 +0000
104@@ -105,8 +105,8 @@
105 # Probably V2 hardware pack without [hwpack] on the first line
106 lines = ["[hwpack]\n"] + lines
107 self.config = Config(StringIO("".join(lines)))
108- self.config.set_board(self.board)
109- self.config.set_bootloader(self.bootloader)
110+ self.config.board = self.board
111+ self.config.bootloader = self.bootloader
112 return self.config
113
114 def get_field(self, field, return_keys=False):
115
116=== modified file 'linaro_image_tools/hwpack/tests/test_config_v3.py'
117--- linaro_image_tools/hwpack/tests/test_config_v3.py 2013-01-03 10:40:12 +0000
118+++ linaro_image_tools/hwpack/tests/test_config_v3.py 2013-02-05 10:08:38 +0000
119@@ -245,7 +245,7 @@
120 "bootloaders:\n"
121 " u_boot:\n"
122 " spl_package: ~~\n")
123- config.set_board("panda")
124+ config.board = "panda"
125 self.assertValidationError(
126 "Invalid value in spl_package in the metadata: ~~",
127 config._validate_spl_package)
128@@ -257,7 +257,7 @@
129 " bootloaders:\n"
130 " u_boot:\n"
131 " spl_file: ~~\n")
132- config.set_board("panda")
133+ config.board = "panda"
134 self.assertValidationError("Invalid path: ~~",
135 config._validate_spl_file)
136
137@@ -297,8 +297,8 @@
138 " u_boot:\n"
139 " in_boot_part: Yes\n")
140
141- config.set_bootloader("u_boot")
142- config.set_board("panda")
143+ config.bootloader = "u_boot"
144+ config.board = "panda"
145
146 config._validate_bootloader_file_in_boot_part()
147 self.assertEqual(config.bootloader_file_in_boot_part, "yes")
148@@ -315,8 +315,8 @@
149 " u_boot:\n"
150 " in_boot_part: Yes\n")
151
152- config.set_bootloader("u_boot")
153- config.set_board("panda")
154+ config.bootloader = "u_boot"
155+ config.board = "panda"
156
157 config._validate_bootloader_file_in_boot_part()
158 self.assertEqual(config.bootloader_file_in_boot_part, "yes")
159@@ -330,11 +330,11 @@
160 " anotherboot:\n"
161 " in_boot_part: Yes\n")
162
163- config.set_bootloader("u_boot")
164+ config.bootloader = "u_boot"
165 config._validate_bootloader_file_in_boot_part()
166 self.assertEqual(config.bootloader_file_in_boot_part, "no")
167
168- config.set_bootloader("anotherboot")
169+ config.bootloader = "anotherboot"
170 config._validate_bootloader_file_in_boot_part()
171 self.assertEqual(config.bootloader_file_in_boot_part, "yes")
172
173
174=== modified file 'linaro_image_tools/hwpack/tests/test_script.py'
175--- linaro_image_tools/hwpack/tests/test_script.py 2012-08-29 15:01:41 +0000
176+++ linaro_image_tools/hwpack/tests/test_script.py 2013-02-05 10:08:38 +0000
177@@ -168,7 +168,7 @@
178 # We now need a real config object to test against the configuration
179 # in the hardware pack we have created.
180 config = Config(StringIO(config_v3))
181- config.set_bootloader("u_boot")
182+ config.bootloader = "u_boot"
183 metadata = Metadata.from_config(config, "1.0", "armel")
184 self.assertThat(
185 "hwpack_ahwpack_1.0_armel.tar.gz",

Subscribers

People subscribed via source and target branches