Пример #1
0
    def Parse(self, path):
        result = []

        for header in rpm.readHeaderListFromFile(path):
            fields = {
                key: str(header[key], self.encoding)
                if header[key] is not None else None
                for key in
                ['name', 'version', 'release', 'packager', 'group', 'summary']
            }

            pkg = Package()

            pkg.name = fields['name']
            pkg.version = fields['version']  # XXX: handle release

            if fields['packager']:
                pkg.maintainers = extract_maintainers(
                    fields['packager'])  # XXX: may have multiple maintainers

            pkg.category = fields['group']
            pkg.comment = fields['summary']

            result.append(pkg)

        return result
Пример #2
0
    def iter_parse(self, path: str, factory: PackageFactory,
                   transformer: PackageTransformer) -> Iterable[PackageMaker]:
        for header in rpm.readHeaderListFromFile(path):
            with factory.begin() as pkg:
                fields = {
                    key: str(header[key], self.encoding)
                    if header[key] is not None else None
                    for key in [
                        'name', 'version', 'release', 'packager', 'group',
                        'summary'
                    ]
                }

                pkg.set_name(fields['name'])
                pkg.set_version(fields['version'])  # XXX: handle release

                if fields['version'] is None:
                    raise RuntimeError('version not defined')

                pkg.set_rawversion(
                    nevra_construct(None, header['epoch'], fields['version'],
                                    fields['release']))

                if fields['packager']:
                    pkg.add_maintainers(extract_maintainers(fields['packager'])
                                        )  # XXX: may have multiple maintainers

                pkg.add_categories(fields['group'])
                pkg.set_summary(fields['summary'])

                yield pkg
Пример #3
0
 def getLoadSteps(self):
     if self._count is None:
         if hasattr(rpm, "readHeaderFromFD"):
             return os.path.getsize(self._filename) / 2500
         else:
             return len(rpm.readHeaderListFromFile(self._filename))
     return self._count
Пример #4
0
def main():
    if len(sys.argv) == 1:
        sys.exit("Usage: convert.py <hdlist file|rpms dir> ...")

    if not hasattr(rpm, "headerFromPackage"):
        ts = rpm.TransactionSet()
    else:
        ts = None

    for entry in sys.argv[1:]:
        if os.path.isfile(entry):
            for header in rpm.readHeaderListFromFile(entry):
                name = header[rpm.RPMTAG_NAME]
                for filename in header[rpm.RPMTAG_FILENAMES]:
                    print filename, name
        if os.path.isdir(entry):
            for filename in os.listdir(entry):
                if filename.endswith(".rpm"):
                    filepath = os.path.join(entry, filename)
                    file = open(filepath)
                    if ts:
                        header = ts.hdrFromFdno(file.fileno())
                    else:
                        header = rpm.headerFromPackage(file.fileno())[0]
                    name = header[rpm.RPMTAG_NAME]
                    for filename in header[rpm.RPMTAG_FILENAMES]:
                        print filename, name
                    file.close()
Пример #5
0
    def iter_parse(self, path, factory):
        for header in rpm.readHeaderListFromFile(path):
            fields = {
                key: str(header[key], self.encoding)
                if header[key] is not None else None
                for key in
                ['name', 'version', 'release', 'packager', 'group', 'summary']
            }

            pkg = factory.begin()

            pkg.set_name(fields['name'])
            pkg.set_version(fields['version'])  # XXX: handle release
            pkg.set_origversion(
                nevra_construct(None, header['epoch'], fields['version'],
                                fields['release']))

            if fields['packager']:
                pkg.add_maintainers(extract_maintainers(
                    fields['packager']))  # XXX: may have multiple maintainers

            pkg.add_categories(fields['group'])
            pkg.set_summary(fields['summary'])

            yield pkg
Пример #6
0
 def getLoadSteps(self):
     if self._count is None:
         if hasattr(rpm, "readHeaderFromFD"):
             return os.path.getsize(self._filename)/2500
         else:
             return len(rpm.readHeaderListFromFile(self._filename))
     return self._count
