#!/usr/bin/python -O # # $Header: $ # Authors: # Eldad Zack - Original application # Robin H. Johnson - SLOT and masking support # # earch: Gentoo last arch keyword checking tool, with SLOT and masking support # version 0.3 import sys import os import re import string import readline import getopt from output import * sys.path.insert(0, "/usr/lib/portage/pym") import portage version = '0.5' def earch_main(): # force to false opt_masking_reasons = False opt_hide_masked = False opt_help = False opt_version = False opt_slot = [] # process commandline try: (opts,args) = getopt.gnu_getopt(sys.argv[1:],'mhHvs:',['masking-reasons','help','hide-masked','version','slot=']) for optkey,optvalue in opts: if optkey == '-m' or optkey == '--masking-reasons': opt_masking_reasons = True if optkey == '-h' or optkey == '--help': opt_help = True if optkey == '-H' or optkey == '--hide-masked': opt_hide_masked = True if optkey == '-s' or optkey == '--slot': opt_slot = re.split(',',optvalue) if optkey == '-v' or optkey == '--version': opt_version = True except getopt.GetoptError: opt_help = True # don't hide masked packages if we are printing reasons if opt_masking_reasons: opt_hide_masked = False # do help if opt_help: earch_help() return # version output if opt_version: earch_version() return # main (ebuildlist,ebuilddata,archslotdict) = earch_data_generate(args) earch_data_output(ebuildlist,ebuilddata,archslotdict,show_masking_reason=opt_masking_reasons,hide_masked=opt_hide_masked,slots=opt_slot) def earch_version(): print 'earch %s' % (version) def earch_help(): earch_version print 'Gentoo last arch keyword checking tool, with SLOT and masking support' print print 'Usage:' print 'earch [opts] [CP]' print 'If CP is omitted, the current directory is used.' print print 'Options:' print '-m|--masking-reason' print ' For all masked versions, print masking reason. Disables other output.' print print '-H|--hide-masked' print ' Exclude all masked versions from output.' print print '-s|--slot ' print ' SLOT values to provide output for, seperated by commas.' print print '-h|--help' print ' This help page.' print print 'Explaination of output:' print '# earch [$CATEGORY/$PN]' print '$PF[$SLOT]: $KEYWORDS' print 'If a specific version is masked, a (M) will preceed the keywords.' def earch_data_generate(args): portdir = portage.settings["PORTDIR"] portdb = portage.portdbapi(portdir) archslotdict = {} ebuildlist = [] ebuilddata = {} if len(args) < 1: workdir = "." else: workdir = portdir + "/" + args[0] try: os.chdir(workdir) except: print red("!!!" + " Can't find " + workdir) return cp_path = os.path.abspath(workdir) cp = re.sub(portdir+'/?','', cp_path, count=1) #print cp cat = re.split('/',cp)[0] #print c for file in os.listdir(workdir): if re.search("\.ebuild$",file): s = re.split("\.ebuild$",file)[0] ebuildlist.append(s) ebuildlist.sort(lambda x,y: portage.pkgcmp(portage.pkgsplit(x),portage.pkgsplit(y))) for pkg in ebuildlist: cpv = cat+'/'+pkg aux = portdb.aux_get(cpv,['SLOT','KEYWORDS']) slot = aux[0] keywords = re.split(' ',aux[1]) masking = portage.getmaskingstatus(cpv) # store this for usage later ebuilddata[pkg] = {'SLOT':slot, 'KEYWORDS':keywords, 'MASKING':masking} # ensure the second level tree exists try: archslotdict[slot] except KeyError: archslotdict[slot] = {} # now actually populate the second level tree if len(masking) > 0: prefix = 'M/' else: prefix = '' for arch in keywords: archslotdict[slot][prefix+arch] = pkg return (ebuildlist,ebuilddata,archslotdict) def earch_data_output(ebuildlist,ebuilddata,archslotdict,show_masking_reason=False,hide_masked=False,slots=[]): for pkg in ebuildlist: slot = ebuilddata[pkg]['SLOT'] masking = ebuilddata[pkg]['MASKING'] is_masked = len(masking) > 0 if is_masked: m = red('(M) ') else: m = '' if hide_masked and is_masked: continue if len(slots) > 0 and slot not in slots: continue print '%s[%s]: %s'%(white(pkg),yellow(slot),m), # print masking reason only if show_masking_reason: print '%s' % (string.join(masking,', ')) continue for value,key in archslotdict[slot].iteritems(): value = re.sub('M/','',value) if (key == pkg): if re.search("^-",value): print red(value), elif re.search("^~",value): print blue(value), else: print green(value), print if __name__ == "__main__": earch_main()