Implemented yum-search-details

This commit is contained in:
Tim Lauridsen 2007-08-24 11:21:27 +01:00 committed by Richard Hughes
parent 19e62712f8
commit 02d0a1d042
3 changed files with 36 additions and 38 deletions

View File

@ -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")

View File

@ -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)

View File

@ -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