Пример #7
0
def main():
    if len(sys.argv) != 4:
        sys.exit("Usage: hdlist2ipack.py <label> <hdlist> <infopack>")
    label = sys.argv[1]
    hdlistname = sys.argv[2]
    ipackname = sys.argv[3]
    packages = {}
    if os.path.exists(ipackname):
        file = open(ipackname)
        name = None
        for line in file.readlines():
            if line[0] == "K":
                name = line.rstrip().split(":")[1]
            elif name and line[0] == "V":
                value = line.rstrip().split(":", 2)[2]
                for pair in value.split(";"):
                    distrostr, versionstr = pair.split(":", 1)
                    distros = packages.setdefault(name, {})
                    versions = distros.setdefault(distrostr.strip(), {})
                    for version in versionstr.split(","):
                        versions[version.strip()] = 1
        file.close()
    for h in rpm.readHeaderListFromFile(hdlistname):
        if h["epoch"]:
            version = "%s:%s-%s" % (h["epoch"], h["version"], h["release"])
        else:
            version = "%s-%s" % (h["version"], h["release"])
        distros = packages.setdefault(h["name"].lower(), {})
        versions = distros.setdefault(label, {})
        versions[version] = 1
    if os.path.exists(ipackname):
        file = open(ipackname)
        oldlines = file.readlines()
        file.close()
    else:
        oldlines = []
    file = open(ipackname, "w")
    for line in oldlines:
        if line[0] not in ("K", "V"):
            file.write(line)
    packagenames = packages.keys()
    packagenames.sort()
    for packagename in packagenames:
        file.write("K:%s\n" % packagename)
        v = ""
        distros = packages[packagename]
        distronames = [SortStr(x) for x in distros.keys()]
        distronames.sort()
        for distroname in distronames:
            if v:
                v += "; "
            versions = distros[distroname].keys()
            versions.sort()
            v += "%s: %s" % (distroname, ", ".join(versions))
        file.write("V:tm:%s\n" % v)
    file.close()
Пример #8
0
    def iter_parse(self, path: str,
                   factory: PackageFactory) -> Iterable[PackageMaker]:
        for header in rpm.readHeaderListFromFile(path):
            with factory.begin() as pkg:
                assert (header.isSource())  # binary packages not supported yet

                def sanitize_key(key: Any) -> Any:
                    return rpm.tagnames[key].lower(
                    ) if key in rpm.tagnames else key

                def sanitize_value(value: Any) -> Any:
                    return value.decode(self._encoding,
                                        errors='ignore') if isinstance(
                                            value, bytes) else value

                pkgdata = {
                    sanitize_key(key): sanitize_value(value)
                    for key, value in dict(header).items()
                }

                # For Sisyphus (but not PCLinuxOS), there is pkgdata[1000011], which contains
                # a different name (for instance, for GLEW there is libGLEW-devel)
                # May use is for some other purposes

                pkg.add_name(pkgdata['name'], NameType.SRCRPM_NAME)

                if pkgdata['version'] is None:
                    raise RuntimeError('version not defined')

                version, flags = parse_rpm_version(self._vertags,
                                                   pkgdata['version'],
                                                   pkgdata['release'])
                pkg.set_version(version)
                pkg.set_rawversion(
                    nevra_construct(None, header['epoch'], pkgdata['version'],
                                    pkgdata['release']))
                pkg.set_flags(flags)

                if 'packager' in pkgdata:
                    pkg.add_maintainers(
                        extract_maintainers(pkgdata['packager'])
                    )  # XXX: may have multiple maintainers

                pkg.add_categories(pkgdata['group'])

                try:
                    # e.g. PCLinuxOS summaries may contain surrogate garbage
                    pkgdata['summary'].encode('utf-8')
                    pkg.set_summary(pkgdata['summary'])
                except:
                    pkg.log('incorrect UTF in summary', Logger.ERROR)

                pkg.set_arch(pkgdata['arch'])

                yield pkg
