Example #1
0
    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
Example #2
0
    def dctrls(self):
        """return plan dependencies control file info"""
        toquery = set([ Dependency(pkg) for pkg in self ])
        packages = PackageGetter(toquery, self.pool)

        dctrls = {}
        for dep in toquery:
            package_path = packages[dep]
            if package_path is None:
                raise Error('could not find package', dep.name)
            dctrls[dep] = debinfo.get_control_fields(package_path)
            dctrls[dep]['Filename'] = basename(package_path)

        return dctrls
Example #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
Example #4
0
    def add(self, path):
        """Add binary to cache. Hardlink if possible, copy otherwise."""
        suffix = get_suffix(path)
        if not suffix in ('deb', 'udeb'):
            raise Error("illegal package suffix (%s)" % suffix)

        control_fields = debinfo.get_control_fields(path)
        name = control_fields['Package']
        version = control_fields['Version']

        if self.exists(name, version):
            return

        arch = control_fields['Architecture']
        filename = "%s_%s_%s.%s" % (name, version, arch, suffix)
        path_cached = join(self.path, filename)
        hardlink_or_copy(path, path_cached)

        self._register(filename)
Example #5
0
File: pool.py Project: qrntz/pool
    def add(self, path):
        """Add binary to cache. Hardlink if possible, copy otherwise."""
        suffix = get_suffix(path)
        if not suffix in ('deb', 'udeb'):
            raise Error("illegal package suffix (%s)" % suffix)

        control_fields = debinfo.get_control_fields(path)
        name = control_fields['Package']
        version = control_fields['Version']

        if self.exists(name, version):
            return

        arch = control_fields['Architecture']
        filename = "%s_%s_%s.%s" % (name, version, arch, suffix)
        path_cached = join(self.path, filename)
        hardlink_or_copy(path, path_cached)

        self._register(filename)
Example #6
0
    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
Example #7
0
    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
Example #8
0
def extract_source_name(path):
    fields = debinfo.get_control_fields(path)
    if 'Source' in fields:
        return fields['Source']

    return None
Example #9
0
    def resolve(self):
        """resolve plan dependencies recursively -> return spec"""
        spec = Spec()

        if not self.pool:
            return list(self)

        resolved = set()
        missing = set()
        provided = set()

        def reformat2dep(pkg):
            if '=' not in pkg:
                return pkg

            name, version = pkg.split("=", 1)
            return "%s (= %s)" % (name, version)

        unresolved = set([ Dependency(reformat2dep(pkg)) for pkg in self ])
        while unresolved:
            # get newest package versions of unresolved dependencies from the pool
            # and pray they don't conflict with our dependency restrictions
            packages = PackageGetter(unresolved, self.pool)
            new_deps = set()
            for dep in unresolved:
                package_path = packages[dep]
                if not package_path:
                    continue

                pkg_control = debinfo.get_control_fields(package_path)

                version = pkg_control['Version']
                if not dep.is_version_ok(version):
                    raise Error("dependency '%s' incompatible with newest pool version (%s)" % (dep, version))
                spec.add(dep.name, version)
                resolved.add(dep)

                new_deps |= self._get_new_deps(pkg_control, resolved | unresolved | new_deps, dep.fields)
                provided |= self._get_provided(pkg_control)

            unresolved = new_deps - resolved
            missing = (missing | packages.missing) - provided

        if missing:
            def get_origins(dep):
                # trace the package origins
                origins = []
                while dep:
                    try:
                        dep = self.packageorigins[dep][0]
                        origins.append(dep)
                    except KeyError:
                        dep = None

                return origins

            brokendeps = []
            for dep in missing:
                brokendeps.append("%s (%s)" % (dep, " -> ".join(get_origins(dep))))

            raise Error("broken dependencies: " + "\n".join(brokendeps))

        return spec
Example #10
0
def extract_source_name(path):
    fields = debinfo.get_control_fields(path)
    if 'Source' in fields:
        return fields['Source']

    return None