Esempio n. 1
0
class PoolInstaller(Installer):
    def __init__(self, chroot_path, pool_path, arch, environ={}):
        super(PoolInstaller, self).__init__(chroot_path, environ)

        from pyproject.pool.pool import Pool
        self.pool = Pool(pool_path)
        self.arch = arch

    @staticmethod
    def _get_package_index(packagedir):
        def filesize(path):
            return str(os.stat(path).st_size)

        def md5sum(path):
            return str(hashlib.md5(open(path, 'rb').read()).hexdigest())

        def sha256sum(path):
            return str(hashlib.sha256(open(path, 'rb').read()).hexdigest())

        index = []
        for package in os.listdir(packagedir):
            path = os.path.join(packagedir, package)
            # dl_path would best be calculated; but we don't have access to chroot_path here...
            dl_path = os.path.join('var/cache/apt/archives', package)
            if path.endswith('.deb'):
                control = debinfo.get_control_fields(path)
                for field in control.keys():
                    index.append(field + ": " + control[field])

                index.append("Filename: " + dl_path)
                index.append("Size: " + filesize(path))
                index.append("MD5sum: " + md5sum(path))
                index.append("SHA256: " + sha256sum(path))
                index.append("")

        return index

    def install(self, packages, ignore_errors=[]):
        """install packages into chroot via pool"""

        print "getting packages..."
        packagedir = join(self.chroot.path, "var/cache/apt/archives")
        self.pool.get(packagedir, packages, strict=True)

        print "generating package index..."
        sources_list = RevertibleFile(
            join(self.chroot.path, "etc/apt/sources.list"))
        print >> sources_list, "deb file:/// local debs"
        sources_list.close()

        index_file = "_dists_local_debs_binary-%s_Packages" % self.arch
        index_path = join(self.chroot.path, "var/lib/apt/lists", index_file)
        index = self._get_package_index(packagedir)
        file(index_path, "w").write("\n".join(index))
        self.chroot.system("apt-cache gencaches")

        print "installing packages..."
        self._install(packages, ignore_errors, ['--allow-unauthenticated'])
Esempio n. 2
0
class PoolInstaller(Installer):
    def __init__(self, chroot_path, pool_path, arch, environ={}):
        super(PoolInstaller, self).__init__(chroot_path, environ)

        from pyproject.pool.pool import Pool
        self.pool = Pool(pool_path)
        self.arch = arch

    @staticmethod
    def _get_package_index(packagedir):
        def filesize(path):
            return str(os.stat(path).st_size)

        def md5sum(path):
            return str(hashlib.md5(open(path, 'rb').read()).hexdigest())

        index = []
        for package in os.listdir(packagedir):
            path = os.path.join(packagedir, package)
            if path.endswith('.deb'):
                control = debinfo.get_control_fields(path)
                for field in control.keys():
                    index.append(field + ": " + control[field])

                index.append("Filename: " + path)
                index.append("Size: " + filesize(path))
                index.append("MD5sum: " + md5sum(path))
                index.append("")

        return index

    def install(self, packages, ignore_errors=[]):
        """install packages into chroot via pool"""

        print "getting packages..."
        packagedir = join(self.chroot.path, "var/cache/apt/archives")
        self.pool.get(packagedir, packages, strict=True)

        print "generating package index..."
        sources_list = RevertibleFile(join(self.chroot.path, "etc/apt/sources.list"))
        print >> sources_list, "deb file:/// local debs"
        sources_list.close()

        index_file = "_dists_local_debs_binary-%s_Packages" % self.arch
        index_path = join(self.chroot.path, "var/lib/apt/lists", index_file)
        index = self._get_package_index(packagedir)
        file(index_path, "w").write("\n".join(index))
        self.chroot.system("apt-cache gencaches")

        print "installing packages..."
        self._install(packages, ignore_errors, ['--allow-unauthenticated'])
Esempio n. 3
0
def get_packages_info(packages, pool_path):
    info = {}

    from pyproject.pool.pool import Pool
    pool = Pool(pool_path)

    tmpdir = TempDir()
    pool.get(tmpdir.path, packages, strict=True)

    for package in os.listdir(tmpdir.path):
        path = os.path.join(tmpdir.path, package)
        if path.endswith('.deb'):
            control = debinfo.get_control_fields(path)
            info[control['Package']] = control['Description']

    return info