Пример #9
0
    def _checkRPM(self):
        if not hasattr(rpm, "readHeaderFromFD"):

            if (not hasattr(self.__class__, "WARNED") and
                sysconf.get("no-rpm-readHeaderFromFD", 0) < 3):

                self.__class__.WARNED = True
                sysconf.set("no-rpm-readHeaderFromFD",
                            sysconf.get("no-rpm-readHeaderFromFD", 0)+1)
                iface.warning(_("Your rpm module has no support for "
                                "readHeaderFromFD()!\n"
                                "As a consequence, Smart will consume "
                                "extra memory."))

            self.__class__.getHeaders = self.getHeadersHDL
            self.__class__.getHeader = self.getHeaderHDL
            self.__class__.loadFileProvides = self.loadFileProvidesHDL

            self._hdl = rpm.readHeaderListFromFile(self._filename)
Пример #10
0
    def _checkRPM(self):
        if not hasattr(rpm, "readHeaderFromFD"):

            if (not hasattr(self.__class__, "WARNED")
                    and sysconf.get("no-rpm-readHeaderFromFD", 0) < 3):

                self.__class__.WARNED = True
                sysconf.set("no-rpm-readHeaderFromFD",
                            sysconf.get("no-rpm-readHeaderFromFD", 0) + 1)
                iface.warning(
                    _("Your rpm module has no support for "
                      "readHeaderFromFD()!\n"
                      "As a consequence, Smart will consume "
                      "extra memory."))

            self.__class__.getHeaders = self.getHeadersHDL
            self.__class__.getHeader = self.getHeaderHDL
            self.__class__.loadFileProvides = self.loadFileProvidesHDL

            self._hdl = rpm.readHeaderListFromFile(self._filename)
Пример #11
0
    def getObsoletes(self, channel, msgCallback=None, progressCallback=None):
        filePath = "%s/%s-obsoletes.%s" % (
            self.cfg["storageDir"], channel['label'], channel['version'])
        globPattern = "%s/%s-obsoletes.*" % (self.cfg["storageDir"],
                                             channel['label'])

        if msgCallback:
            msgCallback("Fetching obsoletes list for %s" % channel['url'])

        fileHdrList = "%s/link-%s" % (self.cfg['storageDir'], channel['label'])
        #print "fhl: %s" % fileHdrList

        hdrList = rpm.readHeaderListFromFile(fileHdrList)

        # FIXME: since we have the package list, and the headers, we dont
        # have to reload the headerlist...

        obsList = []
        total = len(hdrList)
        count = 0
        for hdr in hdrList:

            if progressCallback:
                progressCallback(count, total)
            count = count + 1
            # FIXME: we should share this logic somewhere...
            #   up2dateUtils maybe?
            if not hdr['obsoletes']:
                continue
            obs = up2dateUtils.genObsoleteTupleFromHdr(hdr)
            if obs:
                obsList = obsList + obs

        # now we have the package list, convert it to xmlrpc style
        # presentation and dump it
        obsList.sort(lambda a, b: cmp(a[0], b[0]))

        rpmSourceUtils.saveListToDisk(obsList, filePath, globPattern)

        return obsList
Пример #12
0
    def iter_parse(self, path, factory):
        for header in rpm.readHeaderListFromFile(path):
            fields = {
                key: str(header[key], self.encoding)
                if header[key] is not None else None
                for key in
                ['name', 'version', 'release', 'packager', 'group', 'summary']
            }

            pkg = factory.begin()

            pkg.name = fields['name']
            pkg.version = fields['version']  # XXX: handle release

            if fields['packager']:
                pkg.maintainers = extract_maintainers(
                    fields['packager'])  # XXX: may have multiple maintainers

            pkg.category = fields['group']
            pkg.comment = fields['summary']

            yield pkg
