Пример #1
0
class PackageKitConaryBackend(PackageKitBaseBackend):
    # Packages there require a reboot
    rebootpkgs = ("kernel", "glibc", "hal", "dbus")
    restartpkgs = ("PackageKit","gnome-packagekit")

    packages = []
    #{{{   Packages structure 
    """
    packages = {
        pkg_name: {
            'trove': ( name,version,flavor)
            'metadata': pkgDict,
        }
    }
    
    """
    #}}}
    #{{{ Init
    def __init__(self, args):
        PackageKitBaseBackend.__init__(self, args)

        # conary configurations
        conary = ConaryPk()
        self.cfg = conary.cfg
        self.client = conary.cli
        self.conary = conary
        self.callback = UpdateCallback(self, self.cfg)
        self.client.setUpdateCallback(self.callback)
        self.xmlcache = XMLCache()

    def _freezeData(self, version, flavor):
        frzVersion = version.freeze()
        frzFlavor = flavor.freeze()
        return ','.join([frzVersion, frzFlavor])

    def _thawData(self, frzVersion, frzFlavor ):
        version = versions.ThawVersion(frzVersion)
        flavor = deps.ThawFlavor(frzFlavor)
        return version, flavor
    #}}}
    def _get_arch(self, flavor):
        return _get_arch(flavor)
 
    @ExceptionHandler
    def check_installed(self, troveTuple):
        log.info("============check installed =========")
        result = self.conary.query(troveTuple[0])
        if result:
            installed = INFO_INSTALLED
        else:
            installed = INFO_AVAILABLE
        return installed

    def get_package_id_new(self,pkg):

        name,version,flavor = pkg.get("trove")
        metadata = pkg.get("metadata")
        data = ""
        if metadata:
            if "shortDesc" in metadata:
                data = metadata['shortDesc'].decode("UTF")
                if data == "." or data == "":
                    data = name.replace("-",' ').capitalize()
        return pkpackage.get_package_id(name, version.trailingRevision(), self._get_arch(flavor), data)
            
    @ExceptionHandler
    def get_package_id(self, name, versionObj, flavor):

        version = versionObj.trailingRevision()
        pkg = self.xmlcache.resolve(name)
        #pkg["shortDesc"] = "."
        arch = self._get_arch(flavor)
        #data = versionObj.asString() + "#"
        data = ""
        if pkg:
            if "shortDesc" in pkg:
                data = pkg['shortDesc'].decode("UTF")
                if data == "." or data == "":
                    data = name.replace("-",' ').capitalize()
                
        return pkpackage.get_package_id(name, version, arch, data)

    @ExceptionHandler
    def get_package_from_id(self, package_id):
        """ package_id(string) =
        "dpaster;0.1-3-1;x86;Summary"
        """
        log.info("=========== get package from package_id ======================")
        name, verString, archString, data =  pkpackage.get_package_from_id(package_id)
        trove = self.conary.request_query(name)
        if trove:
            return trove
        else:
            return cli.query(name)

    def _search_package( self, name ):
        for i,pkg in enumerate(self.packages):
            if pkg["trove"][0] == name:
                return i,pkg
        return None,None

    def _edit_package(self, trove, pkgDict, status):
        for i,pkg in enumerate(self.packages):
            if pkg["trove"] == trove:
                name,version, flavor = pkg.get("trove")
                self.packages[i] = dict(
                    trove = (name,version, flavor ),
                    pkgDict = pkgDict
                    )
                return i, self.packages[i]
   
    def _convert_package( self, trove , pkgDict ):
        return dict( 
                trove = trove ,
                metadata = pkgDict
            )

    def _add_package(self, trove, pkgDict):
        self.packages.append( self._convert_package(trove, pkgDict) )
        
    def _do_search(self, filters, searchlist, where = "name"):
        """
         searchlist(str)ist as the package for search like
         filters(str) as the filter
        """
        fltlist = filters
        if where != "name" and where != "details" and where != "group" and where!= "all":
            log.info("where %s" % where)
            self.error(ERROR_UNKNOWN, "DORK---- search where not found")

        log.debug((searchlist, where))
        log.info("||||||||||||||||||||||||||||searching  on cache... ")
        pkgList = self.xmlcache.search(searchlist, where )
        log.info("|||||||||||||||||||||||||||||1end searching on cache... ")

        if len(pkgList) > 0 :
            #for i in troveTupleList:
            #    log.info("FOUND!!!!!! %s " % i["name"] )
            log.info("FOUND (%s) elements " % len(pkgList) )
            for pkgDict in pkgList:
                self._add_package( ( pkgDict["name"], None, None), pkgDict )

            self._resolve_list( fltlist  )
        else:
            log.info("NOT FOUND %s " % searchlist )
            self.message(MESSAGE_COULD_NOT_FIND_PACKAGE,"search not found")
            #self.error(ERROR_INTERNAL_ERROR, "packagenotfound")


    def _get_update(self, applyList, cache=True):
        from conary.conaryclient.update import NoNewTrovesError,DepResolutionFailure
        self.allow_cancel(False)
        updJob = self.client.newUpdateJob()
        jobPath = self.xmlcache.checkCachedUpdateJob(applyList)
        if cache and jobPath:
            try:
                log.info("Using previously cached update job at %s" % (jobPath,))
                updJob.thaw(jobPath)
            except IOError, err:
                log.error("Failed to read update job at %s (error=%s)" % (jobPath, str(err)))
                updJob = None
        else:
