Exemple #1
0
    def try_fetch_by_id(self, pkg_id: PackageId):
        if self._repository_url is None:
            return False

        # TODO(cmaloney): Use storage providers to download instead of open coding.
        pkg_path = "{}.tar.xz".format(pkg_id)
        url = self._repository_url + '/packages/{0}/{1}'.format(pkg_id.name, pkg_path)
        try:
            directory = self.get_package_cache_folder(pkg_id.name)
            # TODO(cmaloney): Move to some sort of logging mechanism?
            print("Attempting to download", pkg_id, "from", url, "to", directory)
            download_atomic(directory + '/' + pkg_path, url, directory)
            assert os.path.exists(directory + '/' + pkg_path)
            return directory + '/' + pkg_path
        except FetchError:
            return False
Exemple #2
0
    def try_fetch_by_id(self, pkg_id: PackageId):
        if self._repository_url is None:
            return False

        # TODO(cmaloney): Use storage providers to download instead of open coding.
        pkg_path = "{}.tar.xz".format(pkg_id)
        url = self._repository_url + '/packages/{0}/{1}'.format(pkg_id.name, pkg_path)
        try:
            directory = self.get_package_cache_folder(pkg_id.name)
            # TODO(cmaloney): Move to some sort of logging mechanism?
            print("Attempting to download", pkg_id, "from", url, "to", directory)
            download_atomic(directory + '/' + pkg_path, url, directory)
            assert os.path.exists(directory + '/' + pkg_path)
            return directory + '/' + pkg_path
        except FetchError:
            return False
Exemple #3
0
    def try_fetch_bootstrap_and_active(self, bootstrap_id):
        if self._repository_url is None:
            return False

        try:
            bootstrap_name = '{}.bootstrap.tar.xz'.format(bootstrap_id)
            active_name = '{}.active.json'.format(bootstrap_id)
            # TODO(cmaloney): Use storage providers to download instead of open coding.
            bootstrap_url = self._repository_url + '/bootstrap/' + bootstrap_name
            active_url = self._repository_url + '/bootstrap/' + active_name
            print("Attempting to download", bootstrap_name, "from", bootstrap_url)
            # Normalize to no trailing slash for repository_url
            download_atomic(self._packages_dir + '/' + bootstrap_name, bootstrap_url, self._packages_dir)
            print("Attempting to download", active_name, "from", active_url)
            download_atomic(self._packages_dir + '/' + active_name, active_url, self._packages_dir)
            return True
        except FetchError:
            return False
Exemple #4
0
    def try_fetch_bootstrap_and_active(self, bootstrap_id):
        if self._repository_url is None:
            return False

        try:
            bootstrap_name = '{}.bootstrap.tar.xz'.format(bootstrap_id)
            active_name = '{}.active.json'.format(bootstrap_id)
            # TODO(cmaloney): Use storage providers to download instead of open coding.
            bootstrap_url = self._repository_url + '/bootstrap/' + bootstrap_name
            active_url = self._repository_url + '/bootstrap/' + active_name
            print("Attempting to download", bootstrap_name, "from", bootstrap_url)
            dest_dir = self.get_bootstrap_cache_dir()
            # Normalize to no trailing slash for repository_url
            download_atomic(dest_dir + '/' + bootstrap_name, bootstrap_url, self._packages_dir)
            print("Attempting to download", active_name, "from", active_url)
            download_atomic(dest_dir + '/' + active_name, active_url, self._packages_dir)
            return True
        except FetchError:
            return False
Exemple #5
0
    def checkout_to(self, directory):
        # Download file to cache if it isn't already there
        if not os.path.exists(self.cache_filename):
            print("Downloading source tarball {}".format(self.url))
            download_atomic(self.cache_filename, self.url, self.working_directory)

        # Validate the sha1 of the source is given and matches the sha1
        file_sha = sha1(self.cache_filename)

        if self.sha != file_sha:
            corrupt_filename = self.cache_filename + '.corrupt'
            check_call(['mv', self.cache_filename, corrupt_filename])
            raise ValidationError(
                "Provided sha1 didn't match sha1 of downloaded file, corrupt download saved as {}. "
                "Provided: {}, Download file's sha1: {}, Url: {}".format(
                    corrupt_filename, self.sha, file_sha, self.url))

        if self.extract:
            extract_archive(self.cache_filename, directory)
        else:
            # Copy the file(s) into src/
            # TODO(cmaloney): Hardlink to save space?
            shutil.copyfile(self.cache_filename, self._get_filename(directory))