Пример #13
0
    def getObsoletes(self, channel, msgCallback=None, progressCallback=None):
        filePath = "%s/%s-obsoletes.%s" % (self.cfg["storageDir"], channel["label"], channel["version"])
        globPattern = "%s/%s-obsoletes.*" % (self.cfg["storageDir"], channel["label"])

        if msgCallback:
            msgCallback("Fetching obsoletes list for %s" % channel["url"])

        fileHdrList = "%s/link-%s" % (self.cfg["storageDir"], channel["label"])
        # print "fhl: %s" % fileHdrList

        hdrList = rpm.readHeaderListFromFile(fileHdrList)

        # FIXME: since we have the package list, and the headers, we dont
        # have to reload the headerlist...

        obsList = []
        total = len(hdrList)
        count = 0
        for hdr in hdrList:

            if progressCallback:
                progressCallback(count, total)
            count = count + 1
            # FIXME: we should share this logic somewhere...
            #   up2dateUtils maybe?
            if not hdr["obsoletes"]:
                continue
            obs = up2dateUtils.genObsoleteTupleFromHdr(hdr)
            if obs:
                obsList = obsList + obs

        # now we have the package list, convert it to xmlrpc style
        # presentation and dump it
        obsList.sort(lambda a, b: cmp(a[0], b[0]))

        rpmSourceUtils.saveListToDisk(obsList, filePath, globPattern)

        return obsList
Пример #14
0
    def iter_parse(self, path: str, factory: PackageFactory,
                   transformer: PackageTransformer) -> Iterable[PackageMaker]:
        for header in rpm.readHeaderListFromFile(path):
            with factory.begin() as pkg:
                assert (header.isSource())  # binary packages not supported yet

                pkgdata = {
                    rpm.tagnames[key].lower() if key in rpm.tagnames else key:
                    value.decode(self.encoding, errors='ignore') if isinstance(
                        value, bytes) else value
                    for key, value in dict(header).items()
                }

                # For Sisyphus (but not PCLinuxOS), there is pkgdata[1000011], which contains
                # a different name (for instance, for GLEW there is libGLEW-devel)
                # May use is for some other purposes

                pkg.add_name(pkgdata['name'], NameType.SRCRPM_NAME)
                pkg.set_version(pkgdata['version'])  # XXX: handle release

                if pkgdata['version'] is None:
                    raise RuntimeError('version not defined')

                pkg.set_rawversion(
                    nevra_construct(None, header['epoch'], pkgdata['version'],
                                    pkgdata['release']))

                if 'packager' in pkgdata:
                    pkg.add_maintainers(
                        extract_maintainers(pkgdata['packager'])
                    )  # XXX: may have multiple maintainers

                pkg.add_categories(pkgdata['group'])
                pkg.set_summary(pkgdata['summary'])
                pkg.set_arch(pkgdata['arch'])

                yield pkg
Пример #15
0
 def __init__(self, path):
     hdlist = rpm.readHeaderListFromFile(path)
     HeaderList.__init__(self, hdlist)
Пример #16
0
def usage():
    print "%s <headerlist>" % (sys.argv[0])


def compareHeaders(first, second):
    name1 = first[rpm.RPMTAG_NAME]
    name2 = second[rpm.RPMTAG_NAME]

    if (name1 < name2):
        return -1
    elif (name1 > name2):
        return 1
    return 0


if len(sys.argv) < 2:
    usage()
    sys.exit(0)

hdlist = rpm.readHeaderListFromFile(sys.argv[1])
hdlist.sort(compareHeaders)
for hdr in hdlist:
    if hdr[rpm.RPMTAG_EPOCH] == None:
        epoch = "0"
    else:
        epoch = hdr[rpm.RPMTAG_EPOCH]
    print "%s:%s-%s-%s.%s %s %s" % (epoch, hdr[rpm.RPMTAG_NAME], hdr[
        rpm.RPMTAG_VERSION], hdr[rpm.RPMTAG_RELEASE], hdr[rpm.RPMTAG_ARCH],
                                    hdr[1000002], hdr[1000003])
