Merge lp:~milo/linaro-image-tools/bug1059579 into lp:linaro-image-tools/11.11
- bug1059579
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 581 | ||||
Proposed branch: | lp:~milo/linaro-image-tools/bug1059579 | ||||
Merge into: | lp:linaro-image-tools/11.11 | ||||
Diff against target: |
506 lines (+81/-104) 10 files modified
linaro-hwpack-convert (+4/-22) linaro-hwpack-create (+8/-18) linaro-hwpack-replace (+3/-17) linaro-media-create (+17/-22) linaro_image_tools/hwpack/__init__.py (+2/-1) linaro_image_tools/hwpack/hwpack_convert.py (+1/-1) linaro_image_tools/media_create/__init__.py (+1/-0) linaro_image_tools/media_create/boards.py (+2/-12) linaro_image_tools/media_create/partitions.py (+2/-2) linaro_image_tools/utils.py (+41/-9) |
||||
To merge this branch: | bzr merge lp:~milo/linaro-image-tools/bug1059579 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Paul Sokolovsky | Approve | ||
James Tunnicliffe | Pending | ||
linaro-image-tools maintainers | Pending | ||
Review via email: mp+128029@code.launchpad.net |
Commit message
Description of the change
The proposed branch cleans up a little bit the logger functionalities in linaro-image-tools.
We now have a single method in utils.py used by all the cli tools when setting up parameters. All the other methods/classes will just call default Python logging with their module name as parameter for logging.
This has a small "drawback": when running the tests output from the logger is not shown anymore, so we do not see the "WARNING" for hwpack format 1.0.
- 572. By Fathi Boudra
-
Add Build-Info support.
- 573. By Ricardo Salveti
-
Added support for Foundation fastmodel.
- 574. By Fathi Boudra
-
Build-Info support:
* manifest file isn't license protected (open).
* create an open BUILD-INFO.txt when no protected files are available. - 575. By Fathi Boudra
-
Skip symlink-ed or invalid debian package file. (LP: #1065826)
- 576. By Fathi Boudra
-
Export the updated manifest when manipulating with linaro-
hwpack- replace. - 577. By Paul Sokolovsky
-
[merge] Allow to override initrd_high and fdt_high uboot params, do so for Snowball.
- 578. By Milo Casagrande
-
Added dtb_files support to hwpack config converter.
- 579. By Milo Casagrande
-
Code refactoring for build() method.
- 580. By Fathi Boudra
-
Workaroun IOError in test case.
- 581. By Milo Casagrande
-
Use common logging infrastructure, add --debug option to linaro-
media-create.
Preview Diff
1 | === modified file 'linaro-hwpack-convert' | |||
2 | --- linaro-hwpack-convert 2012-07-23 07:07:55 +0000 | |||
3 | +++ linaro-hwpack-convert 2012-10-04 14:31:36 +0000 | |||
4 | @@ -22,35 +22,17 @@ | |||
5 | 22 | 22 | ||
6 | 23 | 23 | ||
7 | 24 | import argparse | 24 | import argparse |
8 | 25 | import logging | ||
9 | 26 | import sys | 25 | import sys |
10 | 27 | import os | ||
11 | 28 | 26 | ||
12 | 29 | from linaro_image_tools.hwpack.hwpack_convert import ( | 27 | from linaro_image_tools.hwpack.hwpack_convert import ( |
13 | 30 | HwpackConverter, | 28 | HwpackConverter, |
14 | 31 | HwpackConverterException, | 29 | HwpackConverterException, |
15 | 32 | check_and_validate_args, | 30 | check_and_validate_args, |
16 | 33 | ) | 31 | ) |
17 | 32 | from linaro_image_tools.utils import get_logger | ||
18 | 34 | from linaro_image_tools.__version__ import __version__ | 33 | from linaro_image_tools.__version__ import __version__ |
19 | 35 | 34 | ||
20 | 36 | 35 | ||
21 | 37 | def get_logger(debug=False): | ||
22 | 38 | ch = logging.StreamHandler() | ||
23 | 39 | logger = logging.getLogger("linaro_hwpack_converter") | ||
24 | 40 | |||
25 | 41 | if debug: | ||
26 | 42 | ch.setLevel(logging.DEBUG) | ||
27 | 43 | formatter = logging.Formatter( | ||
28 | 44 | "%(asctime)s - %(name)s - %(levelname)s - %(message)s") | ||
29 | 45 | ch.setFormatter(formatter) | ||
30 | 46 | logger.setLevel(logging.DEBUG) | ||
31 | 47 | else: | ||
32 | 48 | ch.setLevel(logging.INFO) | ||
33 | 49 | formatter = logging.Formatter("%(message)s") | ||
34 | 50 | ch.setFormatter(formatter) | ||
35 | 51 | logger.setLevel(logging.INFO) | ||
36 | 52 | logger.addHandler(ch) | ||
37 | 53 | |||
38 | 54 | if __name__ == '__main__': | 36 | if __name__ == '__main__': |
39 | 55 | parser = argparse.ArgumentParser(version='%(prog)s ' + __version__) | 37 | parser = argparse.ArgumentParser(version='%(prog)s ' + __version__) |
40 | 56 | parser.add_argument("CONFIG_FILE", | 38 | parser.add_argument("CONFIG_FILE", |
41 | @@ -64,10 +46,10 @@ | |||
42 | 64 | logger = get_logger(debug=args.debug) | 46 | logger = get_logger(debug=args.debug) |
43 | 65 | try: | 47 | try: |
44 | 66 | input_file, output_file = check_and_validate_args(args) | 48 | input_file, output_file = check_and_validate_args(args) |
46 | 67 | print "Converting '%s' into new YAML format..." % (input_file) | 49 | logger.info("Converting '%s' into new YAML format..." % input_file) |
47 | 68 | converter = HwpackConverter(input_file, output_file) | 50 | converter = HwpackConverter(input_file, output_file) |
48 | 69 | except HwpackConverterException, e: | 51 | except HwpackConverterException, e: |
50 | 70 | sys.stderr.write(str(e) + "\n") | 52 | logger.error(str(e)) |
51 | 71 | sys.exit(1) | 53 | sys.exit(1) |
52 | 72 | converter.convert() | 54 | converter.convert() |
54 | 73 | print "File '%s' converted in '%s'." % (input_file, output_file) | 55 | logger.info("File '%s' converted in '%s'." % (input_file, output_file)) |
55 | 74 | 56 | ||
56 | === modified file 'linaro-hwpack-create' | |||
57 | --- linaro-hwpack-create 2011-10-03 08:18:45 +0000 | |||
58 | +++ linaro-hwpack-create 2012-10-04 14:31:36 +0000 | |||
59 | @@ -21,14 +21,14 @@ | |||
60 | 21 | # USA. | 21 | # USA. |
61 | 22 | 22 | ||
62 | 23 | import argparse | 23 | import argparse |
63 | 24 | import logging | ||
64 | 25 | import sys | 24 | import sys |
65 | 26 | 25 | ||
66 | 27 | from linaro_image_tools.hwpack.builder import ( | 26 | from linaro_image_tools.hwpack.builder import ( |
67 | 28 | ConfigFileMissing, HardwarePackBuilder) | 27 | ConfigFileMissing, HardwarePackBuilder) |
69 | 29 | 28 | from linaro_image_tools.utils import get_logger | |
70 | 30 | from linaro_image_tools.__version__ import __version__ | 29 | from linaro_image_tools.__version__ import __version__ |
71 | 31 | 30 | ||
72 | 31 | |||
73 | 32 | if __name__ == '__main__': | 32 | if __name__ == '__main__': |
74 | 33 | parser = argparse.ArgumentParser(version='%(prog)s ' + __version__) | 33 | parser = argparse.ArgumentParser(version='%(prog)s ' + __version__) |
75 | 34 | parser.add_argument( | 34 | parser.add_argument( |
76 | @@ -44,24 +44,14 @@ | |||
77 | 44 | "version than a package that would be otherwise installed. " | 44 | "version than a package that would be otherwise installed. " |
78 | 45 | "Can be used more than once.")) | 45 | "Can be used more than once.")) |
79 | 46 | parser.add_argument("--debug", action="store_true") | 46 | parser.add_argument("--debug", action="store_true") |
80 | 47 | |||
81 | 47 | args = parser.parse_args() | 48 | args = parser.parse_args() |
95 | 48 | ch = logging.StreamHandler() | 49 | logger = get_logger(debug=args.debug) |
96 | 49 | ch.setLevel(logging.INFO) | 50 | |
84 | 50 | formatter = logging.Formatter("%(message)s") | ||
85 | 51 | ch.setFormatter(formatter) | ||
86 | 52 | logger = logging.getLogger("linaro_image_tools") | ||
87 | 53 | logger.setLevel(logging.INFO) | ||
88 | 54 | logger.addHandler(ch) | ||
89 | 55 | if args.debug: | ||
90 | 56 | ch.setLevel(logging.DEBUG) | ||
91 | 57 | formatter = logging.Formatter( | ||
92 | 58 | "%(asctime)s - %(name)s - %(levelname)s - %(message)s") | ||
93 | 59 | ch.setFormatter(formatter) | ||
94 | 60 | logger.setLevel(logging.DEBUG) | ||
97 | 61 | try: | 51 | try: |
100 | 62 | builder = HardwarePackBuilder( | 52 | builder = HardwarePackBuilder(args.CONFIG_FILE, |
101 | 63 | args.CONFIG_FILE, args.VERSION, args.local_debs) | 53 | args.VERSION, args.local_debs) |
102 | 64 | except ConfigFileMissing, e: | 54 | except ConfigFileMissing, e: |
104 | 65 | sys.stderr.write(str(e) + "\n") | 55 | logger.error(str(e)) |
105 | 66 | sys.exit(1) | 56 | sys.exit(1) |
106 | 67 | builder.build() | 57 | builder.build() |
107 | 68 | 58 | ||
108 | === modified file 'linaro-hwpack-replace' | |||
109 | --- linaro-hwpack-replace 2011-10-13 12:11:28 +0000 | |||
110 | +++ linaro-hwpack-replace 2012-10-04 14:31:36 +0000 | |||
111 | @@ -26,7 +26,6 @@ | |||
112 | 26 | import sys | 26 | import sys |
113 | 27 | import shutil | 27 | import shutil |
114 | 28 | import glob | 28 | import glob |
115 | 29 | import logging | ||
116 | 30 | import tarfile | 29 | import tarfile |
117 | 31 | import tempfile | 30 | import tempfile |
118 | 32 | import argparse | 31 | import argparse |
119 | @@ -35,6 +34,7 @@ | |||
120 | 35 | from debian.deb822 import Packages | 34 | from debian.deb822 import Packages |
121 | 36 | from linaro_image_tools.hwpack.packages import get_packages_file | 35 | from linaro_image_tools.hwpack.packages import get_packages_file |
122 | 37 | from linaro_image_tools.hwpack.packages import FetchedPackage | 36 | from linaro_image_tools.hwpack.packages import FetchedPackage |
123 | 37 | from linaro_image_tools.utils import get_logger | ||
124 | 38 | 38 | ||
125 | 39 | 39 | ||
126 | 40 | parser = argparse.ArgumentParser() | 40 | parser = argparse.ArgumentParser() |
127 | @@ -53,7 +53,7 @@ | |||
128 | 53 | parser.add_argument("-d", "--debug-output", action="store_true", dest="debug", | 53 | parser.add_argument("-d", "--debug-output", action="store_true", dest="debug", |
129 | 54 | help="Verbose messages are displayed when specified") | 54 | help="Verbose messages are displayed when specified") |
130 | 55 | 55 | ||
132 | 56 | logger = logging.getLogger("linaro-hwpack-replace") | 56 | logger = None |
133 | 57 | 57 | ||
134 | 58 | 58 | ||
135 | 59 | class DummyStanza(object): | 59 | class DummyStanza(object): |
136 | @@ -65,20 +65,6 @@ | |||
137 | 65 | fd.write(get_packages_file([self.info])) | 65 | fd.write(get_packages_file([self.info])) |
138 | 66 | 66 | ||
139 | 67 | 67 | ||
140 | 68 | def set_logging_param(args): | ||
141 | 69 | ch = logging.StreamHandler() | ||
142 | 70 | ch.setLevel(logging.INFO) | ||
143 | 71 | formatter = logging.Formatter("%(message)s") | ||
144 | 72 | ch.setFormatter(formatter) | ||
145 | 73 | logger.setLevel(logging.INFO) | ||
146 | 74 | logger.addHandler(ch) | ||
147 | 75 | if args.debug: | ||
148 | 76 | ch.setLevel(logging.DEBUG) | ||
149 | 77 | formatter = logging.Formatter( | ||
150 | 78 | "%(asctime)s - %(name)s - %(levelname)s - %(message)s") | ||
151 | 79 | ch.setFormatter(formatter) | ||
152 | 80 | logger.setLevel(logging.DEBUG) | ||
153 | 81 | |||
154 | 82 | 68 | ||
155 | 83 | def get_hwpack_name(old_hwpack, build_number): | 69 | def get_hwpack_name(old_hwpack, build_number): |
156 | 84 | # The build_number would be the job build number. | 70 | # The build_number would be the job build number. |
157 | @@ -178,7 +164,7 @@ | |||
158 | 178 | "and the debian package information\n") | 164 | "and the debian package information\n") |
159 | 179 | return 1 | 165 | return 1 |
160 | 180 | 166 | ||
162 | 181 | set_logging_param(args) | 167 | logger = get_logger(debug=args.debug) |
163 | 182 | 168 | ||
164 | 183 | old_hwpack = args.hwpack_name | 169 | old_hwpack = args.hwpack_name |
165 | 184 | new_deb_file_to_copy = args.deb_pack | 170 | new_deb_file_to_copy = args.deb_pack |
166 | 185 | 171 | ||
167 | === modified file 'linaro-media-create' | |||
168 | --- linaro-media-create 2012-10-01 12:50:55 +0000 | |||
169 | +++ linaro-media-create 2012-10-04 14:31:36 +0000 | |||
170 | @@ -22,7 +22,6 @@ | |||
171 | 22 | import os | 22 | import os |
172 | 23 | import sys | 23 | import sys |
173 | 24 | import tempfile | 24 | import tempfile |
174 | 25 | import logging | ||
175 | 26 | 25 | ||
176 | 27 | from linaro_image_tools import cmd_runner | 26 | from linaro_image_tools import cmd_runner |
177 | 28 | 27 | ||
178 | @@ -57,6 +56,7 @@ | |||
179 | 57 | MissingRequiredOption, | 56 | MissingRequiredOption, |
180 | 58 | path_in_tarfile_exists, | 57 | path_in_tarfile_exists, |
181 | 59 | prep_media_path, | 58 | prep_media_path, |
182 | 59 | get_logger, | ||
183 | 60 | ) | 60 | ) |
184 | 61 | 61 | ||
185 | 62 | # Just define the global variables | 62 | # Just define the global variables |
186 | @@ -106,35 +106,29 @@ | |||
187 | 106 | parser = get_args_parser() | 106 | parser = get_args_parser() |
188 | 107 | args = parser.parse_args() | 107 | args = parser.parse_args() |
189 | 108 | 108 | ||
197 | 109 | ch = logging.StreamHandler() | 109 | logger = get_logger(debug=args.debug) |
191 | 110 | ch.setLevel(logging.INFO) | ||
192 | 111 | formatter = logging.Formatter("%(message)s") | ||
193 | 112 | ch.setFormatter(formatter) | ||
194 | 113 | logger = logging.getLogger("linaro_image_tools") | ||
195 | 114 | logger.setLevel(logging.INFO) | ||
196 | 115 | logger.addHandler(ch) | ||
198 | 116 | 110 | ||
199 | 117 | try: | 111 | try: |
200 | 118 | additional_option_checks(args) | 112 | additional_option_checks(args) |
201 | 119 | except IncompatibleOptions as e: | 113 | except IncompatibleOptions as e: |
202 | 120 | parser.print_help() | 114 | parser.print_help() |
204 | 121 | print >> sys.stderr, "\nError:", e.value | 115 | logger.error(e.value) |
205 | 122 | sys.exit(1) | 116 | sys.exit(1) |
206 | 123 | 117 | ||
207 | 124 | if args.readhwpack: | 118 | if args.readhwpack: |
208 | 125 | try: | 119 | try: |
209 | 126 | reader = HwpackReader(args.hwpacks) | 120 | reader = HwpackReader(args.hwpacks) |
211 | 127 | print reader.get_supported_boards() | 121 | logger.info(reader.get_supported_boards()) |
212 | 128 | sys.exit(0) | 122 | sys.exit(0) |
213 | 129 | except HwpackReaderError as e: | 123 | except HwpackReaderError as e: |
215 | 130 | print >> sys.stderr, "\nError:", e.value | 124 | logger.error(e.value) |
216 | 131 | sys.exit(1) | 125 | sys.exit(1) |
217 | 132 | 126 | ||
218 | 133 | try: | 127 | try: |
219 | 134 | check_required_args(args) | 128 | check_required_args(args) |
220 | 135 | except MissingRequiredOption as e: | 129 | except MissingRequiredOption as e: |
221 | 136 | parser.print_help() | 130 | parser.print_help() |
223 | 137 | print >> sys.stderr, "\nError:", e.value | 131 | logger.error(e.value) |
224 | 138 | sys.exit(1) | 132 | sys.exit(1) |
225 | 139 | 133 | ||
226 | 140 | board_config = board_configs[args.dev] | 134 | board_config = board_configs[args.dev] |
227 | @@ -147,16 +141,16 @@ | |||
228 | 147 | 141 | ||
229 | 148 | if media.is_block_device: | 142 | if media.is_block_device: |
230 | 149 | if not board_config.supports_writing_to_mmc: | 143 | if not board_config.supports_writing_to_mmc: |
234 | 150 | print ("The board '%s' does not support the --mmc option. " | 144 | logger.error("The board '%s' does not support the --mmc option. " |
235 | 151 | "Please use --image_file to create an image file for this " | 145 | "Please use --image_file to create an image file for " |
236 | 152 | "board." % args.dev) | 146 | "this board." % args.dev) |
237 | 153 | sys.exit(1) | 147 | sys.exit(1) |
238 | 154 | if not confirm_device_selection_and_ensure_it_is_ready( | 148 | if not confirm_device_selection_and_ensure_it_is_ready( |
239 | 155 | args.device, args.nocheck_mmc): | 149 | args.device, args.nocheck_mmc): |
240 | 156 | sys.exit(1) | 150 | sys.exit(1) |
241 | 157 | elif not args.should_format_rootfs or not args.should_format_bootfs: | 151 | elif not args.should_format_rootfs or not args.should_format_bootfs: |
244 | 158 | print ("Do not use --no-boot or --no-part in conjunction with " | 152 | logger.error("Do not use --no-boot or --no-part in conjunction with " |
245 | 159 | "--image_file.") | 153 | "--image_file.") |
246 | 160 | sys.exit(1) | 154 | sys.exit(1) |
247 | 161 | else: | 155 | else: |
248 | 162 | # All good, move on. | 156 | # All good, move on. |
249 | @@ -170,6 +164,7 @@ | |||
250 | 170 | BIN_DIR = os.path.join(TMP_DIR, 'rootfs') | 164 | BIN_DIR = os.path.join(TMP_DIR, 'rootfs') |
251 | 171 | os.mkdir(BIN_DIR) | 165 | os.mkdir(BIN_DIR) |
252 | 172 | 166 | ||
253 | 167 | logger.info('Searching correct rootfs path') | ||
254 | 173 | # Identify the correct path for the rootfs | 168 | # Identify the correct path for the rootfs |
255 | 174 | filesystem_dir = '' | 169 | filesystem_dir = '' |
256 | 175 | if path_in_tarfile_exists('binary/etc', args.binary): | 170 | if path_in_tarfile_exists('binary/etc', args.binary): |
257 | @@ -212,12 +207,12 @@ | |||
258 | 212 | 207 | ||
259 | 213 | if args.rootfs == 'btrfs': | 208 | if args.rootfs == 'btrfs': |
260 | 214 | if not extract_kpkgs: | 209 | if not extract_kpkgs: |
263 | 215 | print ("Desired rootfs type is 'btrfs', trying to auto-install " | 210 | logger.info("Desired rootfs type is 'btrfs', trying to " |
264 | 216 | "the 'btrfs-tools' package") | 211 | "auto-install the 'btrfs-tools' package") |
265 | 217 | install_packages(ROOTFS_DIR, TMP_DIR, "btrfs-tools") | 212 | install_packages(ROOTFS_DIR, TMP_DIR, "btrfs-tools") |
266 | 218 | else: | 213 | else: |
269 | 219 | print ("Desired rootfs type is 'btrfs', please make sure the " | 214 | logger.info("Desired rootfs type is 'btrfs', please make sure the " |
270 | 220 | "rootfs also includes 'btrfs-tools'") | 215 | "rootfs also includes 'btrfs-tools'") |
271 | 221 | 216 | ||
272 | 222 | boot_partition, root_partition = setup_partitions( | 217 | boot_partition, root_partition = setup_partitions( |
273 | 223 | board_config, media, args.image_size, args.boot_label, args.rfs_label, | 218 | board_config, media, args.image_size, args.boot_label, args.rfs_label, |
274 | @@ -248,4 +243,4 @@ | |||
275 | 248 | board_config.mmc_device_id, board_config.mmc_part_offset, | 243 | board_config.mmc_device_id, board_config.mmc_part_offset, |
276 | 249 | board_config) | 244 | board_config) |
277 | 250 | 245 | ||
279 | 251 | print "Done creating Linaro image on %s" % media.path | 246 | logger.info("Done creating Linaro image on %s" % media.path) |
280 | 252 | 247 | ||
281 | === modified file 'linaro_image_tools/hwpack/__init__.py' | |||
282 | --- linaro_image_tools/hwpack/__init__.py 2012-06-13 14:26:02 +0000 | |||
283 | +++ linaro_image_tools/hwpack/__init__.py 2012-10-04 14:31:36 +0000 | |||
284 | @@ -20,6 +20,7 @@ | |||
285 | 20 | # USA. | 20 | # USA. |
286 | 21 | 21 | ||
287 | 22 | import logging | 22 | import logging |
288 | 23 | from linaro_image_tools.utils import DEFAULT_LOGGER_NAME | ||
289 | 23 | 24 | ||
290 | 24 | 25 | ||
291 | 25 | class NullHandler(logging.Handler): | 26 | class NullHandler(logging.Handler): |
292 | @@ -28,4 +29,4 @@ | |||
293 | 28 | 29 | ||
294 | 29 | 30 | ||
295 | 30 | h = NullHandler() | 31 | h = NullHandler() |
297 | 31 | logging.getLogger(__name__).addHandler(h) | 32 | logging.getLogger(DEFAULT_LOGGER_NAME).addHandler(h) |
298 | 32 | 33 | ||
299 | === modified file 'linaro_image_tools/hwpack/hwpack_convert.py' | |||
300 | --- linaro_image_tools/hwpack/hwpack_convert.py 2012-07-20 08:19:11 +0000 | |||
301 | +++ linaro_image_tools/hwpack/hwpack_convert.py 2012-10-04 14:31:36 +0000 | |||
302 | @@ -80,7 +80,7 @@ | |||
303 | 80 | SPL_KEYS = [SPL_IN_BOOT_PART_FIELD, SPL_DD_FIELD, SPL_PACKAGE_FIELD, | 80 | SPL_KEYS = [SPL_IN_BOOT_PART_FIELD, SPL_DD_FIELD, SPL_PACKAGE_FIELD, |
304 | 81 | SPL_FILE_FIELD, ENV_DD_FIELD] | 81 | SPL_FILE_FIELD, ENV_DD_FIELD] |
305 | 82 | 82 | ||
307 | 83 | logger = logging.getLogger("linaro_hwpack_converter") | 83 | logger = logging.getLogger(__name__) |
308 | 84 | 84 | ||
309 | 85 | 85 | ||
310 | 86 | class HwpackConverterException(Exception): | 86 | class HwpackConverterException(Exception): |
311 | 87 | 87 | ||
312 | === modified file 'linaro_image_tools/media_create/__init__.py' | |||
313 | --- linaro_image_tools/media_create/__init__.py 2012-10-01 13:44:05 +0000 | |||
314 | +++ linaro_image_tools/media_create/__init__.py 2012-10-04 14:31:36 +0000 | |||
315 | @@ -173,6 +173,7 @@ | |||
316 | 173 | help="Select a bootloader from a hardware pack that contains more " | 173 | help="Select a bootloader from a hardware pack that contains more " |
317 | 174 | "than one. If not specified, it will default to '%s'." % | 174 | "than one. If not specified, it will default to '%s'." % |
318 | 175 | DEFAULT_BOOTLOADER) | 175 | DEFAULT_BOOTLOADER) |
319 | 176 | parser.add_argument("--debug", action="store_true") | ||
320 | 176 | 177 | ||
321 | 177 | add_common_options(parser) | 178 | add_common_options(parser) |
322 | 178 | return parser | 179 | return parser |
323 | 179 | 180 | ||
324 | === modified file 'linaro_image_tools/media_create/boards.py' | |||
325 | --- linaro_image_tools/media_create/boards.py 2012-10-02 15:25:27 +0000 | |||
326 | +++ linaro_image_tools/media_create/boards.py 2012-10-04 14:31:36 +0000 | |||
327 | @@ -47,6 +47,8 @@ | |||
328 | 47 | partition_mounted, SECTOR_SIZE, register_loopback) | 47 | partition_mounted, SECTOR_SIZE, register_loopback) |
329 | 48 | from StringIO import StringIO | 48 | from StringIO import StringIO |
330 | 49 | 49 | ||
331 | 50 | logger = logging.getLogger(__name__) | ||
332 | 51 | |||
333 | 50 | KERNEL_GLOB = 'vmlinuz-*-%(kernel_flavor)s' | 52 | KERNEL_GLOB = 'vmlinuz-*-%(kernel_flavor)s' |
334 | 51 | INITRD_GLOB = 'initrd.img-*-%(kernel_flavor)s' | 53 | INITRD_GLOB = 'initrd.img-*-%(kernel_flavor)s' |
335 | 52 | DTB_GLOB = 'dt-*-%(kernel_flavor)s/%(dtb_name)s' | 54 | DTB_GLOB = 'dt-*-%(kernel_flavor)s/%(dtb_name)s' |
336 | @@ -455,14 +457,6 @@ | |||
337 | 455 | 457 | ||
338 | 456 | hardwarepack_handler = None | 458 | hardwarepack_handler = None |
339 | 457 | 459 | ||
340 | 458 | @staticmethod | ||
341 | 459 | def _get_logger(): | ||
342 | 460 | """ | ||
343 | 461 | Gets the logger instance. | ||
344 | 462 | :return: The logger instance | ||
345 | 463 | """ | ||
346 | 464 | return logging.getLogger('linaro_image_tools') | ||
347 | 465 | |||
348 | 466 | @classmethod | 460 | @classmethod |
349 | 467 | def get_metadata_field(cls, field_name): | 461 | def get_metadata_field(cls, field_name): |
350 | 468 | """ Return the metadata value for field_name if it can be found. | 462 | """ Return the metadata value for field_name if it can be found. |
351 | @@ -873,7 +867,6 @@ | |||
352 | 873 | :param dest_dir: The directory where to copy each dtb file. | 867 | :param dest_dir: The directory where to copy each dtb file. |
353 | 874 | :param search_dir: The directory where to search for the real file. | 868 | :param search_dir: The directory where to search for the real file. |
354 | 875 | """ | 869 | """ |
355 | 876 | logger = logging.getLogger("linaro_image_tools") | ||
356 | 877 | logger.info("Copying dtb files") | 870 | logger.info("Copying dtb files") |
357 | 878 | for dtb_file in dtb_files: | 871 | for dtb_file in dtb_files: |
358 | 879 | if dtb_file: | 872 | if dtb_file: |
359 | @@ -918,7 +911,6 @@ | |||
360 | 918 | if max_size is not None: | 911 | if max_size is not None: |
361 | 919 | assert os.path.getsize(from_file) <= max_size, ( | 912 | assert os.path.getsize(from_file) <= max_size, ( |
362 | 920 | "'%s' is larger than %s" % (from_file, max_size)) | 913 | "'%s' is larger than %s" % (from_file, max_size)) |
363 | 921 | logger = logging.getLogger("linaro_image_tools") | ||
364 | 922 | logger.info("Writing '%s' to '%s' at %s." % (from_file, to_file, seek)) | 914 | logger.info("Writing '%s' to '%s' at %s." % (from_file, to_file, seek)) |
365 | 923 | _dd(from_file, to_file, seek=seek) | 915 | _dd(from_file, to_file, seek=seek) |
366 | 924 | 916 | ||
367 | @@ -941,7 +933,6 @@ | |||
368 | 941 | if cls.spl_in_boot_part: | 933 | if cls.spl_in_boot_part: |
369 | 942 | assert spl_file is not None, ( | 934 | assert spl_file is not None, ( |
370 | 943 | "SPL binary could not be found") | 935 | "SPL binary could not be found") |
371 | 944 | logger = logging.getLogger("linaro_image_tools") | ||
372 | 945 | logger.info( | 936 | logger.info( |
373 | 946 | "Copying spl '%s' to boot partition." % spl_file) | 937 | "Copying spl '%s' to boot partition." % spl_file) |
374 | 947 | cmd_runner.run(["cp", "-v", spl_file, boot_dir], | 938 | cmd_runner.run(["cp", "-v", spl_file, boot_dir], |
375 | @@ -1101,7 +1092,6 @@ | |||
376 | 1101 | @classmethod | 1092 | @classmethod |
377 | 1102 | def _get_kflavor_files_v2(cls, path): | 1093 | def _get_kflavor_files_v2(cls, path): |
378 | 1103 | kernel = initrd = dtb = None | 1094 | kernel = initrd = dtb = None |
379 | 1104 | logger = logging.getLogger("linaro_image_tools") | ||
380 | 1105 | 1095 | ||
381 | 1106 | if cls.vmlinuz: | 1096 | if cls.vmlinuz: |
382 | 1107 | kernel = _get_file_matching(os.path.join(path, cls.vmlinuz)) | 1097 | kernel = _get_file_matching(os.path.join(path, cls.vmlinuz)) |
383 | 1108 | 1098 | ||
384 | === modified file 'linaro_image_tools/media_create/partitions.py' | |||
385 | --- linaro_image_tools/media_create/partitions.py 2012-06-13 13:42:08 +0000 | |||
386 | +++ linaro_image_tools/media_create/partitions.py 2012-10-04 14:31:36 +0000 | |||
387 | @@ -36,6 +36,8 @@ | |||
388 | 36 | 36 | ||
389 | 37 | from linaro_image_tools import cmd_runner | 37 | from linaro_image_tools import cmd_runner |
390 | 38 | 38 | ||
391 | 39 | logger = logging.getLogger(__name__) | ||
392 | 40 | |||
393 | 39 | HEADS = 128 | 41 | HEADS = 128 |
394 | 40 | SECTORS = 32 | 42 | SECTORS = 32 |
395 | 41 | SECTOR_SIZE = 512 # bytes | 43 | SECTOR_SIZE = 512 # bytes |
396 | @@ -205,7 +207,6 @@ | |||
397 | 205 | try: | 207 | try: |
398 | 206 | umount(path) | 208 | umount(path) |
399 | 207 | except cmd_runner.SubcommandNonZeroReturnValue, e: | 209 | except cmd_runner.SubcommandNonZeroReturnValue, e: |
400 | 208 | logger = logging.getLogger("linaro_image_tools") | ||
401 | 209 | logger.warn("Failed to umount %s, but ignoring it because of a " | 210 | logger.warn("Failed to umount %s, but ignoring it because of a " |
402 | 210 | "previous error" % path) | 211 | "previous error" % path) |
403 | 211 | logger.warn(e) | 212 | logger.warn(e) |
404 | @@ -586,7 +587,6 @@ | |||
405 | 586 | 587 | ||
406 | 587 | :param media: A setup_partitions.Media object to partition. | 588 | :param media: A setup_partitions.Media object to partition. |
407 | 588 | """ | 589 | """ |
408 | 589 | logger = logging.getLogger("linaro_image_tools") | ||
409 | 590 | tts = 1 | 590 | tts = 1 |
410 | 591 | while (tts > 0) and (tts <= MAX_TTS): | 591 | while (tts > 0) and (tts <= MAX_TTS): |
411 | 592 | try: | 592 | try: |
412 | 593 | 593 | ||
413 | === modified file 'linaro_image_tools/utils.py' | |||
414 | --- linaro_image_tools/utils.py 2012-07-26 19:49:43 +0000 | |||
415 | +++ linaro_image_tools/utils.py 2012-10-04 14:31:36 +0000 | |||
416 | @@ -28,6 +28,8 @@ | |||
417 | 28 | 28 | ||
418 | 29 | from linaro_image_tools import cmd_runner | 29 | from linaro_image_tools import cmd_runner |
419 | 30 | 30 | ||
420 | 31 | DEFAULT_LOGGER_NAME = 'linaro_image_tools' | ||
421 | 32 | |||
422 | 31 | 33 | ||
423 | 32 | # try_import was copied from python-testtools 0.9.12 and was originally | 34 | # try_import was copied from python-testtools 0.9.12 and was originally |
424 | 33 | # licensed under a MIT-style license but relicensed under the GPL in Linaro | 35 | # licensed under a MIT-style license but relicensed under the GPL in Linaro |
425 | @@ -76,13 +78,15 @@ | |||
426 | 76 | 78 | ||
427 | 77 | 79 | ||
428 | 78 | def path_in_tarfile_exists(path, tar_file): | 80 | def path_in_tarfile_exists(path, tar_file): |
430 | 79 | tarinfo = tarfile.open(tar_file, 'r:gz') | 81 | exists = True |
431 | 80 | try: | 82 | try: |
432 | 83 | tarinfo = tarfile.open(tar_file, 'r:gz') | ||
433 | 81 | tarinfo.getmember(path) | 84 | tarinfo.getmember(path) |
435 | 82 | return True | 85 | tarinfo.close() |
436 | 83 | except KeyError: | 86 | except KeyError: |
439 | 84 | return False | 87 | exists = False |
440 | 85 | tarinfo.close() | 88 | finally: |
441 | 89 | return exists | ||
442 | 86 | 90 | ||
443 | 87 | 91 | ||
444 | 88 | def verify_file_integrity(sig_file_list): | 92 | def verify_file_integrity(sig_file_list): |
445 | @@ -145,24 +149,24 @@ | |||
446 | 145 | 149 | ||
447 | 146 | # Check the outputs from verify_file_integrity | 150 | # Check the outputs from verify_file_integrity |
448 | 147 | # Abort if anything fails. | 151 | # Abort if anything fails. |
449 | 152 | logger = logging.getLogger(__name__) | ||
450 | 148 | if len(sig_file_list): | 153 | if len(sig_file_list): |
451 | 149 | if not gpg_sig_pass: | 154 | if not gpg_sig_pass: |
453 | 150 | logging.error("GPG signature verification failed.") | 155 | logger.error("GPG signature verification failed.") |
454 | 151 | return False, [] | 156 | return False, [] |
455 | 152 | 157 | ||
456 | 153 | if not os.path.basename(binary) in verified_files: | 158 | if not os.path.basename(binary) in verified_files: |
458 | 154 | logging.error("OS Binary verification failed") | 159 | logger.error("OS Binary verification failed") |
459 | 155 | return False, [] | 160 | return False, [] |
460 | 156 | 161 | ||
461 | 157 | for hwpack in hwpacks: | 162 | for hwpack in hwpacks: |
462 | 158 | if not os.path.basename(hwpack) in verified_files: | 163 | if not os.path.basename(hwpack) in verified_files: |
464 | 159 | logging.error("Hwpack {0} verification failed".format(hwpack)) | 164 | logger.error("Hwpack {0} verification failed".format(hwpack)) |
465 | 160 | return False, [] | 165 | return False, [] |
466 | 161 | 166 | ||
467 | 162 | for verified_file in verified_files: | 167 | for verified_file in verified_files: |
469 | 163 | logging.info('Hash verification of file {0} OK.'.format( | 168 | logger.info('Hash verification of file {0} OK.'.format( |
470 | 164 | verified_file)) | 169 | verified_file)) |
471 | 165 | |||
472 | 166 | return True, verified_files | 170 | return True, verified_files |
473 | 167 | 171 | ||
474 | 168 | 172 | ||
475 | @@ -348,3 +352,31 @@ | |||
476 | 348 | raise MissingRequiredOption("--dev option is required") | 352 | raise MissingRequiredOption("--dev option is required") |
477 | 349 | if args.binary is None: | 353 | if args.binary is None: |
478 | 350 | raise MissingRequiredOption("--binary option is required") | 354 | raise MissingRequiredOption("--binary option is required") |
479 | 355 | |||
480 | 356 | |||
481 | 357 | def get_logger(name=DEFAULT_LOGGER_NAME, debug=False): | ||
482 | 358 | """ | ||
483 | 359 | Retrieves a named logger. Default name is set in the variable | ||
484 | 360 | DEFAULT_LOG_NAME. Debug is set to False by default. | ||
485 | 361 | |||
486 | 362 | :param name: The name of the logger. | ||
487 | 363 | :param debug: If debug level should be turned on | ||
488 | 364 | :return: A logger instance. | ||
489 | 365 | """ | ||
490 | 366 | logger = logging.getLogger(name) | ||
491 | 367 | ch = logging.StreamHandler() | ||
492 | 368 | |||
493 | 369 | if debug: | ||
494 | 370 | ch.setLevel(logging.DEBUG) | ||
495 | 371 | formatter = logging.Formatter( | ||
496 | 372 | "%(asctime)s - %(name)s - %(levelname)s - %(message)s") | ||
497 | 373 | ch.setFormatter(formatter) | ||
498 | 374 | logger.setLevel(logging.DEBUG) | ||
499 | 375 | else: | ||
500 | 376 | ch.setLevel(logging.INFO) | ||
501 | 377 | formatter = logging.Formatter("%(message)s") | ||
502 | 378 | ch.setFormatter(formatter) | ||
503 | 379 | logger.setLevel(logging.INFO) | ||
504 | 380 | |||
505 | 381 | logger.addHandler(ch) | ||
506 | 382 | return logger |
I'm old for refactoring [old mess], and I assume you weighed pros and cons of that "drawback" - I don't immediately see any issues with it. Code changes look good to me.