#!/usr/bin/env python import optparse import os import sys import portage def get_src_uri_set(): distfiles = set() portdb = portage.portdb for cp in portdb.cp_all(): for cpv in portdb.cp_list(cp): distfiles.update(portdb.getFetchMap(cpv)) return distfiles def get_whitelists(whitelist_dir): whilelists = {} for whitelist_name in os.listdir(whitelist_dir): if whitelist_name[:1] == '.': continue p = os.path.join(whitelist_dir, whitelist_name) if not os.path.isfile(p): continue contents = set() for line in open(p, 'r'): filename = line.strip() if not filename or filename[:1] == "#": continue contents.add(filename) if contents: whilelists[whitelist_name] = contents return whilelists def distfile_whilelist_analysis(whitelist_dir): src_uri_set = get_src_uri_set() whitelists = get_whitelists(whitelist_dir) for whitelist_name in sorted(whitelists): whilelist_only = set() for filename in whitelists[whitelist_name]: if filename not in src_uri_set: whilelist_only.add(filename) if whilelist_only: sys.stdout.write("%s\t" % whitelist_name) sys.stdout.write("\t".join(sorted(whilelist_only))) sys.stdout.write("\n") return os.EX_OK if __name__ == "__main__": description = "Generate a list of files that are ONLY " + \ "present because they are whitelisted (and not " + \ "pulled in by anything in the current tree), and " + \ "which whitelist they are in." usage = "usage: %s PORTDIR WHITELIST_DIR" % \ os.path.basename(sys.argv[0]) parser = optparse.OptionParser(description=description, usage=usage) options, args = parser.parse_args() if len(args) != 2: parser.error('expected 2 args, got %d' % len(args)) for x in args: if not os.path.isdir(x): parser.error("%s is not a directory" % x) portdir, whitelist_dir = args os.environ['PORTDIR'] = portdir os.environ['PORTDIR_OVERLAY'] = '' retval = distfile_whilelist_analysis(whitelist_dir) sys.exit(retval)