From patchwork Wed Apr 18 14:27:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: James Tunnicliffe X-Patchwork-Id: 7934 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 EF66E23E1D for ; Wed, 18 Apr 2012 14:27:14 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id A2209A1830C for ; Wed, 18 Apr 2012 14:27:14 +0000 (UTC) Received: by yenl4 with SMTP id l4so4568983yen.11 for ; Wed, 18 Apr 2012 07:27:14 -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=SjmrcLWDf5L6klpOG8XU/q/yRGamrAnMQ7g+1G+XF38=; b=PPfz7pu0Cd/1nfMacaE0ybqGVmySBU8sMdVhWwDzgbToHbmYgen7VnIgprEVIJouok PQ1SJU0z4jMmzYownuOikKTOoz5v4HKB4nfnZcgZrURwDD27VFJ33fnN78++EzrbyRnY VlN6xp8jdigzjnJM+QP0HozOiJfOB+FfhzIXnnIgF/rp9n8oPf5VYPMvQIdcvK0eMzE0 0SdQBLAu6BE6oYMSZrcBBMUBPG/0Stc8D1nL/HmjIHtG5UqNhBuNz7mycAe0XcU40uzj TFgPk4OX1O8Mm4B75h5kN5h1r98kLDhSnHFHZHFi89YOFUmwUFYrmDSnaj7/OhDg9F5C GL6g== Received: by 10.50.135.36 with SMTP id pp4mr2220573igb.19.1334759232904; Wed, 18 Apr 2012 07:27:12 -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.231.137.198 with SMTP id x6csp220285ibt; Wed, 18 Apr 2012 07:27:11 -0700 (PDT) Received: by 10.216.135.66 with SMTP id t44mr1617578wei.8.1334759231434; Wed, 18 Apr 2012 07:27:11 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id do7si16417202wib.38.2012.04.18.07.27.11 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 18 Apr 2012 07:27:11 -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 1SKVqg-0000AY-SS for ; Wed, 18 Apr 2012 14:27:10 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id C8DB6E0292 for ; Wed, 18 Apr 2012 14:27:10 +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: 508 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 508: Add support for --output-directory parameter Message-Id: <20120418142710.28192.26388.launchpad@ackee.canonical.com> Date: Wed, 18 Apr 2012 14:27:10 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="15108"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 984e9878674a0985e14283609b16559a4376cbdf X-Gm-Message-State: ALoCoQkSoku4adSGXH0/7Df2SvxNj5tNh1wK5RbCIz2xhc2LcD77wCp4FTaxAUgdsxHDbF5MxfJW Merge authors: James Tunnicliffe (dooferlad) Related merge proposals: https://code.launchpad.net/~dooferlad/linaro-image-tools/add-directory-option/+merge/102518 proposed by: James Tunnicliffe (dooferlad) review: Approve - Loïc Minier (lool) ------------------------------------------------------------ revno: 508 [merge] committer: James Tunnicliffe branch nick: trunk timestamp: Wed 2012-04-18 15:25:33 +0100 message: Add support for --output-directory parameter modified: linaro-media-create linaro_image_tools/media_create/__init__.py linaro_image_tools/media_create/boards.py linaro_image_tools/tests/test_utils.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-media-create' --- linaro-media-create 2012-01-17 14:50:47 +0000 +++ linaro-media-create 2012-04-18 13:26:25 +0000 @@ -48,6 +48,9 @@ is_arm_host, check_file_integrity_and_log_errors, path_in_tarfile_exists, + IncompatibleOptions, + prep_media_path, + additional_option_checks, ) # Just define the global variables @@ -97,6 +100,37 @@ parser = get_args_parser() args = parser.parse_args() + try: + additional_option_checks(args) + except IncompatibleOptions as e: + parser.print_help() + print >> sys.stderr, "\nError:", e.value + sys.exit(1) + + board_config = board_configs[args.board] + board_config.set_metadata(args.hwpacks) + board_config.set_board(args.board) + board_config.add_boot_args(args.extra_boot_args) + board_config.add_boot_args_from_file(args.extra_boot_args_file) + + media = Media(prep_media_path(args)) + + if media.is_block_device: + if not board_config.supports_writing_to_mmc: + print "The board '%s' does not support the --mmc option. Please use "\ + "--image_file to create an image file for this board." % args.board + 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: + print ("Do not use --no-boot or --no-part in conjunction with " + "--image_file.") + sys.exit(1) + else: + # All good, move on. + pass + ch = logging.StreamHandler() ch.setLevel(logging.INFO) formatter = logging.Formatter("%(message)s") @@ -116,12 +150,6 @@ BOOT_DISK = os.path.join(TMP_DIR, 'boot-disc') ROOT_DISK = os.path.join(TMP_DIR, 'root-disc') - board_config = board_configs[args.board] - board_config.set_metadata(args.hwpacks) - board_config.set_board(args.board) - board_config.add_boot_args(args.extra_boot_args) - board_config.add_boot_args_from_file(args.extra_boot_args_file) - ensure_required_commands(args) sig_file_list = args.hwpacksigs[:] @@ -134,24 +162,8 @@ sig_file_list, args.binary, args.hwpacks) if not files_ok: sys.exit(1) - + atexit.register(cleanup_tempdir) - media = Media(args.device) - if media.is_block_device: - if not board_config.supports_writing_to_mmc: - print "The board '%s' does not support the --mmc option. Please use " \ - "--image_file to create an image file for this board." % args.board - 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: - print ("Do not use --no-boot or --no-part in conjunction with " - "--image_file.") - sys.exit(1) - else: - # All good, move on. - pass unpack_binary_tarball(args.binary, TMP_DIR) @@ -174,7 +186,7 @@ if args.should_format_bootfs: board_config.populate_boot( - ROOTFS_DIR, rootfs_uuid, boot_partition, BOOT_DISK, args.device, + ROOTFS_DIR, rootfs_uuid, boot_partition, BOOT_DISK, media.path, args.is_live, args.is_lowmem, args.consoles) if args.should_format_rootfs: @@ -185,4 +197,4 @@ rootfs_uuid, create_swap, str(args.swap_file), board_config.mmc_part_offset, board_config) - print "Done creating Linaro image on %s" % args.device + print "Done creating Linaro image on %s" % media.path === modified file 'linaro_image_tools/media_create/__init__.py' --- linaro_image_tools/media_create/__init__.py 2012-01-19 06:31:50 +0000 +++ linaro_image_tools/media_create/__init__.py 2012-04-18 13:08:36 +0000 @@ -77,12 +77,17 @@ def get_args_parser(): """Get the ArgumentParser for the arguments given on the command line.""" parser = argparse.ArgumentParser(version='%(prog)s ' + get_version()) - group = parser.add_mutually_exclusive_group(required=True) - group.add_argument( - '--mmc', dest='device', help='The storage device to use.') - group.add_argument( - '--image-file', '--image_file', dest='device', - help='File where we should write the QEMU image.') + group = parser.add_mutually_exclusive_group() + group.add_argument( + '--mmc', dest='device', default="sd.img", + help='The storage device to use.') + group.add_argument( + '--image-file', '--image_file', dest='device', default="sd.img", + help='File where we should write an image file (defaults to sd.img ' + 'if neither --image-file or --mmc are specified.)') + parser.add_argument( + '--output-directory', dest='directory', + help='Directory where image and accessories should be written to.') parser.add_argument( '--dev', required=True, dest='board', choices=KNOWN_BOARDS, help='Generate an SD card or image for the given board.') === modified file 'linaro_image_tools/media_create/boards.py' --- linaro_image_tools/media_create/boards.py 2012-04-17 16:22:09 +0000 +++ linaro_image_tools/media_create/boards.py 2012-04-18 14:25:33 +0000 @@ -1337,6 +1337,33 @@ pass +class FastModelConfig(BoardConfig): + supports_writing_to_mmc = False + + @classmethod + def _get_bootcmd(cls, d_img_data): + """Get the bootcmd for FastModel. + + We override this as we don't do uboot. + """ + return "" + + @classmethod + def _make_boot_files_v2(cls, boot_env, chroot_dir, boot_dir, + boot_device_or_file, k_img_data, i_img_data, + d_img_data): + logger = logging.getLogger("linaro_image_tools") + logger.info("WTF=%s." % boot_device_or_file ) + output_dir=os.path.dirname(boot_device_or_file) + cmd = [ "cp", "-v", _get_file_matching("%s/boot/img.axf" % chroot_dir), output_dir ] + proc = cmd_runner.run(cmd, as_root=True) + proc.wait() + cmd = [ "cp", "-v", k_img_data, i_img_data, d_img_data, output_dir ] + proc = cmd_runner.run(cmd, as_root=True) + proc.wait() + return + + class SamsungConfig(BoardConfig): @classproperty def extra_serial_opts(cls): @@ -1542,6 +1569,7 @@ 'panda': PandaConfig, 'vexpress': VexpressConfig, 'vexpress-a9': VexpressA9Config, + 'fastmodel': FastModelConfig, 'ux500': Ux500Config, 'snowball_sd': SnowballSdConfig, 'snowball_emmc': SnowballEmmcConfig, === modified file 'linaro_image_tools/tests/test_utils.py' --- linaro_image_tools/tests/test_utils.py 2011-10-12 09:54:29 +0000 +++ linaro_image_tools/tests/test_utils.py 2012-04-18 13:26:25 +0000 @@ -41,9 +41,11 @@ verify_file_integrity, check_file_integrity_and_log_errors, path_in_tarfile_exists, + IncompatibleOptions, + prep_media_path, + additional_option_checks, ) - sudo_args = " ".join(cmd_runner.SUDO_ARGS) @@ -260,3 +262,44 @@ UnableToFindPackageProvidingCommand, install_package_providing, 'mkfs.lean') + +class Args(): + def __init__(self, directory, device, board): + self.directory = directory + self.device = device + self.board = board + + +class TestPrepMediaPath(TestCaseWithFixtures): + + def test_prep_media_path(self): + self.useFixture(MockSomethingFixture(os.path, 'abspath', lambda x: x)) + self.useFixture(MockSomethingFixture(os, "makedirs", lambda x: x)) + + self.assertEqual("testdevice", + prep_media_path(Args(directory=None, + device="testdevice", + board="testboard"))) + + self.assertEqual("/foo/bar/testdevice", + prep_media_path(Args(directory="/foo/bar", + device="testdevice", + board="testboard"))) + +class TestPrepMediaPath(TestCaseWithFixtures): + + def test_additional_option_checks(self): + self.useFixture(MockSomethingFixture(os.path, 'abspath', lambda x: x)) + self.useFixture(MockSomethingFixture(os, "makedirs", lambda x: x)) + + self.assertRaises(IncompatibleOptions, additional_option_checks, + Args(directory="/foo/bar", + device="/testdevice", + board="testboard")) + + sys.argv.append("--mmc") + self.assertRaises(IncompatibleOptions, additional_option_checks, + Args(directory="/foo/bar", + device="testdevice", + board="testboard")) + sys.argv.remove("--mmc") === modified file 'linaro_image_tools/utils.py' --- linaro_image_tools/utils.py 2011-11-28 12:49:14 +0000 +++ linaro_image_tools/utils.py 2012-04-18 13:26:25 +0000 @@ -247,5 +247,41 @@ return prefer_dir +def prep_media_path(args): + if args.directory is not None: + loc = os.path.abspath(args.directory) + try: + os.makedirs(loc) + except OSError: + pass # Directory exists. + + path = os.path.join(loc, args.device) + else: + path = args.device + + return path + + class UnableToFindPackageProvidingCommand(Exception): """We can't find a package which provides the given command.""" + + +class IncompatibleOptions(Exception): + def __init__(self, value): + self.value = value + + def __str__(self): + return repr(self.value) + +def additional_option_checks(args): + if args.directory is not None: + # If args.device is a path to a device (/dev/) then this is an error + if "--mmc" in sys.argv: + raise IncompatibleOptions("--directory option incompatable with " + "option --mmc") + + # If directory is used as well as having a full path (rather than just + # a file name or relative path) in args.device, this is an error. + if re.search(r"^/", args.device): + raise IncompatibleOptions("--directory option incompatable with " + "a full path in --image-file")