From 02d0a1d042b024a991561207ec6985df06ef660a Mon Sep 17 00:00:00 2001 From: Tim Lauridsen Date: Fri, 24 Aug 2007 11:21:27 +0100 Subject: [PATCH] Implemented yum-search-details --- helpers/packagekit.py | 11 +++++++++-- helpers/yum-search-details.py | 34 ++++------------------------------ helpers/yumBackend.py | 29 +++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/helpers/packagekit.py b/helpers/packagekit.py index aae63aa00..7e7a36e18 100644 --- a/helpers/packagekit.py +++ b/helpers/packagekit.py @@ -117,9 +117,16 @@ class PackageKitBaseBackend: # Backend Action Methods # - def search_name(self,opt,keys): + def search_name(self,opt,key): ''' - Implement the {backend}-search-nam functionality + Implement the {backend}-search-name functionality + Needed to be implemented in a sub class + ''' + self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend") + + def search_details(self,opt,key): + ''' + Implement the {backend}-search-details functionality Needed to be implemented in a sub class ''' self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend") diff --git a/helpers/yum-search-details.py b/helpers/yum-search-details.py index 01a3604b8..a3e9723bb 100755 --- a/helpers/yum-search-details.py +++ b/helpers/yum-search-details.py @@ -10,40 +10,14 @@ # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. -import yum import sys -my = yum.YumBase() -#my.doConfigSetup() -my.conf.cache = 1 - options = sys.argv[1] searchterms = sys.argv[2] -searchlist = ['name', 'summary', 'description', 'group'] -res = my.searchGenerator(searchlist, [searchterms]) +from yumBackend import PackageKitYumBackend -count = 1 -for (pkg,values) in res: - if count > 100: - break - count+=1 - installed = '0' - - # are we installed? - if my.rpmdb.installed(pkg.name): - installed = '1' - - # do we print to stdout? - do_print = 0; - if options == 'installed' and installed == '1': - do_print = 1 - elif options == 'available' and installed == '0': - do_print = 1 - elif options == 'all': - do_print = 1 - - # print in correct format - if do_print == 1: - print "package\t%s\t%s\t%s" % (installed, pkg.name, pkg.summary) +backend = PackageKitYumBackend(sys.argv[1:]) +backend.search_details(options,searchterms) +sys.exit(1) diff --git a/helpers/yumBackend.py b/helpers/yumBackend.py index b2205fdab..f8cd45cfa 100644 --- a/helpers/yumBackend.py +++ b/helpers/yumBackend.py @@ -30,14 +30,15 @@ class PackageKitYumBackend(PackageKitBaseBackend): PackageKitBaseBackend.__init__(self,args) self.yumbase = yum.YumBase() - def search_name(self,opt,keys): + def _do_search(self,searchlist,opt,key): ''' - Implement the {backend}-search-nam functionality - Needed to be implemented in a sub class + Search for yum packages + @param searchlist: The yum package fields to search in + @param opt: package types to search (all,installed,available) + @param key: key to seach for ''' self.yumbase.conf.cache = 1 # Only look in cache. - searchlist = ['name'] - res = self.yumbase.searchGenerator(searchlist, [keys]) + res = self.yumbase.searchGenerator(searchlist, [key]) count = 1 for (pkg,values) in res: @@ -64,8 +65,24 @@ class PackageKitYumBackend(PackageKitBaseBackend): if do_print == 1: id = self.get_package_id(pkg.name, pkg.version, pkg.arch, pkg.repo) self.package(id,installed, pkg.summary) - + def search_name(self,opt,key): + ''' + Implement the {backend}-search-nam functionality + Needed to be implemented in a sub class + ''' + searchlist = ['name'] + self._do_search(searchlist, opt, key) + + def search_details(self,opt,key): + ''' + Implement the {backend}-search-details functionality + Needed to be implemented in a sub class + ''' + searchlist = ['name', 'summary', 'description', 'group'] + self._do_search(searchlist, opt, key) + + def get_deps(self,package): ''' Implement the {backend}-get-deps functionality