diff options
author | Fathi Boudra <fathi.boudra@linaro.org> | 2012-10-20 09:17:46 +0300 |
---|---|---|
committer | Fathi Boudra <fathi.boudra@linaro.org> | 2012-10-20 09:17:46 +0300 |
commit | fa407e3065ae0e54232b9f719d9db86c3a67c040 (patch) | |
tree | 35d94ed32fcf2496a1f760556e616a80dd1b2f9a | |
parent | b21d6e2ac0a693009abca7ecff545572156f3fe1 (diff) |
Revert the use of common logging infrastructure.
-rwxr-xr-x | linaro-hwpack-convert | 26 | ||||
-rwxr-xr-x | linaro-hwpack-create | 26 | ||||
-rwxr-xr-x | linaro-hwpack-replace | 20 | ||||
-rwxr-xr-x | linaro-media-create | 39 | ||||
-rw-r--r-- | linaro_image_tools/hwpack/__init__.py | 3 | ||||
-rw-r--r-- | linaro_image_tools/hwpack/hwpack_convert.py | 2 | ||||
-rw-r--r-- | linaro_image_tools/media_create/__init__.py | 1 | ||||
-rw-r--r-- | linaro_image_tools/media_create/boards.py | 14 | ||||
-rw-r--r-- | linaro_image_tools/media_create/partitions.py | 4 | ||||
-rw-r--r-- | linaro_image_tools/utils.py | 50 |
10 files changed, 104 insertions, 81 deletions
diff --git a/linaro-hwpack-convert b/linaro-hwpack-convert index cf9b51f..d366a55 100755 --- a/linaro-hwpack-convert +++ b/linaro-hwpack-convert @@ -22,17 +22,35 @@ import argparse +import logging import sys +import os from linaro_image_tools.hwpack.hwpack_convert import ( HwpackConverter, HwpackConverterException, check_and_validate_args, ) -from linaro_image_tools.utils import get_logger from linaro_image_tools.__version__ import __version__ +def get_logger(debug=False): + ch = logging.StreamHandler() + logger = logging.getLogger("linaro_hwpack_converter") + + if debug: + ch.setLevel(logging.DEBUG) + formatter = logging.Formatter( + "%(asctime)s - %(name)s - %(levelname)s - %(message)s") + ch.setFormatter(formatter) + logger.setLevel(logging.DEBUG) + else: + ch.setLevel(logging.INFO) + formatter = logging.Formatter("%(message)s") + ch.setFormatter(formatter) + logger.setLevel(logging.INFO) + logger.addHandler(ch) + if __name__ == '__main__': parser = argparse.ArgumentParser(version='%(prog)s ' + __version__) parser.add_argument("CONFIG_FILE", @@ -46,10 +64,10 @@ if __name__ == '__main__': logger = get_logger(debug=args.debug) try: input_file, output_file = check_and_validate_args(args) - logger.info("Converting '%s' into new YAML format..." % input_file) + print "Converting '%s' into new YAML format..." % (input_file) converter = HwpackConverter(input_file, output_file) except HwpackConverterException, e: - logger.error(str(e)) + sys.stderr.write(str(e) + "\n") sys.exit(1) converter.convert() - logger.info("File '%s' converted in '%s'." % (input_file, output_file)) + print "File '%s' converted in '%s'." % (input_file, output_file) diff --git a/linaro-hwpack-create b/linaro-hwpack-create index 7a64429..ebb557d 100755 --- a/linaro-hwpack-create +++ b/linaro-hwpack-create @@ -21,13 +21,13 @@ # USA. import argparse +import logging import sys from linaro_image_tools.hwpack.builder import ( ConfigFileMissing, HardwarePackBuilder) -from linaro_image_tools.utils import get_logger -from linaro_image_tools.__version__ import __version__ +from linaro_image_tools.__version__ import __version__ if __name__ == '__main__': parser = argparse.ArgumentParser(version='%(prog)s ' + __version__) @@ -44,14 +44,24 @@ if __name__ == '__main__': "version than a package that would be otherwise installed. " "Can be used more than once.")) parser.add_argument("--debug", action="store_true") - args = parser.parse_args() - logger = get_logger(debug=args.debug) - + ch = logging.StreamHandler() + ch.setLevel(logging.INFO) + formatter = logging.Formatter("%(message)s") + ch.setFormatter(formatter) + logger = logging.getLogger("linaro_image_tools") + logger.setLevel(logging.INFO) + logger.addHandler(ch) + if args.debug: + ch.setLevel(logging.DEBUG) + formatter = logging.Formatter( + "%(asctime)s - %(name)s - %(levelname)s - %(message)s") + ch.setFormatter(formatter) + logger.setLevel(logging.DEBUG) try: - builder = HardwarePackBuilder(args.CONFIG_FILE, - args.VERSION, args.local_debs) + builder = HardwarePackBuilder( + args.CONFIG_FILE, args.VERSION, args.local_debs) except ConfigFileMissing, e: - logger.error(str(e)) + sys.stderr.write(str(e) + "\n") sys.exit(1) builder.build() diff --git a/linaro-hwpack-replace b/linaro-hwpack-replace index a8d9d78..e7f2336 100755 --- a/linaro-hwpack-replace +++ b/linaro-hwpack-replace @@ -26,6 +26,7 @@ import os import sys import shutil import glob +import logging import tarfile import tempfile import argparse @@ -34,7 +35,6 @@ import fileinput from debian.deb822 import Packages from linaro_image_tools.hwpack.packages import get_packages_file from linaro_image_tools.hwpack.packages import FetchedPackage -from linaro_image_tools.utils import get_logger parser = argparse.ArgumentParser() @@ -53,7 +53,7 @@ parser.add_argument("-i", "--in-place", action="store_true", dest="inplace", parser.add_argument("-d", "--debug-output", action="store_true", dest="debug", help="Verbose messages are displayed when specified") -logger = None +logger = logging.getLogger("linaro-hwpack-replace") class DummyStanza(object): @@ -65,6 +65,20 @@ class DummyStanza(object): fd.write(get_packages_file([self.info])) +def set_logging_param(args): + ch = logging.StreamHandler() + ch.setLevel(logging.INFO) + formatter = logging.Formatter("%(message)s") + ch.setFormatter(formatter) + logger.setLevel(logging.INFO) + logger.addHandler(ch) + if args.debug: + ch.setLevel(logging.DEBUG) + formatter = logging.Formatter( + "%(asctime)s - %(name)s - %(levelname)s - %(message)s") + ch.setFormatter(formatter) + logger.setLevel(logging.DEBUG) + def get_hwpack_name(old_hwpack, build_number): # The build_number would be the job build number. @@ -164,7 +178,7 @@ def main(): "and the debian package information\n") return 1 - logger = get_logger(debug=args.debug) + set_logging_param(args) old_hwpack = args.hwpack_name new_deb_file_to_copy = args.deb_pack diff --git a/linaro-media-create b/linaro-media-create index 81a83f8..62a7068 100755 --- a/linaro-media-create +++ b/linaro-media-create @@ -22,6 +22,7 @@ import atexit import os import sys import tempfile +import logging from linaro_image_tools import cmd_runner @@ -56,7 +57,6 @@ from linaro_image_tools.utils import ( MissingRequiredOption, path_in_tarfile_exists, prep_media_path, - get_logger, ) # Just define the global variables @@ -106,29 +106,35 @@ if __name__ == '__main__': parser = get_args_parser() args = parser.parse_args() - logger = get_logger(debug=args.debug) + ch = logging.StreamHandler() + ch.setLevel(logging.INFO) + formatter = logging.Formatter("%(message)s") + ch.setFormatter(formatter) + logger = logging.getLogger("linaro_image_tools") + logger.setLevel(logging.INFO) + logger.addHandler(ch) try: additional_option_checks(args) except IncompatibleOptions as e: parser.print_help() - logger.error(e.value) + print >> sys.stderr, "\nError:", e.value sys.exit(1) if args.readhwpack: try: reader = HwpackReader(args.hwpacks) - logger.info(reader.get_supported_boards()) + print reader.get_supported_boards() sys.exit(0) except HwpackReaderError as e: - logger.error(e.value) + print >> sys.stderr, "\nError:", e.value sys.exit(1) try: check_required_args(args) except MissingRequiredOption as e: parser.print_help() - logger.error(e.value) + print >> sys.stderr, "\nError:", e.value sys.exit(1) board_config = board_configs[args.dev] @@ -141,16 +147,16 @@ if __name__ == '__main__': if media.is_block_device: if not board_config.supports_writing_to_mmc: - logger.error("The board '%s' does not support the --mmc option. " - "Please use --image_file to create an image file for " - "this board." % args.dev) + print ("The board '%s' does not support the --mmc option. " + "Please use --image_file to create an image file for this " + "board." % args.dev) sys.exit(1) if not confirm_device_selection_and_ensure_it_is_ready( args.device, args.nocheck_mmc): sys.exit(1) elif not args.should_format_rootfs or not args.should_format_bootfs: - logger.error("Do not use --no-boot or --no-part in conjunction with " - "--image_file.") + print ("Do not use --no-boot or --no-part in conjunction with " + "--image_file.") sys.exit(1) else: # All good, move on. @@ -164,7 +170,6 @@ if __name__ == '__main__': BIN_DIR = os.path.join(TMP_DIR, 'rootfs') os.mkdir(BIN_DIR) - logger.info('Searching correct rootfs path') # Identify the correct path for the rootfs filesystem_dir = '' if path_in_tarfile_exists('binary/etc', args.binary): @@ -207,12 +212,12 @@ if __name__ == '__main__': if args.rootfs == 'btrfs': if not extract_kpkgs: - logger.info("Desired rootfs type is 'btrfs', trying to " - "auto-install the 'btrfs-tools' package") + print ("Desired rootfs type is 'btrfs', trying to auto-install " + "the 'btrfs-tools' package") install_packages(ROOTFS_DIR, TMP_DIR, "btrfs-tools") else: - logger.info("Desired rootfs type is 'btrfs', please make sure the " - "rootfs also includes 'btrfs-tools'") + print ("Desired rootfs type is 'btrfs', please make sure the " + "rootfs also includes 'btrfs-tools'") boot_partition, root_partition = setup_partitions( board_config, media, args.image_size, args.boot_label, args.rfs_label, @@ -243,4 +248,4 @@ if __name__ == '__main__': board_config.mmc_device_id, board_config.mmc_part_offset, board_config) - logger.info("Done creating Linaro image on %s" % media.path) + print "Done creating Linaro image on %s" % media.path diff --git a/linaro_image_tools/hwpack/__init__.py b/linaro_image_tools/hwpack/__init__.py index 97a4008..9c9cef6 100644 --- a/linaro_image_tools/hwpack/__init__.py +++ b/linaro_image_tools/hwpack/__init__.py @@ -20,7 +20,6 @@ # USA. import logging -from linaro_image_tools.utils import DEFAULT_LOGGER_NAME class NullHandler(logging.Handler): @@ -29,4 +28,4 @@ class NullHandler(logging.Handler): h = NullHandler() -logging.getLogger(DEFAULT_LOGGER_NAME).addHandler(h) +logging.getLogger(__name__).addHandler(h) diff --git a/linaro_image_tools/hwpack/hwpack_convert.py b/linaro_image_tools/hwpack/hwpack_convert.py index 3f35380..3b7237b 100644 --- a/linaro_image_tools/hwpack/hwpack_convert.py +++ b/linaro_image_tools/hwpack/hwpack_convert.py @@ -85,7 +85,7 @@ SPL_KEYS = [SPL_IN_BOOT_PART_FIELD, SPL_DD_FIELD, SPL_PACKAGE_FIELD, # The default name used for renaming dtb file DEFAULT_DTB_NAME = 'board.dtb' -logger = logging.getLogger(__name__) +logger = logging.getLogger("linaro_hwpack_converter") class HwpackConverterException(Exception): diff --git a/linaro_image_tools/media_create/__init__.py b/linaro_image_tools/media_create/__init__.py index aae6970..c67413c 100644 --- a/linaro_image_tools/media_create/__init__.py +++ b/linaro_image_tools/media_create/__init__.py @@ -173,7 +173,6 @@ def get_args_parser(): help="Select a bootloader from a hardware pack that contains more " "than one. If not specified, it will default to '%s'." % DEFAULT_BOOTLOADER) - parser.add_argument("--debug", action="store_true") add_common_options(parser) return parser diff --git a/linaro_image_tools/media_create/boards.py b/linaro_image_tools/media_create/boards.py index ff939e0..5e70357 100644 --- a/linaro_image_tools/media_create/boards.py +++ b/linaro_image_tools/media_create/boards.py @@ -47,8 +47,6 @@ from linaro_image_tools.media_create.partitions import ( partition_mounted, SECTOR_SIZE, register_loopback) from StringIO import StringIO -logger = logging.getLogger(__name__) - KERNEL_GLOB = 'vmlinuz-*-%(kernel_flavor)s' INITRD_GLOB = 'initrd.img-*-%(kernel_flavor)s' DTB_GLOB = 'dt-*-%(kernel_flavor)s/%(dtb_name)s' @@ -459,6 +457,14 @@ class BoardConfig(object): hardwarepack_handler = None + @staticmethod + def _get_logger(): + """ + Gets the logger instance. + :return: The logger instance + """ + return logging.getLogger('linaro_image_tools') + @classmethod def get_metadata_field(cls, field_name): """ Return the metadata value for field_name if it can be found. @@ -871,6 +877,7 @@ class BoardConfig(object): :param dest_dir: The directory where to copy each dtb file. :param search_dir: The directory where to search for the real file. """ + logger = logging.getLogger("linaro_image_tools") logger.info("Copying dtb files") for dtb_file in dtb_files: if dtb_file: @@ -915,6 +922,7 @@ class BoardConfig(object): if max_size is not None: assert os.path.getsize(from_file) <= max_size, ( "'%s' is larger than %s" % (from_file, max_size)) + logger = logging.getLogger("linaro_image_tools") logger.info("Writing '%s' to '%s' at %s." % (from_file, to_file, seek)) _dd(from_file, to_file, seek=seek) @@ -937,6 +945,7 @@ class BoardConfig(object): if cls.spl_in_boot_part: assert spl_file is not None, ( "SPL binary could not be found") + logger = logging.getLogger("linaro_image_tools") logger.info( "Copying spl '%s' to boot partition." % spl_file) cmd_runner.run(["cp", "-v", spl_file, boot_dir], @@ -1096,6 +1105,7 @@ class BoardConfig(object): @classmethod def _get_kflavor_files_v2(cls, path): kernel = initrd = dtb = None + logger = logging.getLogger("linaro_image_tools") if cls.vmlinuz: kernel = _get_file_matching(os.path.join(path, cls.vmlinuz)) diff --git a/linaro_image_tools/media_create/partitions.py b/linaro_image_tools/media_create/partitions.py index 8557ede..b364f77 100644 --- a/linaro_image_tools/media_create/partitions.py +++ b/linaro_image_tools/media_create/partitions.py @@ -36,8 +36,6 @@ from parted import ( from linaro_image_tools import cmd_runner -logger = logging.getLogger(__name__) - HEADS = 128 SECTORS = 32 SECTOR_SIZE = 512 # bytes @@ -207,6 +205,7 @@ def partition_mounted(device, path, *args): try: umount(path) except cmd_runner.SubcommandNonZeroReturnValue, e: + logger = logging.getLogger("linaro_image_tools") logger.warn("Failed to umount %s, but ignoring it because of a " "previous error" % path) logger.warn(e) @@ -587,6 +586,7 @@ def wait_partition_to_settle(media): :param media: A setup_partitions.Media object to partition. """ + logger = logging.getLogger("linaro_image_tools") tts = 1 while (tts > 0) and (tts <= MAX_TTS): try: diff --git a/linaro_image_tools/utils.py b/linaro_image_tools/utils.py index af43834..705ab1e 100644 --- a/linaro_image_tools/utils.py +++ b/linaro_image_tools/utils.py @@ -28,8 +28,6 @@ import sys from linaro_image_tools import cmd_runner -DEFAULT_LOGGER_NAME = 'linaro_image_tools' - # try_import was copied from python-testtools 0.9.12 and was originally # licensed under a MIT-style license but relicensed under the GPL in Linaro @@ -78,15 +76,13 @@ CommandNotFound = try_import('CommandNotFound.CommandNotFound') def path_in_tarfile_exists(path, tar_file): - exists = True + tarinfo = tarfile.open(tar_file, 'r:gz') try: - tarinfo = tarfile.open(tar_file, 'r:gz') tarinfo.getmember(path) - tarinfo.close() + return True except KeyError: - exists = False - finally: - return exists + return False + tarinfo.close() def verify_file_integrity(sig_file_list): @@ -149,24 +145,24 @@ def check_file_integrity_and_log_errors(sig_file_list, binary, hwpacks): # Check the outputs from verify_file_integrity # Abort if anything fails. - logger = logging.getLogger(__name__) if len(sig_file_list): if not gpg_sig_pass: - logger.error("GPG signature verification failed.") + logging.error("GPG signature verification failed.") return False, [] if not os.path.basename(binary) in verified_files: - logger.error("OS Binary verification failed") + logging.error("OS Binary verification failed") return False, [] for hwpack in hwpacks: if not os.path.basename(hwpack) in verified_files: - logger.error("Hwpack {0} verification failed".format(hwpack)) + logging.error("Hwpack {0} verification failed".format(hwpack)) return False, [] for verified_file in verified_files: - logger.info('Hash verification of file {0} OK.'.format( + logging.info('Hash verification of file {0} OK.'.format( verified_file)) + return True, verified_files @@ -352,31 +348,3 @@ def check_required_args(args): raise MissingRequiredOption("--dev option is required") if args.binary is None: raise MissingRequiredOption("--binary option is required") - - -def get_logger(name=DEFAULT_LOGGER_NAME, debug=False): - """ - Retrieves a named logger. Default name is set in the variable - DEFAULT_LOG_NAME. Debug is set to False by default. - - :param name: The name of the logger. - :param debug: If debug level should be turned on - :return: A logger instance. - """ - logger = logging.getLogger(name) - ch = logging.StreamHandler() - - if debug: - ch.setLevel(logging.DEBUG) - formatter = logging.Formatter( - "%(asctime)s - %(name)s - %(levelname)s - %(message)s") - ch.setFormatter(formatter) - logger.setLevel(logging.DEBUG) - else: - ch.setLevel(logging.INFO) - formatter = logging.Formatter("%(message)s") - ch.setFormatter(formatter) - logger.setLevel(logging.INFO) - - logger.addHandler(ch) - return logger |