#!/usr/bin/python -tt import sys sys.path.insert(0,'/usr/share/yum-cli') import yum import yum.comps from yum.misc import setup_locale, to_xml from yum.i18n import to_unicode from utils import YumUtilBase class AppFinder(YumUtilBase): NAME= 'appfinder' VERSION = '1.0' USAGE = 'appfinder [options] [package globs]' def __init__(self): YumUtilBase.__init__(self, AppFinder.NAME, AppFinder.VERSION, AppFinder.USAGE) #self.logger = logging.getLogger("yum.verbose.cli.appfinder") # Add util commandline options to the yum-cli ones if hasattr(self, 'getOptionGroup'): self.optparser_grp = self.getOptionGroup() else: self.optparser_grp = self.optparser self.optparser_grp.add_option("--output-to=", default='AppMarket.xml', dest="destfile", help='Do not complete the transaction just clean up transaction journals') self.main() def main(self): # Parse the commandline option and setup the basics. opts = self.doUtilConfigSetup() mycomps = yum.comps.Comps() apppkgs = [] apppkgs.extend(self.pkgSack.searchFiles('*.desktop')) # uncomment to include all pkgs which have a file in /usr/bin :) #apppkgs.extend(self.pkgSack.searchFiles('/usr/bin/*')) sack = yum.packageSack.ListPackageSack(yum.misc.unique(apppkgs)) for pkg in sorted(sack.returnNewestByNameArch()): app = yum.comps.Group() app.groupid = pkg.name app.name = app.groupid app.description = to_xml(pkg.summary + '\n' + pkg.description) app.mandatory_packages[pkg.name] = 1 mycomps.add_group(app) fo = open(opts.destfile, 'w') fo.write(mycomps.xml()) fo.close() print 'outputted to %s' % opts.destfile if __name__ == '__main__': setup_locale() util = AppFinder()