コード例 #1
0
ファイル: repodb.py プロジェクト: devzero2000/pyrpm
 def readComps(self):
     # Try to read a comps.xml file if there is any before we parse the
     # primary.xml
     if self.repomd.has_key("group"):
         if not self.repomd["group"].has_key("location"):
             log.error(
                 "Couldn't find proper location for comps.xml in repomd")
             return 0
         comps = self.repomd["group"]["location"]
         (csum, destfile) = self.nc.checksum(comps, "sha")
         if self.repomd["group"].has_key("checksum") and \
                csum == self.repomd["group"]["checksum"]:
             filename = destfile
         else:
             filename = self.nc.cache(comps, 1)
         if not filename:
             return 0
         try:
             self.comps = RpmCompsXML(self.config, filename)
             self.comps.read()
         except IOError:
             return 0
     return 1
コード例 #2
0
ファイル: repodb.py プロジェクト: pombredanne/cvs-pyrpm
 def readComps(self):
     # Try to read a comps.xml file if there is any before we parse the
     # primary.xml
     if self.repomd.has_key("group"):
         if not self.repomd["group"].has_key("location"):
             log.error("Couldn't find proper location for comps.xml in repomd")
             return 0
         comps = self.repomd["group"]["location"]
         (csum, destfile) = self.nc.checksum(comps, "sha")
         if self.repomd["group"].has_key("checksum") and \
                csum == self.repomd["group"]["checksum"]:
             filename = destfile
         else:
             filename = self.nc.cache(comps, 1)
         if not filename:
             return 0
         try:
             self.comps = RpmCompsXML(self.config, filename)
             self.comps.read()
         except IOError:
             return 0
     return 1
コード例 #3
0
ファイル: repodb.py プロジェクト: pombredanne/cvs-pyrpm
class RpmRepoDB(memorydb.RpmMemoryDB):
    """A (mostly) read-only RPM database storage in repodata XML.

    This is not a full implementation of Database: notably the file database
    is not populated at all."""

    # A mapping between strings and RPMSENSE_* comparison flags
    flagmap = { 0 : None,
                None: 0,
                "EQ": RPMSENSE_EQUAL,
                "LT": RPMSENSE_LESS,
                "GT": RPMSENSE_GREATER,
                "LE": RPMSENSE_EQUAL | RPMSENSE_LESS,
                "GE": RPMSENSE_EQUAL | RPMSENSE_GREATER,
                RPMSENSE_EQUAL: "EQ",
                RPMSENSE_LESS: "LT",
                RPMSENSE_GREATER: "GT",
                RPMSENSE_EQUAL | RPMSENSE_LESS: "LE",
                RPMSENSE_EQUAL | RPMSENSE_GREATER: "GE"}

    def __init__(self, config, source, buildroot='', reponame="default", nc=None):
        """Exclude packages matching whitespace-separated excludes.  Use
        reponame for cache subdirectory name and pkg["yumreponame"].

        Load PGP keys from URLs in key_urls."""

        memorydb.RpmMemoryDB.__init__(self, config, source, buildroot)
        self.reponame = reponame
        self.excludes = self.config.excludes[:]
        self.mirrorlist = None
        self.baseurls = None
        self.yumconf = None
        self.key_urls = []
        if nc:
            self.nc = nc
        else:
            self.nc = NetworkCache([], self.config.cachedir, self.reponame)
        if isinstance(source, types.DictType):
            found_urls = False
            self.yumconf = source
            if self.yumconf.has_key("main"):
                sec = self.yumconf["main"]
                if sec.has_key("exclude"):
                    self.excludes.extend(sec["exclude"])
            sec = self.yumconf[self.reponame]
            if sec.has_key("exclude"):
                self.excludes.extend(sec["exclude"])
            if sec.has_key("gpgkey"):
                self.key_urls = sec["gpgkey"]
            if sec.has_key("baseurl"):
                self.nc.addCache(sec["baseurl"], self.reponame)
                found_urls = True
            if sec.has_key("mirrorlist"):
                self.mirrorlist = sec["mirrorlist"]
                found_urls = True
            if not found_urls:
                raise ValueError, "yum.conf is missing mirrorlist or baseurl parameter"
        else:
            self.baseurls = source
            self.nc.addCache(self.baseurls, self.reponame)
        self.repomd = None
        self.filelist_imported  = 0
        # Files included in primary.xml
        self._filerc = re.compile('^(.*bin/.*|/etc/.*|/usr/lib/sendmail)$')
        self._dirrc = re.compile('^(.*bin/.*|/etc/.*)$')
        self.comps = None

    def readMirrorList(self):
        if not self.is_read and self.mirrorlist and self.yumconf:
            fname = self.nc.cache(self.mirrorlist, 1)
            if fname:
                lines = open(fname).readlines()
                os.unlink(fname)
            else:
                lines = []
            for l in lines:
                l = l.strip()
                l = l.replace("$ARCH", "$basearch")
                l = self.yumconf.replaceVars(l)
                if l and l[0] != "#":
                    self.nc.addCache([l,])

    def getExcludes(self):
        return self.excludes

    def getMirrorList(self):
        return self.mirrorlist

    def isIdentitySave(self):
        """return if package objects that are added are in the db afterwards
        (.__contains__() returns True and the object are return from searches)
        """
        return False

    def readRepoMD(self):
        # First we try and read the repomd file as a starting point.
        filename = self.nc.cache("repodata/repomd.xml", 1)
        if not filename:
            log.error("Couldn't open repomd.xml")
            return 0
        try:
            fd = open(filename)
            ip = iterparse(fd, events=("start","end"))
            ip = iter(ip)
        except IOError:
            log.error("Couldn't parse repomd.xml")
            return 0
        # Create our network cache object
        self.repomd = self._parse(ip)
        return 1

    def readComps(self):
        # Try to read a comps.xml file if there is any before we parse the
        # primary.xml
        if self.repomd.has_key("group"):
            if not self.repomd["group"].has_key("location"):
                log.error("Couldn't find proper location for comps.xml in repomd")
                return 0
            comps = self.repomd["group"]["location"]
            (csum, destfile) = self.nc.checksum(comps, "sha")
            if self.repomd["group"].has_key("checksum") and \
                   csum == self.repomd["group"]["checksum"]:
                filename = destfile
            else:
                filename = self.nc.cache(comps, 1)
            if not filename:
                return 0
            try:
                self.comps = RpmCompsXML(self.config, filename)
                self.comps.read()
            except IOError:
                return 0
        return 1

    def readPrimary(self):
        # If we have either a local cache of the primary.xml.gz file or if
        # it is already local (nfs or local file system) we calculate it's
        # checksum and compare it with the one from repomd. If they are
        # the same we don't need to cache it again and can directly use it.
        if self.repomd.has_key("primary"):
            if not self.repomd["primary"].has_key("location"):
                return 0
            primary = self.repomd["primary"]["location"]
            (csum, destfile) = self.nc.checksum(primary, "sha")
            if self.repomd["primary"].has_key("checksum") and \
                   csum == self.repomd["primary"]["checksum"]:
                filename = destfile
            else:
                filename = self.nc.cache(primary, 1)
            if not filename:
                return 0
            try:
                fd = PyGZIP(filename)
                ip = iterparse(fd, events=("start","end"))
                ip = iter(ip)
            except IOError:
                log.error("Couldn't parse primary.xml")
                return 0
            self._parse(ip)
        return 1

    def readPGPKeys(self):
        for url in self.key_urls:
            filename = self.nc.cache(url, 1)
            try:
                f = file(filename)
                key_data = f.read()
                f.close()
            except Exception, e:
                log.error("Error reading GPG key %s: %s", filename, e)
                continue
            try:
                key_data = openpgp.isolateASCIIArmor(key_data)
                keys = openpgp.parsePGPKeys(key_data)
            except Exception, e:
                log.error("Invalid GPG key %s: %s", url, e)
                continue
            for k in keys:
                self.keyring.addKey(k)
