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

Proposed by Milo Casagrande
Status: Merged
Merged at revision: 585
Proposed branch: lp:~milo/linaro-image-tools/bug1059579
Merge into: lp:linaro-image-tools/11.11
Diff against target: 507 lines (+82/-104)
10 files modified
linaro-hwpack-convert (+4/-22)
linaro-hwpack-create (+8/-18)
linaro-hwpack-replace (+4/-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
Данило Шеган (community) Approve
Fathi Boudra Pending
Review via email: mp+130736@code.launchpad.net

Description of the change

Re-using the same branch: we reapply the logger refactoring, and fix the regression found - it was missing the global declaration when initializing the variable.

To post a comment you must log in.
Revision history for this message
Данило Шеган (danilo) wrote :

Based on the fact that this was already reviewed, I'll just review the simple change in 586.

Is there any simple way you can add a test that exercises this code path? If not, land as-is, though I'd very much prefer a test.

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

On Wed, Oct 24, 2012 at 1:46 PM, Данило Шеган <email address hidden> wrote:
> Review: Approve
>
> Based on the fact that this was already reviewed, I'll just review the simple change in 586.
>
> Is there any simple way you can add a test that exercises this code path? If not, land as-is, though I'd very much prefer a test.

I looked into that, but it is not that easy. It should be possible to
use the already mocking infrastructure to fake hwpack and deb files in
this case, but the problem is that all this code is inside a user
script (it is linaro-hwpack-replace), and we cannot really import
anything from it to test it out and use it as a module. It would
really call to refactor all the code of that script (something that
would be cool to do).

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

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-10-20 06:17:46 +0000
+++ linaro-hwpack-convert 2012-10-22 07:04:22 +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 2012-10-20 06:17:46 +0000
+++ linaro-hwpack-create 2012-10-22 07:04:22 +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 2012-10-20 06:17:46 +0000
+++ linaro-hwpack-replace 2012-10-22 07:04:22 +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,8 @@
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 global logger
168 logger = get_logger(debug=args.debug)
182169
183 old_hwpack = args.hwpack_name170 old_hwpack = args.hwpack_name
184 new_deb_file_to_copy = args.deb_pack171 new_deb_file_to_copy = args.deb_pack
185172
=== modified file 'linaro-media-create'
--- linaro-media-create 2012-10-20 06:17:46 +0000
+++ linaro-media-create 2012-10-22 07:04:22 +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-10-20 06:17:46 +0000
+++ linaro_image_tools/hwpack/__init__.py 2012-10-22 07:04:22 +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-10-20 06:17:46 +0000
+++ linaro_image_tools/hwpack/hwpack_convert.py 2012-10-22 07:04:22 +0000
@@ -85,7 +85,7 @@
85# The default name used for renaming dtb file85# The default name used for renaming dtb file
86DEFAULT_DTB_NAME = 'board.dtb'86DEFAULT_DTB_NAME = 'board.dtb'
8787
88logger = logging.getLogger("linaro_hwpack_converter")88logger = logging.getLogger(__name__)
8989
9090
91class HwpackConverterException(Exception):91class HwpackConverterException(Exception):
9292
=== modified file 'linaro_image_tools/media_create/__init__.py'
--- linaro_image_tools/media_create/__init__.py 2012-10-20 06:17:46 +0000
+++ linaro_image_tools/media_create/__init__.py 2012-10-22 07:04:22 +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-20 06:17:46 +0000
+++ linaro_image_tools/media_create/boards.py 2012-10-22 07:04:22 +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'
@@ -457,14 +459,6 @@
457459
458 hardwarepack_handler = None460 hardwarepack_handler = None
459461
460 @staticmethod
461 def _get_logger():
462 """
463 Gets the logger instance.
464 :return: The logger instance
465 """
466 return logging.getLogger('linaro_image_tools')
467
468 @classmethod462 @classmethod
469 def get_metadata_field(cls, field_name):463 def get_metadata_field(cls, field_name):
470 """ Return the metadata value for field_name if it can be found.464 """ Return the metadata value for field_name if it can be found.
@@ -877,7 +871,6 @@
877 :param dest_dir: The directory where to copy each dtb file.871 :param dest_dir: The directory where to copy each dtb file.
878 :param search_dir: The directory where to search for the real file.872 :param search_dir: The directory where to search for the real file.
879 """873 """
880 logger = logging.getLogger("linaro_image_tools")
881 logger.info("Copying dtb files")874 logger.info("Copying dtb files")
882 for dtb_file in dtb_files:875 for dtb_file in dtb_files:
883 if dtb_file:876 if dtb_file:
@@ -922,7 +915,6 @@
922 if max_size is not None:915 if max_size is not None:
923 assert os.path.getsize(from_file) <= max_size, (916 assert os.path.getsize(from_file) <= max_size, (
924 "'%s' is larger than %s" % (from_file, max_size))917 "'%s' is larger than %s" % (from_file, max_size))
925 logger = logging.getLogger("linaro_image_tools")
926 logger.info("Writing '%s' to '%s' at %s." % (from_file, to_file, seek))918 logger.info("Writing '%s' to '%s' at %s." % (from_file, to_file, seek))
927 _dd(from_file, to_file, seek=seek)919 _dd(from_file, to_file, seek=seek)
928920
@@ -945,7 +937,6 @@
945 if cls.spl_in_boot_part:937 if cls.spl_in_boot_part:
946 assert spl_file is not None, (938 assert spl_file is not None, (
947 "SPL binary could not be found")939 "SPL binary could not be found")
948 logger = logging.getLogger("linaro_image_tools")
949 logger.info(940 logger.info(
950 "Copying spl '%s' to boot partition." % spl_file)941 "Copying spl '%s' to boot partition." % spl_file)
951 cmd_runner.run(["cp", "-v", spl_file, boot_dir],942 cmd_runner.run(["cp", "-v", spl_file, boot_dir],
@@ -1105,7 +1096,6 @@
1105 @classmethod1096 @classmethod
1106 def _get_kflavor_files_v2(cls, path):1097 def _get_kflavor_files_v2(cls, path):
1107 kernel = initrd = dtb = None1098 kernel = initrd = dtb = None
1108 logger = logging.getLogger("linaro_image_tools")
11091099
1110 if cls.vmlinuz:1100 if cls.vmlinuz:
1111 kernel = _get_file_matching(os.path.join(path, cls.vmlinuz))1101 kernel = _get_file_matching(os.path.join(path, cls.vmlinuz))
11121102
=== modified file 'linaro_image_tools/media_create/partitions.py'
--- linaro_image_tools/media_create/partitions.py 2012-10-20 06:17:46 +0000
+++ linaro_image_tools/media_create/partitions.py 2012-10-22 07:04:22 +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-10-20 06:17:46 +0000
+++ linaro_image_tools/utils.py 2012-10-22 07:04:22 +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