#!/usr/bin/python2.2 # # useupdate - list packages that would be affected by USE changes that have # happened since they were built # # Copyright (c) Chris Willis-Ford # This program is distributed under the terms of the GPL version 2. # # Note: This is my first Python program, so don't trust it to be 100% perfect # or optimal. It *was* written in one night, after all... :P from os.path import walk, normpath, split from portage import pkgsplit, settings from string import join installRoot = "/var/db/pkg" maxRead = 1024*1024 # Read no more than 1MB for safety def undupe(list): unique = [] for word in list: if not ( word in unique ): unique.append(word) return unique # Normalize the global USE settings first use = join(undupe(settings["USE"].strip().split())) # Compare two USE strings, ignoring order and duplicates. # Return None if there are no differences that would affect a recompile # Return differences if there are any def whatchanged(old,new): if (old == new): return None newsplit=undupe(new.split()) oldsplit=undupe(old.split()) for word in oldsplit[:]: if ( word in newsplit ): # Setting has not changed oldsplit.remove(word) newsplit.remove(word) else: if ( word[0] == '-' ): # Don't care if it was off before oldsplit.remove(word) else: newsplit.append('-'+word) # It was on, now it's not. Notice this. diffs=join(newsplit) if ( diffs ): return diffs return None def affects(usechanges, rdepfile): changes=usechanges.split() rdep=rdepfile.split() important=[] for word in rdep: if ( word[-1] == '?' ): if ( word[:-1] in changes ): important.append(word[:-1]) if ( '-'+word[:-1] in changes ): important.append('-'+word[:-1]) return join(important) def visit(dummy, dirname, files): for file in files: if (file == 'USE'): f=open(dirname+'/USE') thisuse=f.readline(maxRead).strip() f.close() f=open(dirname+'/RDEPEND') thisrdep=f.read(maxRead) f.close() (cat, fullname)=split(normpath(dirname)) cat=split(cat)[1] (name,ver,rev)=pkgsplit(fullname) changes=whatchanged(thisuse,use) if ( changes ): important=affects(changes, thisrdep) if ( important ): print cat + '/' + name + ' : ' + important if __name__ == '__main__': import sys if (len(sys.argv) != 1): print 'Usage: useupdate' sys.exit(1) walk(installRoot, visit, "")