def get_packages(self, connection, repository, consumer): baseurl = repository.url repomd = urljoin(baseurl, "repodata/repomd.xml") self.logger.debug("repomd: %s", repomd) repomd_tree = etree.parse(connection.open_stream(repomd)) mandatory = self._get_mandatory_packages( self._load_db(connection, baseurl, repomd_tree, "group_gz", "group")) primary_db = self._load_db(connection, baseurl, repomd_tree, "primary") if primary_db is None: raise ValueError("Malformed repository: {0}".format(repository)) counter = 0 for tag in primary_db.iterfind("./main:package", _NAMESPACES): try: name = tag.find("./main:name", _NAMESPACES).text consumer( Package( repository=repository, name=tag.find("./main:name", _NAMESPACES).text, version=self._unparse_version_attrs( tag.find("./main:version", _NAMESPACES).attrib), filesize=int( tag.find("./main:size", _NAMESPACES).attrib.get("package", -1)), filename=tag.find("./main:location", _NAMESPACES).attrib["href"], checksum=self._get_checksum(tag), mandatory=name in mandatory, requires=self._get_relations(tag, "requires"), obsoletes=self._get_relations(tag, "obsoletes"), provides=self._get_provides_from_xml(tag), group=tag.find("./main:format/rpm:group", _NAMESPACES).text, )) except (ValueError, KeyError) as e: self.logger.error("Malformed tag %s - %s: %s", repository, etree.tostring(tag), six.text_type(e)) raise counter += 1 self.logger.info("loaded: %d packages from %s.", counter, repository)
def load_package_from_file(self, repository, filepath): fullpath = utils.get_path_from_url(repository.url + filepath) _, size, checksum = next( iter( utils.get_size_and_checksum_for_files([fullpath], _checksum_collector))) pkg = createrepo.yumbased.YumLocalPackage(filename=fullpath) hdr = pkg.returnLocalHeader() return Package( repository=repository, name=hdr["name"], version=RpmPackageVersion(hdr['epoch'], hdr['version'], hdr['release']), filesize=int(hdr['size']), filename=filepath, checksum=FileChecksum(*checksum), mandatory=False, requires=self._parse_package_relations(pkg.requires), obsoletes=self._parse_package_relations(pkg.obsoletes), provides=self._get_provides_from_rpm(pkg), group=hdr["group"], )
def get_packages(self, connection, repository, consumer): index = self._get_url_of_metafile(repository, "Packages.gz") stream = GzipDecompress(connection.open_stream(index)) self.logger.info("loading packages from %s ...", repository) pkg_iter = deb822.Packages.iter_paragraphs(stream) counter = 0 for dpkg in pkg_iter: try: consumer( Package( repository=repository, name=dpkg["package"], version=Version(dpkg['version']), filesize=int(dpkg.get('size', -1)), filename=dpkg["filename"], checksum=FileChecksum( md5=dpkg.get("md5sum"), sha1=dpkg.get("sha1"), sha256=dpkg.get("sha256"), ), mandatory=self._is_mandatory(dpkg), # Recommends are installed by default (since Lucid) requires=self._get_relations(dpkg, "depends", "pre-depends", "recommends"), # The deb does not have obsoletes section obsoletes=[], provides=self._get_relations(dpkg, "provides"), group=dpkg.get("section"), )) except KeyError as e: self.logger.error("Malformed index %s - %s: %s", repository, six.text_type(dpkg), six.text_type(e)) raise counter += 1 self.logger.info("loaded: %d packages from %s.", counter, repository)
def load_package_from_file(self, repository, filename): filepath = utils.get_path_from_url(repository.url + filename) _, size, checksum = next( iter( utils.get_size_and_checksum_for_files([filepath], _checksum_collector))) with closing(debfile.DebFile(filepath)) as deb: debcontrol = deb822.Packages( deb.control.get_content(debfile.CONTROL_FILE)) return Package( repository=repository, name=debcontrol["package"], version=Version(debcontrol['version']), filesize=int(debcontrol.get('size', size)), filename=filename, checksum=FileChecksum(*checksum), mandatory=self._is_mandatory(debcontrol), requires=self._get_relations(debcontrol, "depends", "pre-depends", "recommends"), provides=self._get_relations(debcontrol, "provides"), obsoletes=[], group=debcontrol.get('section'), )