Exemple #1
0
    def _load_releases(self, base_path):
        "Load release information from the repository we came from."

        for pkg in self.packages:
            release_key = _gen_release_key(pkg["distribution"],
                                           pkg["component"])
            if release_key in self.release_info:
                continue

            toprelease_fn = "%s/dists/%s/Release" % (base_path,
                                                     pkg["distribution"])

            if os.path.exists(toprelease_fn):
                toprelease_file = open(toprelease_fn)
                self.toprelease_info[pkg["distribution"]] = \
                    toprelease_file.readlines()
                toprelease_file.close()

            release_fn = "%s/dists/%s/%s/binary-%s/Release" \
                         % (base_path, pkg["distribution"],
                            pkg["component"], self.config["arch"])

            if os.path.exists(release_fn):
                release_file = hashfile.open(release_fn)
                release_md5 = md5.new()
                release_sha = sha.new()
                release_file.add_hash(release_md5)
                release_file.add_hash(release_sha)
                release_data = release_file.read()
                release_file.close()

                self.release_info[release_key] = \
                    (release_md5, release_sha, release_data)
Exemple #2
0
    def _load_releases(self, base_path):
        "Load release information from the repository we came from."

        for pkg in self.packages:
            release_key = _gen_release_key(pkg["distribution"],
                                           pkg["component"])
            if release_key in self.release_info:
                continue

            toprelease_fn = "%s/dists/%s/Release" % (base_path,
                                                     pkg["distribution"])

            if os.path.exists(toprelease_fn):
                toprelease_file = open(toprelease_fn)
                self.toprelease_info[pkg["distribution"]] = \
                    toprelease_file.readlines()
                toprelease_file.close()

            release_fn = "%s/dists/%s/%s/binary-%s/Release" \
                         % (base_path, pkg["distribution"],
                            pkg["component"], self.config["arch"])

            if os.path.exists(release_fn):
                release_file = hashfile.open(release_fn)
                release_md5 = md5.new()
                release_sha = sha.new()
                release_file.add_hash(release_md5)
                release_file.add_hash(release_sha)
                release_data = release_file.read()
                release_file.close()

                self.release_info[release_key] = \
                    (release_md5, release_sha, release_data)
Exemple #3
0
    def _compress_and_hash_indexes(self):
        """Create compressed versions of indexes, and their hashes.
        Also clear out zero-length files."""

        index_list = [[(x, z) for z in y]
                      for (x, y) in self.index_paths.items()]
        index_list = reduce(lambda x, y: x + y, index_list)

        for (distro_key, index_fn) in index_list:
            if index_fn[-7:] == "Release":
                continue

            if os.path.exists(self.dest_path + "/" + index_fn):
                (fn_path, fn) = os.path.split(index_fn)
                fn_size = os.stat(self.dest_path + "/" + index_fn).st_size
                if fn_size > 0:
                    gzip_fn = index_fn + ".gz"
                    gzip_hash = hashfile.open(
                        self.dest_path + "/" + gzip_fn, "w")
                    gzip_md5 = hashlib.md5()
                    gzip_sha1 = hashlib.sha1()
                    gzip_sha256 = hashlib.sha256()
                    gzip_sha512 = hashlib.sha512()
                    gzip_hash.add_hash(gzip_md5)
                    gzip_hash.add_hash(gzip_sha1)
                    gzip_hash.add_hash(gzip_sha256)
                    gzip_hash.add_hash(gzip_sha512)

                    gzip_file = gzip.GzipFile(fn, "w", 9,
                                              gzip_hash)

                    part_file = open(self.dest_path + "/" + index_fn)
                    gzip_file.write(part_file.read())
                    part_file.close()
                    gzip_file.close()

                    self.index_paths[distro_key].append(gzip_fn)
                    self.index_hashes[gzip_fn] = (gzip_md5.hexdigest(),
                                              gzip_sha1.hexdigest(),
                                              gzip_sha256.hexdigest(),
                                              gzip_sha512.hexdigest())
            else:
                fn_size = 0

            if fn_size == 0:
                if os.path.isdir(self.dest_path + "/" + fn_path):
                    for emptyfn in \
                            os.listdir(self.dest_path + "/" + fn_path):
                        os.unlink("%s/%s/%s" % (self.dest_path, fn_path,
                                                emptyfn))
                    os.rmdir(self.dest_path + "/" + fn_path)
                self.index_paths[distro_key].remove(index_fn)
                del self.index_hashes[index_fn]