Пример #2
0
class PackageKitConaryBackend(PackageKitBaseBackend):
    # Packages there require a reboot
    rebootpkgs = ("kernel", "glibc", "hal", "dbus")
    restartpkgs = ("PackageKit", "gnome-packagekit")

    packages = []
    #{{{   Packages structure
    """
    packages = {
        pkg_name: {
            'trove': ( name,version,flavor)
            'metadata': pkgDict,
        }
    }
    
    """

    #}}}
    #{{{ Init
    def __init__(self, args):
        PackageKitBaseBackend.__init__(self, args)

        # conary configurations
        conary = ConaryPk()
        self.cfg = conary.cfg
        self.client = conary.cli
        self.conary = conary
        self.callback = UpdateCallback(self, self.cfg)
        self.client.setUpdateCallback(self.callback)
        self.xmlcache = XMLCache()

    def _freezeData(self, version, flavor):
        frzVersion = version.freeze()
        frzFlavor = flavor.freeze()
        return ','.join([frzVersion, frzFlavor])

    def _thawData(self, frzVersion, frzFlavor):
        version = versions.ThawVersion(frzVersion)
        flavor = deps.ThawFlavor(frzFlavor)
        return version, flavor

    #}}}
    def _get_arch(self, flavor):
        return _get_arch(flavor)

    @ExceptionHandler
    def check_installed(self, troveTuple):
        log.info("============check installed =========")
        result = self.conary.query(troveTuple[0])
        if result:
            installed = INFO_INSTALLED
        else:
            installed = INFO_AVAILABLE
        return installed

    def get_package_id_new(self, pkg):

        name, version, flavor = pkg.get("trove")
        metadata = pkg.get("metadata")
        data = ""
        if metadata:
            if "shortDesc" in metadata:
                data = metadata['shortDesc'].decode("UTF")
                if data == "." or data == "":
                    data = name.replace("-", ' ').capitalize()
        return pkpackage.get_package_id(name, version.trailingRevision(),
                                        self._get_arch(flavor), data)

    @ExceptionHandler
    def get_package_id(self, name, versionObj, flavor):

        version = versionObj.trailingRevision()
        pkg = self.xmlcache.resolve(name)
        #pkg["shortDesc"] = "."
        arch = self._get_arch(flavor)
        #data = versionObj.asString() + "#"
        data = ""
        if pkg:
            if "shortDesc" in pkg:
                data = pkg['shortDesc'].decode("UTF")
                if data == "." or data == "":
                    data = name.replace("-", ' ').capitalize()

        return pkpackage.get_package_id(name, version, arch, data)

    @ExceptionHandler
    def get_package_from_id(self, package_id):
        """ package_id(string) =
        "dpaster;0.1-3-1;x86;Summary"
        """
        log.info(
            "=========== get package from package_id ======================")
        name, verString, archString, data = pkpackage.get_package_from_id(
            package_id)
        trove = self.conary.request_query(name)
        if trove:
            return trove
        else:
            return cli.query(name)

    def _search_package(self, name):
        for i, pkg in enumerate(self.packages):
            if pkg["trove"][0] == name:
                return i, pkg
        return None, None

    def _edit_package(self, trove, pkgDict, status):
        for i, pkg in enumerate(self.packages):
            if pkg["trove"] == trove:
                name, version, flavor = pkg.get("trove")
                self.packages[i] = dict(trove=(name, version, flavor),
                                        pkgDict=pkgDict)
                return i, self.packages[i]

    def _convert_package(self, trove, pkgDict):
        return dict(trove=trove, metadata=pkgDict)

    def _add_package(self, trove, pkgDict):
        self.packages.append(self._convert_package(trove, pkgDict))

    def _do_search(self, filters, searchlist, where="name"):
        """
         searchlist(str)ist as the package for search like
         filters(str) as the filter
        """
        fltlist = filters
        if where != "name" and where != "details" and where != "group" and where != "all":
            log.info("where %s" % where)
            self.error(ERROR_UNKNOWN, "DORK---- search where not found")

        log.debug((searchlist, where))
        log.info("||||||||||||||||||||||||||||searching  on cache... ")
        pkgList = self.xmlcache.search(searchlist, where)
        log.info("|||||||||||||||||||||||||||||1end searching on cache... ")

        if len(pkgList) > 0:
            #for i in troveTupleList:
            #    log.info("FOUND!!!!!! %s " % i["name"] )
            log.info("FOUND (%s) elements " % len(pkgList))
            for pkgDict in pkgList:
                self._add_package((pkgDict["name"], None, None), pkgDict)

            self._resolve_list(fltlist)
        else:
            log.info("NOT FOUND %s " % searchlist)
            self.message(MESSAGE_COULD_NOT_FIND_PACKAGE, "search not found")
            #self.error(ERROR_INTERNAL_ERROR, "packagenotfound")

    def _get_update(self, applyList, cache=True):
        from conary.conaryclient.update import NoNewTrovesError, DepResolutionFailure
        self.allow_cancel(False)
        updJob = self.client.newUpdateJob()
        jobPath = self.xmlcache.checkCachedUpdateJob(applyList)
        if cache and jobPath:
            try:
                log.info("Using previously cached update job at %s" %
                         (jobPath, ))
                updJob.thaw(jobPath)
            except IOError, err:
                log.error("Failed to read update job at %s (error=%s)" %
                          (jobPath, str(err)))
                updJob = None
        else: