Пример #1
0
def do_package_download(datadir, key):
    with requests_mock.Mocker() as repository_request_mock:
        repository_mock = RepositoryMock(datadir)
        repository_mock.update_checksums()
        if key:
            repository_mock.sign_release()
        repository_request_mock.add_matcher(repository_mock.repository_matcher)

        repository = 'deb http://www.example.com/foodist/ stable main contrib'
        repository_key = key
        package_name = 'foo'
        architectures = ['all', 'amd64']

        workdir = os.path.join(str(datadir), 'workdir')
        os.mkdir(workdir)
        expected_file = os.path.join(workdir, 'foo_1.0_amd64.deb')
        assert not os.path.isfile(expected_file)

        d = PackageDownloader(repository=repository,
                              repository_key=repository_key,
                              architectures=architectures)
        result = d.download(package_name=package_name, dest=workdir)

        assert os.path.isfile(expected_file)
        assert result == expected_file
Пример #2
0
    def run(self, config_file, introspection_method=None):
        self._setup_parser(config_file)

        if introspection_method:
            print(introspection_method())
            return self._result()

        if not self._needs_qemu():
            return None

        if os.path.isfile(self._result()):
            logging.info(("{0} is already there. "
                          "Delete it to re-fetch it.").format(self._result()))
            return self._result()

        qemu_package = self.config.get_qemu_package_name()
        print("Going to fetch qemu Debian package ({}).".format(qemu_package))

        workdir = self.config.get_workdir()

        with tempfile.TemporaryDirectory(dir=workdir) as tempdir:
            chown_to_user(tempdir)

            qemu_repository = self.config.get_qemu_repository()

            if qemu_repository:
                key_url = self.config.get_qemu_repository_key()
            else:
                qemu_repository = self.config.get_bootstrap_repository()
                key_url = self.config.get_bootstrap_repository_key()

            d = PackageDownloader(repository=qemu_repository,
                                  repository_key=key_url,
                                  architectures=[get_debian_architecture()])
            package_file = d.download(package_name=qemu_package, dest=tempdir)

            apt_inst.DebFile(package_file).data.extractall(tempdir)
            qemu_binary = os.path.join(tempdir, 'usr', 'bin',
                                       self._get_qemu_binary_name())
            chown_to_user(qemu_binary)
            shutil.move(qemu_binary, self._result())

        print_success("Fetched qemu binary {}.".format(self._result()))
        return self._result()