コード例 #1
0
 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))
コード例 #2
0
 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))
コード例 #3
0
def install_hwpacks(
        rootfs_dir, tmp_dir, tools_dir, hwpack_force_yes, verified_files,
        extract_kpkgs=False, *hwpack_files):
    """Install the given hwpacks onto the given rootfs."""

    install_command = 'linaro-hwpack-install'
    linaro_hwpack_install_path = find_command(
        install_command, prefer_dir=tools_dir)

    if not linaro_hwpack_install_path:
        raise ChrootException("The program linaro-hwpack-install could not "
                              "be found found: cannot proceed.")
    else:
        linaro_hwpack_install_path = os.path.abspath(
            linaro_hwpack_install_path)

    # In case we just want to extract the kernel packages, don't force qemu
    # with chroot, as we could have archs without qemu support
    if not extract_kpkgs:
        prepare_chroot(rootfs_dir, tmp_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(rootfs_dir, 'usr', 'bin'))

        mount_chroot_proc(rootfs_dir)
        try:
            # Sometimes the host will have qemu-user-static installed but
            # another package (i.e. scratchbox) will have mangled its config
            # and thus we won't be able to chroot and install the hwpack, so
            # we fail here and tell the user to ensure qemu-arm-static is
            # setup before trying again.
            cmd_runner.run(['true'], as_root=True, chroot=rootfs_dir).wait()
        except:
            print ("Cannot proceed with hwpack installation because "
                   "there doesn't seem to be a binfmt interpreter registered "
                   "to execute arm binaries in the chroot. Please check "
                   "that qemu-user-static is installed and properly "
                   "configured before trying again.")
            raise
    else:
        # We are not in the chroot, we do not copy the linaro-hwpack-install
        # file, but we might not have l-i-t installed, so we need the full path
        # of the linaro-hwpack-install program to run.
        install_command = linaro_hwpack_install_path

    try:
        for hwpack_file in hwpack_files:
            hwpack_verified = False
            if os.path.basename(hwpack_file) in verified_files:
                hwpack_verified = True
            install_hwpack(rootfs_dir, hwpack_file, extract_kpkgs,
                           hwpack_force_yes or hwpack_verified,
                           install_command)
    finally:
        run_local_atexit_funcs()
コード例 #4
0
 def test_existing_command(self):
     lmc = 'linaro-media-create'
     prefer_dir = preferred_tools_dir()
     if prefer_dir is None:
         expected, _ = cmd_runner.run(
             ['which', lmc, ],
             stdout=subprocess.PIPE).communicate()
         expected = expected.strip()
     else:
         expected = os.path.join(prefer_dir, lmc)
     self.assertEquals(expected, find_command(lmc))
コード例 #5
0
 def test_existing_command(self):
     lmc = 'linaro-media-create'
     prefer_dir = preferred_tools_dir()
     if prefer_dir is None:
         expected, _ = cmd_runner.run([
             'which',
             lmc,
         ],
                                      stdout=subprocess.PIPE).communicate()
         expected = expected.strip()
     else:
         expected = os.path.join(prefer_dir, lmc)
     self.assertEquals(expected, find_command(lmc))
コード例 #6
0
def install_hwpacks(
        rootfs_dir, tmp_dir, tools_dir, hwpack_force_yes, verified_files,
        extract_kpkgs=False, *hwpack_files):
    """Install the given hwpacks onto the given rootfs."""

    # In case we just want to extract the kernel packages, don't force qemu
    # with chroot, as we could have archs without qemu support

    if not extract_kpkgs:
        prepare_chroot(rootfs_dir, tmp_dir)

        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(rootfs_dir, 'usr', 'bin'))

        mount_chroot_proc(rootfs_dir)
        try:
            # Sometimes the host will have qemu-user-static installed but
            # another package (i.e. scratchbox) will have mangled its config
            # and thus we won't be able to chroot and install the hwpack, so
            # we fail here and tell the user to ensure qemu-arm-static is
            # setup before trying again.
            cmd_runner.run(['true'], as_root=True, chroot=rootfs_dir).wait()
        except:
            print ("Cannot proceed with hwpack installation because "
                   "there doesn't seem to be a binfmt interpreter registered "
                   "to execute armel binaries in the chroot. Please check "
                   "that qemu-user-static is installed and properly "
                   "configured before trying again.")
            raise

    try:
        for hwpack_file in hwpack_files:
            hwpack_verified = False
            if os.path.basename(hwpack_file) in verified_files:
                hwpack_verified = True
            install_hwpack(rootfs_dir, hwpack_file, extract_kpkgs,
                           hwpack_force_yes or hwpack_verified)
    finally:
        run_local_atexit_funcs()
コード例 #7
0
    def setUp(self):
        super(ScriptTests, self).setUp()

        # Work out root of checkout.
        # We do this here because when running in PyCharm
        # the assumption in find_command that os.path.isabs(__file__) is
        # only true when not running from a Bazaar checkout is broken.
        # Thankfully find_command allows us to work around this by specifying
        # prefer_dir.
        dir = os.path.dirname(__file__)
        while True:
            path = os.path.join(dir, "linaro-hwpack-create")
            if dir == "/" or dir == "":
                # Didn't find linaro-media-create. Continue as if we haven't
                # tried to work out prefer_dir.
                dir = None
                break
            if os.path.exists(path) and os.access(path, os.X_OK):
                break
            dir = os.path.split(dir)[0]

        self.script_path = find_command("linaro-hwpack-create", prefer_dir=dir)
        self.useFixture(ChdirToTempdirFixture())
コード例 #8
0
    def setUp(self):
        super(ScriptTests, self).setUp()

        # Work out root of checkout.
        # We do this here because when running in PyCharm
        # the assumption in find_command that os.path.isabs(__file__) is
        # only true when not running from a Bazaar checkout is broken.
        # Thankfully find_command allows us to work around this by specifying
        # prefer_dir.
        dir = os.path.dirname(__file__)
        while True:
            path = os.path.join(dir, "linaro-hwpack-create")
            if dir == "/" or dir == "":
                # Didn't find linaro-media-create. Continue as if we haven't
                # tried to work out prefer_dir.
                dir = None
                break
            if os.path.exists(path) and os.access(path, os.X_OK):
                break
            dir = os.path.split(dir)[0]

        self.script_path = find_command("linaro-hwpack-create", prefer_dir=dir)
        self.useFixture(ChdirToTempdirFixture())
コード例 #9
0
 def test_nonexisting_command(self):
     self.assertEquals(find_command('linaro-moo'), None)
コード例 #10
0
 def test_nonexisting_command(self):
     self.assertEquals(find_command('linaro-moo'), None)