コード例 #1
0
ファイル: rpmdriver.py プロジェクト: thwarted/swup
 def open_db(self, writeflag=false):
     """(Re)opens the packagedatabase. Optional argument writeflag can
     be set to 1 if database should be (re)opened in write-mode.
     Default is 0 (read only) for the database."""
     try:
         self.db = rpm.opendb(writeflag,'/')
     except rpm.error:
         raise self.query_error, "unable to open local rpm database."
コード例 #2
0
 def open_db(self, writeflag=false):
     """(Re)opens the packagedatabase. Optional argument writeflag can
     be set to 1 if database should be (re)opened in write-mode.
     Default is 0 (read only) for the database."""
     try:
         self.db = rpm.opendb(writeflag, '/')
     except rpm.error:
         raise self.query_error, "unable to open local rpm database."
コード例 #3
0
 def prime(self):
     try:
         uid = os.getuid()
         if 'ts' in dir(rpm):
             # FIXME: make sure it works for users too.
             #This means we are in RPM>4.1 mode
             self.oldrpm = False
             self.db = rpm.TransactionSet(self.root)
             self.db.setVSFlags(~(rpm.RPMVSF_NODSA|rpm.RPMVSF_NORSA))
         else:
             self.oldrpm = True
             self.db = rpm.opendb(False, self.root)
     except rpm.error:
         raise ex.query_error, "unable to open local rpm database."
コード例 #4
0
ファイル: package.py プロジェクト: bhdn/scrutiny
 def __init__(self, name, h=None):
     if h:
         Pkg.__init__(self, name, '/', h)
     else:
         if v42:
             ts = rpm.TransactionSet()
             tab = ts.dbMatch('name', name)
             if not tab:
                 raise KeyError, name
             theHdr = tab.next()
         else:
             db = rpm.opendb()
             tab = db.findbyname(name)
             if not tab:
                 del db
                 raise KeyError, name
             theHdr = db[tab[0]]
             del db
         Pkg.__init__(self, name, '/', theHdr)
     self.extracted = 1
     # create a fake filename to satisfy some checks on the filename
     self.filename = '%s-%s-%s.%s.rpm' % (self[rpm.RPMTAG_NAME], self[rpm.RPMTAG_VERSION], self[rpm.RPMTAG_RELEASE], self[rpm.RPMTAG_ARCH])
コード例 #5
0
 def opendb_readwrite(self):
     if self.oldrpm:
         del self.db
         self.db = rpm.opendb(True, self.root)
コード例 #6
0
    def get_providers(self, resource, operator, version, release):
        valids = []
        invalids = []
        foundheaders = []
        checkver = True

        unwantedrequires = self._rpmlib_hack()
        for req in unwantedrequires:
            if resource == req:
                valids.append(self.get_package('rpm'))
                return valids, invalids
        if not operator or not version:
            checkver = False

        # Had to add this try/except hack, because rpm 4 raises rpm.error
        # when <string> in findbyname(<string>) does not match. Shame on rpm.
        try:
            if self.oldrpm:
                #
                # Old rpm leak memory, so we need to reset the database.
                # This takes some time, but is faster with readonly.
                # 
                del self.db
                self.db = rpm.opendb(False, self.root)
            
                # Check for package first.
                index = self.db.findbyname(resource)
                # If there was no matching package, check for capability.
                if len(index) < 1:
                    index = self.db.findbyprovides(resource)
                    
                # Last, check for file.
                if len(index) < 1:
                    index = self.db.findbyfile(resource)
                for i in index:
                    #
                    # anybody is ok:
                    #
                    header = self.db[i]
                    foundheaders.append(header)
            else:
                # Check for package first.
                headers = self.db.dbMatch('name',str(resource))
                # If there was no matching package, check for capability.
                if headers.count() < 1:
                    headers = self.db.dbMatch('providename', str(resource))
                # Last, check for file.
                if headers.count() < 1:
                    headers = self.db.dbMatch('basenames', str(resource))

                for header in headers:
                    foundheaders.append(header)

            #
            # Now the logic:
            #
            if len(foundheaders) == 0:
                    return valids, invalids
                            
            for header in foundheaders:
                if not checkver:
                    rpmname = header[rpm.RPMTAG_NAME]
                    package = self.get_package(rpmname)
                    valids.append(self.get_package(rpmname))
                    continue
                
                rpmname = header[rpm.RPMTAG_NAME]
                installedpackage = self.get_package(rpmname)
                #
                # we might have conflicts or provides specifying version:
                #
                checkoperator = ">="
                if operator:
                    checkoperator = operator
                if rpmname == resource:
                    #
                    # We ask for a specific version of the resource, so 
                    # we must create a package-like dict we can use for 
                    # comparison:
                    #
                    epoch, version = self._version_split(version)
                    
                    resourcepackage = { 'name': resource,
                                        'version': version,
                                        'release': release,
                                        'epoch': epoch }
                        
                    compres = self.version_compare(installedpackage, 
                                                resourcepackage)

                    if compres >= 0 and ( checkoperator == '>=' or 
                                            checkoperator == '=>'):
                        valids.append(installedpackage)
                    if compres <= 0 and ( checkoperator == '<=' or 
                                            checkoperator == '=<'):
                        valids.append(installedpackage)
                    elif compres < 0 and checkoperator == '<':
                        valids.append(installedpackage)
                    elif compres > 0 and checkoperator == '>':
                        valids.append(installedpackage)
                    elif compres == 0 and checkoperator == '=':
                        valids.append(installedpackage)
                    else:
                        invalids.append(installedpackage)
                else:
                    #
                    # The package just provides this resource, or does not
                    # forfill the version requirement:
                    # Think checking version here is overkill.
                    #
                    invalids.append(installedpackage)


            return valids, invalids
        except rpm.error, message:
            raise ex.query_error, message