Exemple #4
0
    def _compress_and_hash_indexes(self):
        """Create compressed versions of indexes, and their hashes.
        Also clear out zero-length files."""

        index_list = [[(x, z) for z in y]
                      for (x, y) in self.index_paths.items()]
        index_list = reduce(lambda x, y: x + y, index_list)

        for (distro_key, index_fn) in index_list:
            if index_fn[-7:] == "Release":
                continue

            if os.path.exists(self.dest_path + "/" + index_fn):
                (fn_path, fn) = os.path.split(index_fn)
                fn_size = os.stat(self.dest_path + "/" + index_fn).st_size
                if fn_size > 0:
                    gzip_fn = index_fn + ".gz"
                    gzip_hash = hashfile.open(self.dest_path + "/" + gzip_fn,
                                              "w")
                    gzip_md5 = hashlib.md5()
                    gzip_sha1 = hashlib.sha1()
                    gzip_sha256 = hashlib.sha256()
                    gzip_sha512 = hashlib.sha512()
                    gzip_hash.add_hash(gzip_md5)
                    gzip_hash.add_hash(gzip_sha1)
                    gzip_hash.add_hash(gzip_sha256)
                    gzip_hash.add_hash(gzip_sha512)

                    gzip_file = gzip.GzipFile(fn, "w", 9, gzip_hash)

                    part_file = open(self.dest_path + "/" + index_fn)
                    gzip_file.write(part_file.read())
                    part_file.close()
                    gzip_file.close()

                    self.index_paths[distro_key].append(gzip_fn)
                    self.index_hashes[gzip_fn] = (gzip_md5.hexdigest(),
                                                  gzip_sha1.hexdigest(),
                                                  gzip_sha256.hexdigest(),
                                                  gzip_sha512.hexdigest())
            else:
                fn_size = 0

            if fn_size == 0:
                if os.path.isdir(self.dest_path + "/" + fn_path):
                    for emptyfn in \
                            os.listdir(self.dest_path + "/" + fn_path):
                        os.unlink("%s/%s/%s" %
                                  (self.dest_path, fn_path, emptyfn))
                    os.rmdir(self.dest_path + "/" + fn_path)
                self.index_paths[distro_key].remove(index_fn)
                del self.index_hashes[index_fn]
Exemple #5
0
    def get_file_size_and_hash(self):
        """Return (size, md5, sha1, sha256, sha512)
        for the main package file.
        """

        fn = self.cache.file_path(self.package.blob_id)
        size = os.stat(fn).st_size

        file = hashfile.open(fn)
        hash_md5 = hashlib.md5()
        hash_sha1 = hashlib.sha1()
        hash_sha256 = hashlib.sha256()
        hash_sha512 = hashlib.sha512()
        file.add_hash(hash_md5)
        file.add_hash(hash_sha1)
        file.add_hash(hash_sha256)
        file.add_hash(hash_sha512)
        file_data = file.read()
        file.close()

        return (size, hash_md5.hexdigest(), hash_sha1.hexdigest(), \
                   hash_sha256.hexdigest(), hash_sha512.hexdigest())
Exemple #6
0
    def get_file_size_and_hash(self):
        """Return (size, md5, sha1, sha256, sha512)
        for the main package file.
        """

        fn = self.cache.file_path(self.package.blob_id)
        size = os.stat(fn).st_size

        file = hashfile.open(fn)
        hash_md5 = hashlib.md5()
        hash_sha1 = hashlib.sha1()
        hash_sha256 = hashlib.sha256()
        hash_sha512 = hashlib.sha512()
        file.add_hash(hash_md5)
        file.add_hash(hash_sha1)
        file.add_hash(hash_sha256)
        file.add_hash(hash_sha512)
        file_data = file.read()
        file.close()

        return (size, hash_md5.hexdigest(), hash_sha1.hexdigest(), \
                   hash_sha256.hexdigest(), hash_sha512.hexdigest())
