Beispiel #1
0
    def _download_tagged_http_resource(self,
                                       source_url,
                                       target_file,
                                       tag="",
                                       digest=None,
                                       connection_timeout=30):
        downloader = Downloader()
        if not tag:
            tag = downloader.tag(source_url)

        blob_file = os.path.join(os.path.dirname(target_file), tag)
        try:
            with open(blob_file + "$", "wb+") as f:
                for chunk in downloader.get(source_url, digest=digest):
                    f.write(chunk)
        except Exception:
            if os.path.exists(blob_file + "$"):
                os.unlink(blob_file + "$")
            raise
        #end try

        # Atomically rename blob.
        os.rename(blob_file + "$", blob_file)
        # Create temporary symlink to new blob.
        os.symlink(os.path.basename(blob_file), target_file + "$")
        # Atomically rename symlink (hopefully).
        os.rename(target_file + "$", target_file)
Beispiel #2
0
    def download(self):
        """
        Downloads all components of this source package to self.work_dir.
        """
        downloader = Downloader(progress_bar_class=ProgressBar)
        pool_dir = self.metadata.get("Directory")

        orig_tarball, \
        orig_components, \
        deb_tarball, \
        deb_patches, \
        debdiff_gz = self._guess_file_components()

        files_to_download = [orig_tarball, deb_tarball, debdiff_gz
                             ] + orig_components

        for filename in files_to_download:
            if not filename:
                continue

            outfile = os.path.join(self.work_dir, filename)

            url = "/".join([self.metadata.base_url, pool_dir, filename])

            LOGGER.info("fetching {}".format(url))

            with open(outfile, "wb+") as f:
                for chunk in downloader.get(url):
                    f.write(chunk)
            #end with
        #end for

        return self
Beispiel #3
0
    def fetch_from_repo(self, repo_name, pkg_name, version, filename,
            sha256sum=None):
        downloader = Downloader(progress_bar_class=ProgressBar)

        if pkg_name.startswith("lib"):
            first_letter = pkg_name[3]
        else:
            first_letter = pkg_name[0]

        rel_path = os.sep.join([first_letter, pkg_name, version, filename])

        mirror_url = DistroInfo().pick_mirror(
            release=self.release, repo_name=repo_name
        )

        source_url = "/".join([
            mirror_url,
            self.release,
            repo_name,
            "sources",
            rel_path
        ])

        target_url = os.sep.join([
            self.cache_dir,
            "bolt",
            "dists",
            self.release,
            "sources",
            repo_name,
            rel_path
        ])

        h = hashlib.sha256()

        LOGGER.info("retrieving {}".format(source_url))
        try:
            os.makedirs(os.path.dirname(target_url), exist_ok=True)

            with open(target_url, "wb+") as f:
                for chunk in downloader.get(source_url, digest=h):
                    f.write(chunk)
        except urllib.error.URLError as e:
            raise NetworkError(
                "failed to retrieve {}: {}".format(source_url, e.reason)
            )

        if sha256sum and sha256sum != h.hexdigest():
            raise BoltError("file {} has invalid checksum!".format(target_url))

        return target_url
Beispiel #4
0
    def build_content_spec(self):
        downloader = Downloader(progress_bar_class=ProgressBar)

        filename = self.metadata["Filename"]
        outfile = os.path.join(self.work_dir, os.path.basename(filename))
        url = "/".join([self.metadata.base_url, filename])

        LOGGER.info("fetching {}".format(url))

        with open(outfile, "wb+") as f:
            for chunk in downloader.get(url):
                f.write(chunk)
        #end with

        self.contents = \
            self._binary_deb_list_contents(outfile)