Пример #17
0
    def listPackages(self, channel, msgCallback=None, progressCallback=None):

        # TODO: implement cache invalidations, Last-Modified
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel['label'],
                                 channel['version'])

        # a glob used to find the old versions to cleanup
        globPattern = "%s/%s.*" % (self.cfg["storageDir"], channel['label'])
        oldLists = glob.glob(globPattern)
        channelTimeStamp = None
        if oldLists:
            filename = oldLists[0]
            filename = os.path.basename(filename)
            oldVersion = string.split(filename, '.')[-1]
            channelTimeStamp = time.strptime(oldVersion, "%Y%m%d%H%M%S")

        # assuming this is always bz2?
        url = "%s/base/pkglist.%s.bz2" % (channel['url'], channel['dist'])
        if msgCallback:
            msgCallback("Fetching %s" % url)

        ret = urlUtils.fetchUrl(url,
                                lastModified=channelTimeStamp,
                                progressCallback=progressCallback,
                                agent="Up2date %s/Apt" %
                                up2dateUtils.version())
        if ret:
            (buffer, lmtime) = ret
        else:
            return None

        symlinkname = "%s/link-%s" % (self.cfg["storageDir"], channel['label'])
        try:
            os.unlink(symlinkname)
        except OSError:
            # file doesnt exist, shrug
            pass

        self.version = time.strftime("%Y%m%d%H%M%S", lmtime)
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel['label'],
                                 self.version)

        # sigh, no native bzip2 module... do it the old fashioned way
        tmpfilename = "%s/tmp-%s-%s" % (self.cfg['storageDir'],
                                        channel['label'], self.version)
        #print "timefilename: %s" % tmpfilename
        f = open("%s.bz2" % tmpfilename, "w")
        f.write(buffer)
        f.close()

        # FIXME, um, lame... once we settle on what url/http lib
        # we use, plugin in proper callbacks
        if progressCallback:
            progressCallback(1, 1)

        # well, since we dont have any knowledge about what the
        # channel version is supposed to be, I'cant really rely
        # on that (with up2date, the login tells me what channel
        # versions to look for). So we need a generic name
        # we symlink to the latest version.

        pipe = os.popen("/usr/bin/bunzip2 %s.bz2" % tmpfilename)
        tmp = pipe.read()

        os.symlink(tmpfilename, symlinkname)

        hdrList = rpm.readHeaderListFromFile(tmpfilename)
        # a list of rpm hdr's, handy!!

        pkgList = []

        for hdr in hdrList:
            epoch = hdr['epoch']
            if epoch == None or epoch == "0" or epoch == 0:
                epoch = ""
            pkgList.append([
                hdr['name'],
                hdr['version'],
                hdr['release'],
                epoch,
                hdr['arch'],
                # we want the actual filesize, but alas...
                str(hdr['size']),
                channel['label']
            ])

            # what the hell, this is a little bit of a side effect, but
            # were already poking at headers, lets just save them while
            # were at it to same us some trouble
            rpmSourceUtils.saveHeader(hdr)
            self.headerCache["%s-%s-%s.%s" %
                             (hdr['name'], hdr['version'], hdr['release'],
                              hdr['arch'])] = hdr

        # nowwe have the package list, convert it to xmlrpc style
        # presentation and dump it
        pkgList.sort(lambda a, b: cmp(a[0], b[0]))

        rpmSourceUtils.saveListToDisk(pkgList, filePath, globPattern)

        return pkgList
Пример #18
0
def usage():
    print "%s <headerlist>" % (sys.argv[0])

def compareHeaders(first, second):
    name1 = first[rpm.RPMTAG_NAME]
    name2 = second[rpm.RPMTAG_NAME]

    if (name1 < name2):
        return -1
    elif (name1 > name2):
        return 1
    return 0


if len(sys.argv) < 2:
    usage()
    sys.exit(0)

hdlist = rpm.readHeaderListFromFile(sys.argv[1])
hdlist.sort(compareHeaders)
for hdr in hdlist:
    if hdr[rpm.RPMTAG_EPOCH] == None:
        epoch = "0"
    else:
        epoch = hdr[rpm.RPMTAG_EPOCH]
    print "%s:%s-%s-%s.%s %s %s" %(epoch,
                                hdr[rpm.RPMTAG_NAME], hdr[rpm.RPMTAG_VERSION],
                                hdr[rpm.RPMTAG_RELEASE], hdr[rpm.RPMTAG_ARCH],
                                hdr[1000002], hdr[1000003])
    