Exemple #7
0
    def _write_packages(self):
        "Link packages to the target, and write indexes."

        index_files = {}
        hashes = {}

        for pkg in self.packages:
            distro = pkg["distribution"]
            component = pkg["component"]
            distro_key = _gen_release_key(distro, component)

            if not index_files.has_key(distro_key):
                dist_path = "dists/%s/%s/binary-%s" \
                            % (distro, component, self.config["arch"])
                src_dist_path = "dists/%s/%s/source" \
                                % (distro, component)
                os.makedirs(self.dest_path + "/" + dist_path)
                os.makedirs(self.dest_path + "/" + src_dist_path)

                if distro_key not in self.index_paths:
                    self.index_paths[distro_key] = []

                if self.release_info.has_key(distro_key):
                    for release_path in (dist_path, src_dist_path):
                        (release_md5, release_sha, release_data) = \
                            self.release_info[distro_key]
                        release_fn = "%s/Release" % (release_path, )
                        release_file = open(self.dest_path + "/" + release_fn,
                                            "w")
                        release_file.write(release_data)
                        release_file.close()

                        self.index_paths[distro_key].append(release_fn)
                        hashes[release_fn] = (release_md5, release_sha)

                pkgs_fn = dist_path + "/Packages"
                pkgs_file = hashfile.open(self.dest_path + "/" + pkgs_fn, "w")
                pkgs_md5 = md5.new()
                pkgs_sha = sha.new()
                pkgs_file.add_hash(pkgs_md5)
                pkgs_file.add_hash(pkgs_sha)

                srcs_fn = src_dist_path + "/Sources"
                srcs_file = hashfile.open(self.dest_path + "/" + srcs_fn, "w")
                srcs_md5 = md5.new()
                srcs_sha = sha.new()
                srcs_file.add_hash(srcs_md5)
                srcs_file.add_hash(srcs_sha)

                self.index_paths[distro_key].extend([pkgs_fn, srcs_fn])
                index_files[distro_key] = (pkgs_file, srcs_file)
                hashes[pkgs_fn] = (pkgs_md5, pkgs_sha)
                hashes[srcs_fn] = (srcs_md5, srcs_sha)

            else:
                (pkgs_file, srcs_file) = index_files[distro_key]

            pkg.link(self.dest_path)

            if pkg.has_key("Binary"):
                index_file = srcs_file
            else:
                index_file = pkgs_file

            for line in pkg.get_lines():
                index_file.write(line)
            index_file.write("\n")

        for distro_key in index_files.keys():
            for x in index_files[distro_key]:
                x.close()
            for index_fn in self.index_paths[distro_key]:
                self.index_hashes[index_fn] = \
                    tuple([x.hexdigest() for x in hashes[index_fn]])
Exemple #8
0
    def _write_packages(self):
        "Link packages to the target, and write indexes."

        index_files = {}
        hashes = {}

        for pkg in self.packages:
            distro = pkg["distribution"]
            component = pkg["component"]
            distro_key = _gen_release_key(distro, component)

            if not index_files.has_key(distro_key):
                dist_path = "dists/%s/%s/binary-%s" \
                            % (distro, component, self.config["arch"])
                src_dist_path = "dists/%s/%s/source" \
                                % (distro, component)
                os.makedirs(self.dest_path + "/" + dist_path)
                os.makedirs(self.dest_path + "/" + src_dist_path)

                if distro_key not in self.index_paths:
                    self.index_paths[distro_key] = []

                if self.release_info.has_key(distro_key):
                    for release_path in (dist_path, src_dist_path):
                        (release_md5, release_sha, release_data) = \
                            self.release_info[distro_key]
                        release_fn = "%s/Release" % (release_path,)
                        release_file = open(
                            self.dest_path + "/" + release_fn, "w")
                        release_file.write(release_data)
                        release_file.close()

                        self.index_paths[distro_key].append(release_fn)
                        hashes[release_fn] = (release_md5, release_sha)

                pkgs_fn = dist_path + "/Packages"
                pkgs_file = hashfile.open(self.dest_path + "/" + pkgs_fn,
                                          "w")
                pkgs_md5 = md5.new()
                pkgs_sha = sha.new()
                pkgs_file.add_hash(pkgs_md5)
                pkgs_file.add_hash(pkgs_sha)

                srcs_fn = src_dist_path + "/Sources"
                srcs_file = hashfile.open(self.dest_path + "/" + srcs_fn,
                                          "w")
                srcs_md5 = md5.new()
                srcs_sha = sha.new()
                srcs_file.add_hash(srcs_md5)
                srcs_file.add_hash(srcs_sha)

                self.index_paths[distro_key].extend([pkgs_fn, srcs_fn])
                index_files[distro_key] = (pkgs_file, srcs_file)
                hashes[pkgs_fn] = (pkgs_md5, pkgs_sha)
                hashes[srcs_fn] = (srcs_md5, srcs_sha)

            else:
                (pkgs_file, srcs_file) = index_files[distro_key]

            pkg.link(self.dest_path)

            if pkg.has_key("Binary"):
                index_file = srcs_file
            else:
                index_file = pkgs_file

            for line in pkg.get_lines():
                index_file.write(line)
            index_file.write("\n")

        for distro_key in index_files.keys():
            for x in index_files[distro_key]:
                x.close()
            for index_fn in self.index_paths[distro_key]:
                self.index_hashes[index_fn] = \
                    tuple([x.hexdigest() for x in hashes[index_fn]])