コード例 #4
0
ファイル: repodb.py プロジェクト: devzero2000/pyrpm
class RpmRepoDB(memorydb.RpmMemoryDB):
    """A (mostly) read-only RPM database storage in repodata XML.

    This is not a full implementation of Database: notably the file database
    is not populated at all."""

    # A mapping between strings and RPMSENSE_* comparison flags
    flagmap = {
        0: None,
        None: 0,
        "EQ": RPMSENSE_EQUAL,
        "LT": RPMSENSE_LESS,
        "GT": RPMSENSE_GREATER,
        "LE": RPMSENSE_EQUAL | RPMSENSE_LESS,
        "GE": RPMSENSE_EQUAL | RPMSENSE_GREATER,
        RPMSENSE_EQUAL: "EQ",
        RPMSENSE_LESS: "LT",
        RPMSENSE_GREATER: "GT",
        RPMSENSE_EQUAL | RPMSENSE_LESS: "LE",
        RPMSENSE_EQUAL | RPMSENSE_GREATER: "GE"
    }

    def __init__(self,
                 config,
                 source,
                 buildroot='',
                 reponame="default",
                 nc=None):
        """Exclude packages matching whitespace-separated excludes.  Use
        reponame for cache subdirectory name and pkg["yumreponame"].

        Load PGP keys from URLs in key_urls."""

        memorydb.RpmMemoryDB.__init__(self, config, source, buildroot)
        self.reponame = reponame
        self.excludes = self.config.excludes[:]
        self.mirrorlist = None
        self.baseurls = None
        self.yumconf = None
        self.key_urls = []
        if nc:
            self.nc = nc
        else:
            self.nc = NetworkCache([], self.config.cachedir, self.reponame)
        if isinstance(source, types.DictType):
            found_urls = False
            self.yumconf = source
            if self.yumconf.has_key("main"):
                sec = self.yumconf["main"]
                if sec.has_key("exclude"):
                    self.excludes.extend(sec["exclude"])
            sec = self.yumconf[self.reponame]
            if sec.has_key("exclude"):
                self.excludes.extend(sec["exclude"])
            if sec.has_key("gpgkey"):
                self.key_urls = sec["gpgkey"]
            if sec.has_key("baseurl"):
                self.nc.addCache(sec["baseurl"], self.reponame)
                found_urls = True
            if sec.has_key("mirrorlist"):
                self.mirrorlist = sec["mirrorlist"]
                found_urls = True
            if not found_urls:
                raise ValueError, "yum.conf is missing mirrorlist or baseurl parameter"
        else:
            self.baseurls = source
            self.nc.addCache(self.baseurls, self.reponame)
        self.repomd = None
        self.filelist_imported = 0
        # Files included in primary.xml
        self._filerc = re.compile('^(.*bin/.*|/etc/.*|/usr/lib/sendmail)$')
        self._dirrc = re.compile('^(.*bin/.*|/etc/.*)$')
        self.comps = None

    def readMirrorList(self):
        if not self.is_read and self.mirrorlist and self.yumconf:
            fname = self.nc.cache(self.mirrorlist, 1)
            if fname:
                lines = open(fname).readlines()
                os.unlink(fname)
            else:
                lines = []
            for l in lines:
                l = l.strip()
                l = l.replace("$ARCH", "$basearch")
                l = self.yumconf.replaceVars(l)
                if l and l[0] != "#":
                    self.nc.addCache([
                        l,
                    ])

    def getExcludes(self):
        return self.excludes

    def getMirrorList(self):
        return self.mirrorlist

    def isIdentitySave(self):
        """return if package objects that are added are in the db afterwards
        (.__contains__() returns True and the object are return from searches)
        """
        return False

    def readRepoMD(self):
        # First we try and read the repomd file as a starting point.
        filename = self.nc.cache("repodata/repomd.xml", 1)
        if not filename:
            log.error("Couldn't open repomd.xml")
            return 0
        try:
            fd = open(filename)
            ip = iterparse(fd, events=("start", "end"))
            ip = iter(ip)
        except IOError:
            log.error("Couldn't parse repomd.xml")
            return 0
        # Create our network cache object
        self.repomd = self._parse(ip)
        return 1

    def readComps(self):
        # Try to read a comps.xml file if there is any before we parse the
        # primary.xml
        if self.repomd.has_key("group"):
            if not self.repomd["group"].has_key("location"):
                log.error(
                    "Couldn't find proper location for comps.xml in repomd")
                return 0
            comps = self.repomd["group"]["location"]
            (csum, destfile) = self.nc.checksum(comps, "sha")
            if self.repomd["group"].has_key("checksum") and \
                   csum == self.repomd["group"]["checksum"]:
                filename = destfile
            else:
                filename = self.nc.cache(comps, 1)
            if not filename:
                return 0
            try:
                self.comps = RpmCompsXML(self.config, filename)
                self.comps.read()
            except IOError:
                return 0
        return 1

    def readPrimary(self):
        # If we have either a local cache of the primary.xml.gz file or if
        # it is already local (nfs or local file system) we calculate it's
        # checksum and compare it with the one from repomd. If they are
        # the same we don't need to cache it again and can directly use it.
        if self.repomd.has_key("primary"):
            if not self.repomd["primary"].has_key("location"):
                print "Error primary has no location"
                return 0
            primary = self.repomd["primary"]["location"]
            #            if self.repomd["primary"].has_key("checksum"):
            #                (csum, destfile) = self.nc.checksum(primary, "sha")
            #                   csum == self.repomd["primary"]["checksum"]:
            #                filename = destfile
            #            else:
            filename = self.nc.cache(primary, 1)
            if not filename:
                print "Error can't find file for primary: " + primary
                return 0
            try:
                fd = PyGZIP(filename)
                ip = iterparse(fd, events=("start", "end"))
                ip = iter(ip)
            except IOError:
                log.error("Couldn't parse primary.xml")
                print "Error parsing primary.xml"
                return 0
            self._parse(ip)
        return 1

    def readPGPKeys(self):
        for url in self.key_urls:
            filename = self.nc.cache(url, 1)
            try:
                f = file(filename)
                key_data = f.read()
                f.close()
            except Exception, e:
                log.error("Error reading GPG key %s: %s", filename, e)
                continue
            try:
                key_data = openpgp.isolateASCIIArmor(key_data)
                keys = openpgp.parsePGPKeys(key_data)
            except Exception, e:
                log.error("Invalid GPG key %s: %s", url, e)
                continue
            for k in keys:
                self.keyring.addKey(k)