From patchwork Wed Feb 2 17:34:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Lo=C3=AFc_Minier?= X-Patchwork-Id: 60 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:39:37 -0000 Delivered-To: patches@linaro.org Received: by 10.147.124.5 with SMTP id b5cs22153yan; Wed, 2 Feb 2011 09:34:30 -0800 (PST) Received: by 10.216.166.2 with SMTP id f2mr2017093wel.24.1296668069582; Wed, 02 Feb 2011 09:34:29 -0800 (PST) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id k15si39454079wer.128.2011.02.02.09.34.28; Wed, 02 Feb 2011 09:34:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Pkgb6-0006ii-2k for ; Wed, 02 Feb 2011 17:34:28 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 10F9A2E80AC for ; Wed, 2 Feb 2011 17:34:28 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-maintainers/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 284 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-maintainers/linaro-image-tools/trunk] Rev 284: Merge lp:~lool/linaro-image-tools/testsuite-when-installed; allows running Message-Id: <20110202173428.6695.52038.launchpad@loganberry.canonical.com> Date: Wed, 02 Feb 2011 17:34:28 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="12274"; Instance="initZopeless config overlay" X-Launchpad-Hash: 7eec52b7a061721b6a03491a6c8bebaf4cdd098f Merge authors: Loïc Minier (lool) Related merge proposals: https://code.launchpad.net/~lool/linaro-image-tools/testsuite-when-installed/+merge/48193 proposed by: James Westby (james-w) review: Approve - James Westby (james-w) ------------------------------------------------------------ revno: 284 [merge] committer: Loïc Minier branch nick: linaro-image-tools timestamp: Wed 2011-02-02 18:32:10 +0100 message: Merge lp:~lool/linaro-image-tools/testsuite-when-installed; allows running parts of the testsuite when installed system-wide. Had to resolve a conflict in linaro-media-create and patch an additional install_hwpacks() call site. modified: linaro-media-create linaro_media_create/hwpack.py linaro_media_create/tests/test_media_create.py linaro_media_create/utils.py --- lp:linaro-image-tools https://code.launchpad.net/~linaro-maintainers/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-maintainers/linaro-image-tools/trunk/+edit-subscription === modified file 'linaro-media-create' --- linaro-media-create 2011-02-02 12:08:05 +0000 +++ linaro-media-create 2011-02-02 17:32:10 +0000 @@ -121,7 +121,11 @@ unpack_binary_tarball(args.binary, TMP_DIR) hwpacks = args.hwpacks - install_hwpacks(ROOTFS_DIR, TMP_DIR, args.hwpack_force_yes, *hwpacks) + lmc_dir = os.path.dirname(__file__) + if lmc_dir == '': + lmc_dir = None + install_hwpacks( + ROOTFS_DIR, TMP_DIR, lmc_dir, args.hwpack_force_yes, *hwpacks) boot_partition, root_partition = setup_partitions( board_config, media, args.image_size, args.boot_label, args.rfs_label, === modified file 'linaro_media_create/hwpack.py' --- linaro_media_create/hwpack.py 2011-02-01 17:07:04 +0000 +++ linaro_media_create/hwpack.py 2011-02-02 17:32:10 +0000 @@ -21,7 +21,10 @@ import sys from linaro_media_create import cmd_runner -from linaro_media_create.utils import is_arm_host +from linaro_media_create.utils import ( + is_arm_host, + find_command, + ) # It'd be nice if we could use atexit here, but all the things we need to undo @@ -29,7 +32,8 @@ # functions would only be called after l-m-c.py exits. local_atexit = [] -def install_hwpacks(chroot_dir, tmp_dir, hwpack_force_yes, *hwpack_files): +def install_hwpacks( + chroot_dir, tmp_dir, tools_dir, hwpack_force_yes, *hwpack_files): """Install the given hwpacks onto the given chroot.""" chroot_etc = os.path.join(chroot_dir, 'etc') @@ -40,13 +44,11 @@ copy_file('/usr/bin/qemu-arm-static', os.path.join(chroot_dir, 'usr', 'bin')) - # FIXME: This is an ugly hack to make sure we use the l-h-i script from - # the current development tree when possible. - here = os.path.dirname(__file__) - linaro_hwpack_install_path = os.path.join( - here, '..', 'linaro-hwpack-install') - if not os.path.exists(linaro_hwpack_install_path): - linaro_hwpack_install_path = '/usr/bin/linaro-hwpack-install' + linaro_hwpack_install_path = find_command( + 'linaro-hwpack-install', prefer_dir=tools_dir) + # FIXME: shouldn't use chroot/usr/bin as this might conflict with installed + # packages; would be best to use some custom directory like + # chroot/linaro-image-tools/bin copy_file(linaro_hwpack_install_path, os.path.join(chroot_dir, 'usr', 'bin')) === modified file 'linaro_media_create/tests/test_media_create.py' --- linaro_media_create/tests/test_media_create.py 2011-02-01 17:29:25 +0000 +++ linaro_media_create/tests/test_media_create.py 2011-02-02 17:32:10 +0000 @@ -21,6 +21,7 @@ import glob import os import random +import stat import string import subprocess import sys @@ -82,6 +83,7 @@ from linaro_media_create.unpack_binary_tarball import unpack_binary_tarball from linaro_media_create.utils import ( ensure_command, + find_command, install_package_providing, UnableToFindPackageProvidingCommand, ) @@ -121,6 +123,32 @@ utils, 'install_package_providing', mock_func)) +class TestFindCommand(TestCaseWithFixtures): + + def test_preferred_dir(self): + tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir() + lmc = 'linaro-media-create' + path = os.path.join(tempdir, lmc) + open(path, 'w').close() + os.chmod(path, stat.S_IXUSR) + self.assertEquals(path, find_command(lmc, tempdir)) + + def test_existing_command(self): + lmc = 'linaro-media-create' + # running from bzr checkout? + if os.path.isabs(__file__): + expected, _ = cmd_runner.run( + ['which', lmc, ], + stdout=subprocess.PIPE).communicate() + expected = expected.strip() + else: + expected = os.path.join(os.getcwd(), lmc) + self.assertEquals(expected, find_command(lmc)) + + def test_nonexisting_command(self): + self.assertEquals(find_command('linaro-moo'), None) + + class TestInstallPackageProviding(TestCaseWithFixtures): def test_found_package(self): @@ -1083,8 +1111,17 @@ sys, 'stdout', open('/dev/null', 'w'))) fixture = self.useFixture(MockCmdRunnerPopenFixture()) force_yes = True + + prefer_dir = None + # running from bzr checkout? + if not os.path.isabs(__file__): + prefer_dir = os.getcwd() + install_hwpacks( - 'chroot', '/tmp/dir', force_yes, 'hwpack1.tgz', 'hwpack2.tgz') + 'chroot', '/tmp/dir', prefer_dir, force_yes, 'hwpack1.tgz', + 'hwpack2.tgz') + linaro_hwpack_install = find_command( + 'linaro-hwpack-install', prefer_dir=prefer_dir) self.assertEquals( [['sudo', 'mv', '-f', 'chroot/etc/resolv.conf', '/tmp/dir/resolv.conf'], @@ -1092,8 +1129,7 @@ ['sudo', 'mv', '-f', 'chroot/etc/hosts', '/tmp/dir/hosts'], ['sudo', 'cp', '/etc/hosts', 'chroot/etc'], ['sudo', 'cp', '/usr/bin/qemu-arm-static', 'chroot/usr/bin'], - ['sudo', 'cp', 'linaro_media_create/../linaro-hwpack-install', - 'chroot/usr/bin'], + ['sudo', 'cp', linaro_hwpack_install, 'chroot/usr/bin'], ['sudo', 'mount', 'proc', 'chroot/proc', '-t', 'proc'], ['sudo', 'cp', 'hwpack1.tgz', 'chroot'], ['sudo', 'chroot', 'chroot', 'linaro-hwpack-install', @@ -1152,11 +1188,17 @@ linaro_media_create.hwpack, 'run_local_atexit_funcs', mock_run_local_atexit_functions)) + prefer_dir = None + # running from bzr checkout? + if not os.path.isabs(__file__): + prefer_dir = os.getcwd() + force_yes = True exception_caught = False try: install_hwpacks( - 'chroot', '/tmp/dir', force_yes, 'hwp.tgz', 'hwp2.tgz') + 'chroot', '/tmp/dir', prefer_dir, force_yes, 'hwp.tgz', + 'hwp2.tgz') except: exception_caught = True self.assertTrue(self.run_local_atexit_functions_called) === modified file 'linaro_media_create/utils.py' --- linaro_media_create/utils.py 2011-01-28 19:50:48 +0000 +++ linaro_media_create/utils.py 2011-02-02 16:37:15 +0000 @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with Linaro Image Tools. If not, see . +import os import platform try: @@ -61,6 +62,37 @@ except cmd_runner.SubcommandNonZeroReturnValue: install_package_providing(command) +def find_command(name, prefer_dir=None): + """Finds a linaro-image-tools command. + + Prefers specified directory, otherwise searches only the current directory + when running from a checkout, or only PATH when running from an installed + version. + """ + assert name != "" + assert os.path.dirname(name) == "" + + if not os.environ.has_key("PATH"): + os.environ["PATH"] = ":/bin:usr/bin" + + # default to searching in current directory when running from a bzr + # checkout + dirs = [os.getcwd(),] + if os.path.isabs(__file__): + dirs = os.environ["PATH"].split(os.pathsep) + # empty dir in PATH means current directory + dirs = map(lambda x: x == '' and '.' or x, dirs) + + if prefer_dir is not None: + dirs.insert(0, prefer_dir) + + for dir in dirs: + path = os.path.join(dir, name) + if os.path.exists(path) and os.access(path, os.X_OK): + return path + + return None + def is_arm_host(): return platform.machine().startswith('arm')