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

Proposed by Milo Casagrande
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
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

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.

To post a comment you must log in.
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.

Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

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.

review: Approve
581. By Milo Casagrande

Use common logging infrastructure, add --debug option to linaro-media-create.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'linaro-hwpack-convert'
--- linaro-hwpack-convert 2012-07-23 07:07:55 +0000
+++ linaro-hwpack-convert 2012-10-04 14:31:36 +0000
@@ -22,35 +22,17 @@
2222
2323
24import argparse24import argparse
25import logging
26import sys25import sys
27import os
2826
29from linaro_image_tools.hwpack.hwpack_convert import (27from linaro_image_tools.hwpack.hwpack_convert import (
30 HwpackConverter,28 HwpackConverter,
31 HwpackConverterException,29 HwpackConverterException,
32 check_and_validate_args,30 check_and_validate_args,
33 )31 )
32from linaro_image_tools.utils import get_logger
34from linaro_image_tools.__version__ import __version__33from linaro_image_tools.__version__ import __version__
3534
3635
37def get_logger(debug=False):
38 ch = logging.StreamHandler()
39 logger = logging.getLogger("linaro_hwpack_converter")
40
41 if debug:
42 ch.setLevel(logging.DEBUG)
43 formatter = logging.Formatter(
44 "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
45 ch.setFormatter(formatter)
46 logger.setLevel(logging.DEBUG)
47 else:
48 ch.setLevel(logging.INFO)
49 formatter = logging.Formatter("%(message)s")
50 ch.setFormatter(formatter)
51 logger.setLevel(logging.INFO)
52 logger.addHandler(ch)
53
54if __name__ == '__main__':36if __name__ == '__main__':
55 parser = argparse.ArgumentParser(version='%(prog)s ' + __version__)37 parser = argparse.ArgumentParser(version='%(prog)s ' + __version__)
56 parser.add_argument("CONFIG_FILE",38 parser.add_argument("CONFIG_FILE",
@@ -64,10 +46,10 @@
64 logger = get_logger(debug=args.debug)46 logger = get_logger(debug=args.debug)
65 try:47 try:
66 input_file, output_file = check_and_validate_args(args)48 input_file, output_file = check_and_validate_args(args)
67 print "Converting '%s' into new YAML format..." % (input_file)49 logger.info("Converting '%s' into new YAML format..." % input_file)
68 converter = HwpackConverter(input_file, output_file)50 converter = HwpackConverter(input_file, output_file)
69 except HwpackConverterException, e:51 except HwpackConverterException, e:
70 sys.stderr.write(str(e) + "\n")52 logger.error(str(e))
71 sys.exit(1)53 sys.exit(1)
72 converter.convert()54 converter.convert()
73 print "File '%s' converted in '%s'." % (input_file, output_file)55 logger.info("File '%s' converted in '%s'." % (input_file, output_file))
7456
=== modified file 'linaro-hwpack-create'
--- linaro-hwpack-create 2011-10-03 08:18:45 +0000
+++ linaro-hwpack-create 2012-10-04 14:31:36 +0000
@@ -21,14 +21,14 @@
21# USA.21# USA.
2222
23import argparse23import argparse
24import logging
25import sys24import sys
2625
27from linaro_image_tools.hwpack.builder import (26from linaro_image_tools.hwpack.builder import (
28 ConfigFileMissing, HardwarePackBuilder)27 ConfigFileMissing, HardwarePackBuilder)
2928from linaro_image_tools.utils import get_logger
30from linaro_image_tools.__version__ import __version__29from linaro_image_tools.__version__ import __version__
3130
31
32if __name__ == '__main__':32if __name__ == '__main__':
33 parser = argparse.ArgumentParser(version='%(prog)s ' + __version__)33 parser = argparse.ArgumentParser(version='%(prog)s ' + __version__)
34 parser.add_argument(34 parser.add_argument(
@@ -44,24 +44,14 @@
44 "version than a package that would be otherwise installed. "44 "version than a package that would be otherwise installed. "
45 "Can be used more than once."))45 "Can be used more than once."))
46 parser.add_argument("--debug", action="store_true")46 parser.add_argument("--debug", action="store_true")
47
47 args = parser.parse_args()48 args = parser.parse_args()
48 ch = logging.StreamHandler()49 logger = get_logger(debug=args.debug)
49 ch.setLevel(logging.INFO)50
50 formatter = logging.Formatter("%(message)s")
51 ch.setFormatter(formatter)
52 logger = logging.getLogger("linaro_image_tools")
53 logger.setLevel(logging.INFO)
54 logger.addHandler(ch)
55 if args.debug:
56 ch.setLevel(logging.DEBUG)
57 formatter = logging.Formatter(
58 "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
59 ch.setFormatter(formatter)
60 logger.setLevel(logging.DEBUG)
61 try:51 try:
62 builder = HardwarePackBuilder(52 builder = HardwarePackBuilder(args.CONFIG_FILE,
63 args.CONFIG_FILE, args.VERSION, args.local_debs)53 args.VERSION, args.local_debs)
64 except ConfigFileMissing, e:54 except ConfigFileMissing, e:
65 sys.stderr.write(str(e) + "\n")55 logger.error(str(e))
66 sys.exit(1)56 sys.exit(1)
67 builder.build()57 builder.build()
6858
=== modified file 'linaro-hwpack-replace'
--- linaro-hwpack-replace 2011-10-13 12:11:28 +0000
+++ linaro-hwpack-replace 2012-10-04 14:31:36 +0000
@@ -26,7 +26,6 @@
26import sys26import sys
27import shutil27import shutil
28import glob28import glob
29import logging
30import tarfile29import tarfile
31import tempfile30import tempfile
32import argparse31import argparse
@@ -35,6 +34,7 @@
35from debian.deb822 import Packages34from debian.deb822 import Packages
36from linaro_image_tools.hwpack.packages import get_packages_file35from linaro_image_tools.hwpack.packages import get_packages_file
37from linaro_image_tools.hwpack.packages import FetchedPackage36from linaro_image_tools.hwpack.packages import FetchedPackage
37from linaro_image_tools.utils import get_logger
3838
3939
40parser = argparse.ArgumentParser()40parser = argparse.ArgumentParser()
@@ -53,7 +53,7 @@
53parser.add_argument("-d", "--debug-output", action="store_true", dest="debug",53parser.add_argument("-d", "--debug-output", action="store_true", dest="debug",
54 help="Verbose messages are displayed when specified")54 help="Verbose messages are displayed when specified")
5555
56logger = logging.getLogger("linaro-hwpack-replace")56logger = None
5757
5858
59class DummyStanza(object):59class DummyStanza(object):
@@ -65,20 +65,6 @@
65 fd.write(get_packages_file([self.info]))65 fd.write(get_packages_file([self.info]))
6666
6767
68def set_logging_param(args):
69 ch = logging.StreamHandler()
70 ch.setLevel(logging.INFO)
71 formatter = logging.Formatter("%(message)s")
72 ch.setFormatter(formatter)
73 logger.setLevel(logging.INFO)
74 logger.addHandler(ch)
75 if args.debug:
76 ch.setLevel(logging.DEBUG)
77 formatter = logging.Formatter(
78 "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
79 ch.setFormatter(formatter)
80 logger.setLevel(logging.DEBUG)
81
8268
83def get_hwpack_name(old_hwpack, build_number):69def get_hwpack_name(old_hwpack, build_number):
84 # The build_number would be the job build number.70 # The build_number would be the job build number.
@@ -178,7 +164,7 @@
178 "and the debian package information\n")164 "and the debian package information\n")
179 return 1165 return 1
180166
181 set_logging_param(args)167 logger = get_logger(debug=args.debug)
182168
183 old_hwpack = args.hwpack_name169 old_hwpack = args.hwpack_name
184 new_deb_file_to_copy = args.deb_pack170 new_deb_file_to_copy = args.deb_pack
185171
=== modified file 'linaro-media-create'
--- linaro-media-create 2012-10-01 12:50:55 +0000
+++ linaro-media-create 2012-10-04 14:31:36 +0000
@@ -22,7 +22,6 @@
22import os22import os
23import sys23import sys
24import tempfile24import tempfile
25import logging
2625
27from linaro_image_tools import cmd_runner26from linaro_image_tools import cmd_runner
2827
@@ -57,6 +56,7 @@
57 MissingRequiredOption,56 MissingRequiredOption,
58 path_in_tarfile_exists,57 path_in_tarfile_exists,
59 prep_media_path,58 prep_media_path,
59 get_logger,
60 )60 )
6161
62# Just define the global variables62# Just define the global variables
@@ -106,35 +106,29 @@
106 parser = get_args_parser()106 parser = get_args_parser()
107 args = parser.parse_args()107 args = parser.parse_args()
108108
109 ch = logging.StreamHandler()109 logger = get_logger(debug=args.debug)
110 ch.setLevel(logging.INFO)
111 formatter = logging.Formatter("%(message)s")
112 ch.setFormatter(formatter)
113 logger = logging.getLogger("linaro_image_tools")
114 logger.setLevel(logging.INFO)
115 logger.addHandler(ch)
116110
117 try:111 try:
118 additional_option_checks(args)112 additional_option_checks(args)
119 except IncompatibleOptions as e:113 except IncompatibleOptions as e:
120 parser.print_help()114 parser.print_help()
121 print >> sys.stderr, "\nError:", e.value115 logger.error(e.value)
122 sys.exit(1)116 sys.exit(1)
123117
124 if args.readhwpack:118 if args.readhwpack:
125 try:119 try:
126 reader = HwpackReader(args.hwpacks)120 reader = HwpackReader(args.hwpacks)
127 print reader.get_supported_boards()121 logger.info(reader.get_supported_boards())
128 sys.exit(0)122 sys.exit(0)
129 except HwpackReaderError as e:123 except HwpackReaderError as e:
130 print >> sys.stderr, "\nError:", e.value124 logger.error(e.value)
131 sys.exit(1)125 sys.exit(1)
132126
133 try:127 try:
134 check_required_args(args)128 check_required_args(args)
135 except MissingRequiredOption as e:129 except MissingRequiredOption as e:
136 parser.print_help()130 parser.print_help()
137 print >> sys.stderr, "\nError:", e.value131 logger.error(e.value)
138 sys.exit(1)132 sys.exit(1)
139133
140 board_config = board_configs[args.dev]134 board_config = board_configs[args.dev]
@@ -147,16 +141,16 @@
147141
148 if media.is_block_device:142 if media.is_block_device:
149 if not board_config.supports_writing_to_mmc:143 if not board_config.supports_writing_to_mmc:
150 print ("The board '%s' does not support the --mmc option. "144 logger.error("The board '%s' does not support the --mmc option. "
151 "Please use --image_file to create an image file for this "145 "Please use --image_file to create an image file for "
152 "board." % args.dev)146 "this board." % args.dev)
153 sys.exit(1)147 sys.exit(1)
154 if not confirm_device_selection_and_ensure_it_is_ready(148 if not confirm_device_selection_and_ensure_it_is_ready(
155 args.device, args.nocheck_mmc):149 args.device, args.nocheck_mmc):
156 sys.exit(1)150 sys.exit(1)
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:
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 "
159 "--image_file.")153 "--image_file.")
160 sys.exit(1)154 sys.exit(1)
161 else:155 else:
162 # All good, move on.156 # All good, move on.
@@ -170,6 +164,7 @@
170 BIN_DIR = os.path.join(TMP_DIR, 'rootfs')164 BIN_DIR = os.path.join(TMP_DIR, 'rootfs')
171 os.mkdir(BIN_DIR)165 os.mkdir(BIN_DIR)
172166
167 logger.info('Searching correct rootfs path')
173 # Identify the correct path for the rootfs168 # Identify the correct path for the rootfs
174 filesystem_dir = ''169 filesystem_dir = ''
175 if path_in_tarfile_exists('binary/etc', args.binary):170 if path_in_tarfile_exists('binary/etc', args.binary):
@@ -212,12 +207,12 @@
212207
213 if args.rootfs == 'btrfs':208 if args.rootfs == 'btrfs':
214 if not extract_kpkgs:209 if not extract_kpkgs:
215 print ("Desired rootfs type is 'btrfs', trying to auto-install "210 logger.info("Desired rootfs type is 'btrfs', trying to "
216 "the 'btrfs-tools' package")211 "auto-install the 'btrfs-tools' package")
217 install_packages(ROOTFS_DIR, TMP_DIR, "btrfs-tools")212 install_packages(ROOTFS_DIR, TMP_DIR, "btrfs-tools")
218 else:213 else:
219 print ("Desired rootfs type is 'btrfs', please make sure the "214 logger.info("Desired rootfs type is 'btrfs', please make sure the "
220 "rootfs also includes 'btrfs-tools'")215 "rootfs also includes 'btrfs-tools'")
221216
222 boot_partition, root_partition = setup_partitions(217 boot_partition, root_partition = setup_partitions(
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,
@@ -248,4 +243,4 @@
248 board_config.mmc_device_id, board_config.mmc_part_offset,243 board_config.mmc_device_id, board_config.mmc_part_offset,
249 board_config)244 board_config)
250245
251 print "Done creating Linaro image on %s" % media.path246 logger.info("Done creating Linaro image on %s" % media.path)
252247
=== modified file 'linaro_image_tools/hwpack/__init__.py'
--- linaro_image_tools/hwpack/__init__.py 2012-06-13 14:26:02 +0000
+++ linaro_image_tools/hwpack/__init__.py 2012-10-04 14:31:36 +0000
@@ -20,6 +20,7 @@
20# USA.20# USA.
2121
22import logging22import logging
23from linaro_image_tools.utils import DEFAULT_LOGGER_NAME
2324
2425
25class NullHandler(logging.Handler):26class NullHandler(logging.Handler):
@@ -28,4 +29,4 @@
2829
2930
30h = NullHandler()31h = NullHandler()
31logging.getLogger(__name__).addHandler(h)32logging.getLogger(DEFAULT_LOGGER_NAME).addHandler(h)
3233
=== modified file 'linaro_image_tools/hwpack/hwpack_convert.py'
--- linaro_image_tools/hwpack/hwpack_convert.py 2012-07-20 08:19:11 +0000
+++ linaro_image_tools/hwpack/hwpack_convert.py 2012-10-04 14:31:36 +0000
@@ -80,7 +80,7 @@
80SPL_KEYS = [SPL_IN_BOOT_PART_FIELD, SPL_DD_FIELD, SPL_PACKAGE_FIELD,80SPL_KEYS = [SPL_IN_BOOT_PART_FIELD, SPL_DD_FIELD, SPL_PACKAGE_FIELD,
81 SPL_FILE_FIELD, ENV_DD_FIELD]81 SPL_FILE_FIELD, ENV_DD_FIELD]
8282
83logger = logging.getLogger("linaro_hwpack_converter")83logger = logging.getLogger(__name__)
8484
8585
86class HwpackConverterException(Exception):86class HwpackConverterException(Exception):
8787
=== modified file 'linaro_image_tools/media_create/__init__.py'
--- linaro_image_tools/media_create/__init__.py 2012-10-01 13:44:05 +0000
+++ linaro_image_tools/media_create/__init__.py 2012-10-04 14:31:36 +0000
@@ -173,6 +173,7 @@
173 help="Select a bootloader from a hardware pack that contains more "173 help="Select a bootloader from a hardware pack that contains more "
174 "than one. If not specified, it will default to '%s'." %174 "than one. If not specified, it will default to '%s'." %
175 DEFAULT_BOOTLOADER)175 DEFAULT_BOOTLOADER)
176 parser.add_argument("--debug", action="store_true")
176177
177 add_common_options(parser)178 add_common_options(parser)
178 return parser179 return parser
179180
=== modified file 'linaro_image_tools/media_create/boards.py'
--- linaro_image_tools/media_create/boards.py 2012-10-02 15:25:27 +0000
+++ linaro_image_tools/media_create/boards.py 2012-10-04 14:31:36 +0000
@@ -47,6 +47,8 @@
47 partition_mounted, SECTOR_SIZE, register_loopback)47 partition_mounted, SECTOR_SIZE, register_loopback)
48from StringIO import StringIO48from StringIO import StringIO
4949
50logger = logging.getLogger(__name__)
51
50KERNEL_GLOB = 'vmlinuz-*-%(kernel_flavor)s'52KERNEL_GLOB = 'vmlinuz-*-%(kernel_flavor)s'
51INITRD_GLOB = 'initrd.img-*-%(kernel_flavor)s'53INITRD_GLOB = 'initrd.img-*-%(kernel_flavor)s'
52DTB_GLOB = 'dt-*-%(kernel_flavor)s/%(dtb_name)s'54DTB_GLOB = 'dt-*-%(kernel_flavor)s/%(dtb_name)s'
@@ -455,14 +457,6 @@
455457
456 hardwarepack_handler = None458 hardwarepack_handler = None
457459
458 @staticmethod
459 def _get_logger():
460 """
461 Gets the logger instance.
462 :return: The logger instance
463 """
464 return logging.getLogger('linaro_image_tools')
465
466 @classmethod460 @classmethod
467 def get_metadata_field(cls, field_name):461 def get_metadata_field(cls, field_name):
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.
@@ -873,7 +867,6 @@
873 :param dest_dir: The directory where to copy each dtb file.867 :param dest_dir: The directory where to copy each dtb file.
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.
875 """869 """
876 logger = logging.getLogger("linaro_image_tools")
877 logger.info("Copying dtb files")870 logger.info("Copying dtb files")
878 for dtb_file in dtb_files:871 for dtb_file in dtb_files:
879 if dtb_file:872 if dtb_file:
@@ -918,7 +911,6 @@
918 if max_size is not None:911 if max_size is not None:
919 assert os.path.getsize(from_file) <= max_size, (912 assert os.path.getsize(from_file) <= max_size, (
920 "'%s' is larger than %s" % (from_file, max_size))913 "'%s' is larger than %s" % (from_file, max_size))
921 logger = logging.getLogger("linaro_image_tools")
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))
923 _dd(from_file, to_file, seek=seek)915 _dd(from_file, to_file, seek=seek)
924916
@@ -941,7 +933,6 @@
941 if cls.spl_in_boot_part:933 if cls.spl_in_boot_part:
942 assert spl_file is not None, (934 assert spl_file is not None, (
943 "SPL binary could not be found")935 "SPL binary could not be found")
944 logger = logging.getLogger("linaro_image_tools")
945 logger.info(936 logger.info(
946 "Copying spl '%s' to boot partition." % spl_file)937 "Copying spl '%s' to boot partition." % spl_file)
947 cmd_runner.run(["cp", "-v", spl_file, boot_dir],938 cmd_runner.run(["cp", "-v", spl_file, boot_dir],
@@ -1101,7 +1092,6 @@
1101 @classmethod1092 @classmethod
1102 def _get_kflavor_files_v2(cls, path):1093 def _get_kflavor_files_v2(cls, path):
1103 kernel = initrd = dtb = None1094 kernel = initrd = dtb = None
1104 logger = logging.getLogger("linaro_image_tools")
11051095
1106 if cls.vmlinuz:1096 if cls.vmlinuz:
1107 kernel = _get_file_matching(os.path.join(path, cls.vmlinuz))1097 kernel = _get_file_matching(os.path.join(path, cls.vmlinuz))
11081098
=== modified file 'linaro_image_tools/media_create/partitions.py'
--- linaro_image_tools/media_create/partitions.py 2012-06-13 13:42:08 +0000
+++ linaro_image_tools/media_create/partitions.py 2012-10-04 14:31:36 +0000
@@ -36,6 +36,8 @@
3636
37from linaro_image_tools import cmd_runner37from linaro_image_tools import cmd_runner
3838
39logger = logging.getLogger(__name__)
40
39HEADS = 12841HEADS = 128
40SECTORS = 3242SECTORS = 32
41SECTOR_SIZE = 512 # bytes43SECTOR_SIZE = 512 # bytes
@@ -205,7 +207,6 @@
205 try:207 try:
206 umount(path)208 umount(path)
207 except cmd_runner.SubcommandNonZeroReturnValue, e:209 except cmd_runner.SubcommandNonZeroReturnValue, e:
208 logger = logging.getLogger("linaro_image_tools")
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 "
210 "previous error" % path)211 "previous error" % path)
211 logger.warn(e)212 logger.warn(e)
@@ -586,7 +587,6 @@
586587
587 :param media: A setup_partitions.Media object to partition.588 :param media: A setup_partitions.Media object to partition.
588 """589 """
589 logger = logging.getLogger("linaro_image_tools")
590 tts = 1590 tts = 1
591 while (tts > 0) and (tts <= MAX_TTS):591 while (tts > 0) and (tts <= MAX_TTS):
592 try:592 try:
593593
=== modified file 'linaro_image_tools/utils.py'
--- linaro_image_tools/utils.py 2012-07-26 19:49:43 +0000
+++ linaro_image_tools/utils.py 2012-10-04 14:31:36 +0000
@@ -28,6 +28,8 @@
2828
29from linaro_image_tools import cmd_runner29from linaro_image_tools import cmd_runner
3030
31DEFAULT_LOGGER_NAME = 'linaro_image_tools'
32
3133
32# try_import was copied from python-testtools 0.9.12 and was originally34# try_import was copied from python-testtools 0.9.12 and was originally
33# licensed under a MIT-style license but relicensed under the GPL in Linaro35# licensed under a MIT-style license but relicensed under the GPL in Linaro
@@ -76,13 +78,15 @@
7678
7779
78def path_in_tarfile_exists(path, tar_file):80def path_in_tarfile_exists(path, tar_file):
79 tarinfo = tarfile.open(tar_file, 'r:gz')81 exists = True
80 try:82 try:
83 tarinfo = tarfile.open(tar_file, 'r:gz')
81 tarinfo.getmember(path)84 tarinfo.getmember(path)
82 return True85 tarinfo.close()
83 except KeyError:86 except KeyError:
84 return False87 exists = False
85 tarinfo.close()88 finally:
89 return exists
8690
8791
88def verify_file_integrity(sig_file_list):92def verify_file_integrity(sig_file_list):
@@ -145,24 +149,24 @@
145149
146 # Check the outputs from verify_file_integrity150 # Check the outputs from verify_file_integrity
147 # Abort if anything fails.151 # Abort if anything fails.
152 logger = logging.getLogger(__name__)
148 if len(sig_file_list):153 if len(sig_file_list):
149 if not gpg_sig_pass:154 if not gpg_sig_pass:
150 logging.error("GPG signature verification failed.")155 logger.error("GPG signature verification failed.")
151 return False, []156 return False, []
152157
153 if not os.path.basename(binary) in verified_files:158 if not os.path.basename(binary) in verified_files:
154 logging.error("OS Binary verification failed")159 logger.error("OS Binary verification failed")
155 return False, []160 return False, []
156161
157 for hwpack in hwpacks:162 for hwpack in hwpacks:
158 if not os.path.basename(hwpack) in verified_files:163 if not os.path.basename(hwpack) in verified_files:
159 logging.error("Hwpack {0} verification failed".format(hwpack))164 logger.error("Hwpack {0} verification failed".format(hwpack))
160 return False, []165 return False, []
161166
162 for verified_file in verified_files:167 for verified_file in verified_files:
163 logging.info('Hash verification of file {0} OK.'.format(168 logger.info('Hash verification of file {0} OK.'.format(
164 verified_file))169 verified_file))
165
166 return True, verified_files170 return True, verified_files
167171
168172
@@ -348,3 +352,31 @@
348 raise MissingRequiredOption("--dev option is required")352 raise MissingRequiredOption("--dev option is required")
349 if args.binary is None:353 if args.binary is None:
350 raise MissingRequiredOption("--binary option is required")354 raise MissingRequiredOption("--binary option is required")
355
356
357def get_logger(name=DEFAULT_LOGGER_NAME, debug=False):
358 """
359 Retrieves a named logger. Default name is set in the variable
360 DEFAULT_LOG_NAME. Debug is set to False by default.
361
362 :param name: The name of the logger.
363 :param debug: If debug level should be turned on
364 :return: A logger instance.
365 """
366 logger = logging.getLogger(name)
367 ch = logging.StreamHandler()
368
369 if debug:
370 ch.setLevel(logging.DEBUG)
371 formatter = logging.Formatter(
372 "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
373 ch.setFormatter(formatter)
374 logger.setLevel(logging.DEBUG)
375 else:
376 ch.setLevel(logging.INFO)
377 formatter = logging.Formatter("%(message)s")
378 ch.setFormatter(formatter)
379 logger.setLevel(logging.INFO)
380
381 logger.addHandler(ch)
382 return logger

Subscribers

People subscribed via source and target branches