From patchwork Sat Oct 20 06:18:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fathi Boudra X-Patchwork-Id: 12385 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id ED13223E29 for ; Sat, 20 Oct 2012 06:18:17 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 3BA4BA18E83 for ; Sat, 20 Oct 2012 06:18:17 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so1567287iej.11 for ; Fri, 19 Oct 2012 23:18:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :content-type:mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state; bh=3PpeGmgwI9yzSXEGhFyZYVQNh3CT22G/VG/XN+CVwco=; b=ONqv3IdeZcqjmpA3HyUIsAp6OfH3u6r6HNN/v/ntHF++B/iKmypfKpSAdMlE5UDfDU mujLap0BiwX8EOvPGkM2d4ljFdszAepAhPsC/bv7xW+HVvXAXTOOmf5reBijdZrEzlS/ 2mFUL+T4amkbPeiHV6K0Y8mhrIG59fceSxPxTqTXZSq/1t6kBy/+t+iUGt+iMBu8XGv1 m8MXP9PnV16cVmjt+2sfHfQClLhS10CmyPvCj9wBYc1GYYdx0CzbVtO6jr0cPuE0tWKf tubEUQsmy6ywyNWTEmDaba7wObxCCuVXx3WJqhJk+ng7gZ7MppMg9nQ+apKYQ1fhCRHH 6SPQ== Received: by 10.50.168.37 with SMTP id zt5mr3618807igb.57.1350713896497; Fri, 19 Oct 2012 23:18:16 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp212502igt; Fri, 19 Oct 2012 23:18:15 -0700 (PDT) Received: by 10.180.19.71 with SMTP id c7mr23583424wie.2.1350713894776; Fri, 19 Oct 2012 23:18:14 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id x5si3962185wex.150.2012.10.19.23.18.13 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 19 Oct 2012 23:18:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1TPSNx-0000p8-Ej for ; Sat, 20 Oct 2012 06:18:13 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 62759E00AC for ; Sat, 20 Oct 2012 06:18:13 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-image-tools/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 582 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 582: Revert the use of common logging infrastructure. Message-Id: <20121020061813.26550.23298.launchpad@ackee.canonical.com> Date: Sat, 20 Oct 2012 06:18:13 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="16165"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 2dbb71644a56adb06bf2c0702ff56e9755b161f2 X-Gm-Message-State: ALoCoQmCUlZzuWrr7YrTkrrTQzzB598nVJeYWq9xwXKJi5LEv+Jaw2Pdrnlt3quQh2UOKVLf2WP4 ------------------------------------------------------------ revno: 582 committer: Fathi Boudra branch nick: linaro-image-tools timestamp: Sat 2012-10-20 09:17:46 +0300 message: Revert the use of common logging infrastructure. modified: linaro-hwpack-convert linaro-hwpack-create linaro-hwpack-replace linaro-media-create linaro_image_tools/hwpack/__init__.py linaro_image_tools/hwpack/hwpack_convert.py linaro_image_tools/media_create/__init__.py linaro_image_tools/media_create/boards.py linaro_image_tools/media_create/partitions.py linaro_image_tools/utils.py --- lp:linaro-image-tools https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk You are subscribed to branch lp:linaro-image-tools. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription === modified file 'linaro-hwpack-convert' --- linaro-hwpack-convert 2012-10-04 14:19:47 +0000 +++ linaro-hwpack-convert 2012-10-20 06:17:46 +0000 @@ -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 @@ 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) === modified file 'linaro-hwpack-create' --- linaro-hwpack-create 2012-10-04 14:20:32 +0000 +++ linaro-hwpack-create 2012-10-20 06:17:46 +0000 @@ -21,14 +21,14 @@ # 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__ - if __name__ == '__main__': parser = argparse.ArgumentParser(version='%(prog)s ' + __version__) parser.add_argument( @@ -44,14 +44,24 @@ "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() === modified file 'linaro-hwpack-replace' --- linaro-hwpack-replace 2012-10-19 12:37:48 +0000 +++ linaro-hwpack-replace 2012-10-20 06:17:46 +0000 @@ -26,6 +26,7 @@ import sys import shutil import glob +import logging import tarfile import tempfile import argparse @@ -34,7 +35,6 @@ 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("-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 @@ 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 @@ "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 === modified file 'linaro-media-create' --- linaro-media-create 2012-10-04 14:21:31 +0000 +++ linaro-media-create 2012-10-20 06:17:46 +0000 @@ -22,6 +22,7 @@ import os import sys import tempfile +import logging from linaro_image_tools import cmd_runner @@ -56,7 +57,6 @@ MissingRequiredOption, path_in_tarfile_exists, prep_media_path, - get_logger, ) # Just define the global variables @@ -106,29 +106,35 @@ 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 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 @@ 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 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 @@ 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 === modified file 'linaro_image_tools/hwpack/__init__.py' --- linaro_image_tools/hwpack/__init__.py 2012-10-04 14:21:54 +0000 +++ linaro_image_tools/hwpack/__init__.py 2012-10-20 06:17:46 +0000 @@ -20,7 +20,6 @@ # USA. import logging -from linaro_image_tools.utils import DEFAULT_LOGGER_NAME class NullHandler(logging.Handler): @@ -29,4 +28,4 @@ h = NullHandler() -logging.getLogger(DEFAULT_LOGGER_NAME).addHandler(h) +logging.getLogger(__name__).addHandler(h) === modified file 'linaro_image_tools/hwpack/hwpack_convert.py' --- linaro_image_tools/hwpack/hwpack_convert.py 2012-10-19 12:37:48 +0000 +++ linaro_image_tools/hwpack/hwpack_convert.py 2012-10-20 06:17:46 +0000 @@ -85,7 +85,7 @@ # 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): === modified file 'linaro_image_tools/media_create/__init__.py' --- linaro_image_tools/media_create/__init__.py 2012-10-04 14:23:50 +0000 +++ linaro_image_tools/media_create/__init__.py 2012-10-20 06:17:46 +0000 @@ -173,7 +173,6 @@ 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 === modified file 'linaro_image_tools/media_create/boards.py' --- linaro_image_tools/media_create/boards.py 2012-10-19 12:37:48 +0000 +++ linaro_image_tools/media_create/boards.py 2012-10-20 06:17:46 +0000 @@ -47,8 +47,6 @@ 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 @@ 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 @@ :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 @@ 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 @@ 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 @@ @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)) === modified file 'linaro_image_tools/media_create/partitions.py' --- linaro_image_tools/media_create/partitions.py 2012-10-04 14:25:28 +0000 +++ linaro_image_tools/media_create/partitions.py 2012-10-20 06:17:46 +0000 @@ -36,8 +36,6 @@ from linaro_image_tools import cmd_runner -logger = logging.getLogger(__name__) - HEADS = 128 SECTORS = 32 SECTOR_SIZE = 512 # bytes @@ -207,6 +205,7 @@ 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 @@ :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: === modified file 'linaro_image_tools/utils.py' --- linaro_image_tools/utils.py 2012-10-04 14:19:05 +0000 +++ linaro_image_tools/utils.py 2012-10-20 06:17:46 +0000 @@ -28,8 +28,6 @@ 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 @@ 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 @@ # 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 @@ 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