Пример #19
0
    def __init__(self, path, compatPackages = None, noscore = 0, prunePPCKernels = 1):
	hdlist = rpm.readHeaderListFromFile(path)
	HeaderList.__init__(self, hdlist, compatPackages = compatPackages,
			    noscore = noscore, prunePPCKernels = prunePPCKernels)
Пример #20
0
    def listPackages(self, channel, msgCallback=None, progressCallback=None):

        # TODO: implement cache invalidations, Last-Modified
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel["label"], channel["version"])

        # a glob used to find the old versions to cleanup
        globPattern = "%s/%s.*" % (self.cfg["storageDir"], channel["label"])
        oldLists = glob.glob(globPattern)
        channelTimeStamp = None
        if oldLists:
            filename = oldLists[0]
            filename = os.path.basename(filename)
            oldVersion = string.split(filename, ".")[-1]
            channelTimeStamp = time.strptime(oldVersion, "%Y%m%d%H%M%S")

        # assuming this is always bz2?
        url = "%s/base/pkglist.%s.bz2" % (channel["url"], channel["dist"])
        if msgCallback:
            msgCallback("Fetching %s" % url)

        ret = urlUtils.fetchUrl(
            url,
            lastModified=channelTimeStamp,
            progressCallback=progressCallback,
            agent="Up2date %s/Apt" % up2dateUtils.version(),
        )
        if ret:
            (buffer, lmtime) = ret
        else:
            return None

        symlinkname = "%s/link-%s" % (self.cfg["storageDir"], channel["label"])
        try:
            os.unlink(symlinkname)
        except OSError:
            # file doesnt exist, shrug
            pass

        self.version = time.strftime("%Y%m%d%H%M%S", lmtime)
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel["label"], self.version)

        # sigh, no native bzip2 module... do it the old fashioned way
        tmpfilename = "%s/tmp-%s-%s" % (self.cfg["storageDir"], channel["label"], self.version)
        # print "timefilename: %s" % tmpfilename
        f = open("%s.bz2" % tmpfilename, "w")
        f.write(buffer)
        f.close()

        # FIXME, um, lame... once we settle on what url/http lib
        # we use, plugin in proper callbacks
        if progressCallback:
            progressCallback(1, 1)

        # well, since we dont have any knowledge about what the
        # channel version is supposed to be, I'cant really rely
        # on that (with up2date, the login tells me what channel
        # versions to look for). So we need a generic name
        # we symlink to the latest version.

        pipe = os.popen("/usr/bin/bunzip2 %s.bz2" % tmpfilename)
        tmp = pipe.read()

        os.symlink(tmpfilename, symlinkname)

        hdrList = rpm.readHeaderListFromFile(tmpfilename)
        # a list of rpm hdr's, handy!!

        pkgList = []

        for hdr in hdrList:
            epoch = hdr["epoch"]
            if epoch == None or epoch == "0" or epoch == 0:
                epoch = ""
            pkgList.append(
                [
                    hdr["name"],
                    hdr["version"],
                    hdr["release"],
                    epoch,
                    hdr["arch"],
                    # we want the actual filesize, but alas...
                    str(hdr["size"]),
                    channel["label"],
                ]
            )

            # what the hell, this is a little bit of a side effect, but
            # were already poking at headers, lets just save them while
            # were at it to same us some trouble
            rpmSourceUtils.saveHeader(hdr)
            self.headerCache["%s-%s-%s.%s" % (hdr["name"], hdr["version"], hdr["release"], hdr["arch"])] = hdr

        # nowwe have the package list, convert it to xmlrpc style
        # presentation and dump it
        pkgList.sort(lambda a, b: cmp(a[0], b[0]))

        rpmSourceUtils.saveListToDisk(pkgList, filePath, globPattern)

        return pkgList