diff options
author | Alexander Bersenev <bay@hackerdom.ru> | 2011-08-16 12:29:44 +0000 |
---|---|---|
committer | Alexander Bersenev <bay@hackerdom.ru> | 2011-08-16 12:29:44 +0000 |
commit | 35e1dc34db0539d6a6478209bdc8caf00d82bb7a (patch) | |
tree | 0151e11221be67f9bf381c8d62cfd409f9511725 /src | |
parent | allowing all dependencies of portage package (diff) | |
download | autodep-35e1dc34db0539d6a6478209bdc8caf00d82bb7a.tar.gz autodep-35e1dc34db0539d6a6478209bdc8caf00d82bb7a.tar.bz2 autodep-35e1dc34db0539d6a6478209bdc8caf00d82bb7a.zip |
changes in output
Diffstat (limited to 'src')
-rwxr-xr-x | src/autodep/autodep | 123 | ||||
-rw-r--r-- | src/autodep/helpers/events_analysis.py | 2 | ||||
-rw-r--r-- | src/autodep/package_utils/portage_misc_functions.py | 54 | ||||
-rw-r--r-- | src/autodep/tests/all_tests.py | 2 |
4 files changed, 126 insertions, 55 deletions
diff --git a/src/autodep/autodep b/src/autodep/autodep index 751dca7..1152180 100755 --- a/src/autodep/autodep +++ b/src/autodep/autodep @@ -41,7 +41,8 @@ def parse_args(): const="fusefs", help="use fuse logging approach(slow, but reliable)") args_parser.set_defaults(approach="hooklib") - args_parser.epilog="Example: %s -b lsof,cowsay emerge bash" % (os.path.basename(sys.argv[0])) + args_parser.epilog="Example: %s -blockpkgs lsof,cowsay emerge bash" % ( + os.path.basename(sys.argv[0])) args_parser.disable_interspersed_args() (options, args) = args_parser.parse_args() if len(args)==0: @@ -56,20 +57,27 @@ def init_environment(): return portage_api, system_packages -def init_runtime_vars(options,args): +def init_runtime_vars(portage_api, options,args): runtime_vars={} # This is here mainly for grouping. We are trying to # get as much data about an environment as possible runtime_vars["starttime"]=int(time.time()) # trivial check for emerge proccess - if args[0]=="emerge": + if os.path.basename(args[0])=="emerge": runtime_vars["is_emerge"]=True emergeaction ,emergeopts, emergefiles=portage_api.parse_emerge_args(args[1:]) runtime_vars["raw_emerge_parameters"]=args[1:] runtime_vars["emerge_parameters"]=(emergeaction ,emergeopts, emergefiles) + runtime_vars["mergelist"]=portage_api.get_merge_list( + runtime_vars["raw_emerge_parameters"]) + if len(emergefiles)>1: print "Please, install packages one by one to get more accurate reports" + + if len(runtime_vars["mergelist"])==0: + print "No packages will be installed or there is an error with counting" + else: runtime_vars["is_emerge"]=False @@ -94,9 +102,9 @@ def get_filter_function(options,system_packages,portage_api): def filter(eventname,filename,stage): return not filename in files_to_block return filter - elif options.strict_block and options.packages: - print "You can't use --block and --blockpkgs options togeter\n" - exit(1) + #elif options.strict_block and options.packages: + #print "You can't use --block and --blockpkgs options togeter\n" + #exit(1) elif options.strict_block: # this option is very strict # because blocking logic is complex print "Building a list of files to block. This may take some time" @@ -111,16 +119,15 @@ def get_filter_function(options,system_packages,portage_api): if len(emergefiles)>1: print "You can't install several packages with option -b" exit(1) - mergelist=portage_api.get_merge_list(runtime_vars["raw_emerge_parameters"]) - if len(mergelist)!=1: - print "You can't install several packages with option -b" - print "Emerge tried to install several packages: %s" % mergelist - print "You can force emerge to merge a package without any other " \ - "packages with emerge --nodeps option or you can install these " \ + if len(runtime_vars["mergelist"])!=1: + print "You can't install several packages with option -b." + print "Emerge tried to install several packages: %s. " % runtime_vars["mergelist"] + print "You can force emerge to merge a package wit hout any other "\ + "packages with emerge --nodeps option or you can install these "\ "packages first" exit(1) - pkg=mergelist[0] + pkg=runtime_vars["mergelist"][0] depslist=list(portage_api.get_deps(pkg)) allowedpkgs+=depslist else: @@ -155,7 +162,7 @@ def get_filter_function(options,system_packages,portage_api): portage_api, system_packages=init_environment() options,args=parse_args() -runtime_vars=init_runtime_vars(options,args) +runtime_vars=init_runtime_vars(portage_api,options,args) color_printer=colorize_output.color_printer(not options.nocolor) @@ -168,24 +175,35 @@ print "Program finished, analyzing dependencies" if runtime_vars["is_emerge"]: # try to get information about packages merged sucessfully - try: - pkgs=portage_log_parser.get_list_of_merged_packages( - runtime_vars["starttime"],runtime_vars["endtime"] - ) - if len(pkgs) > 1: - print "Several packages were installed. The report will be inaccurate" - elif len(pkgs)==0: - print "None packages have been installed sucessfully. The report will be inaccurate" - runtime_vars["pkgs_installed"]=pkgs - runtime_vars["deps_buildtime"]=[] - runtime_vars["deps_all"]=[] - for pkg in pkgs: - runtime_vars["deps_buildtime"]+=portage_api.get_deps(pkg,["DEPEND"]) - runtime_vars["deps_all"]+=portage_api.get_deps(pkg,["DEPEND","RDEPEND"]) - except: - print "Non-critical error while parsing logfile of emerge" - runtime_vars["is_emerge"]=False # shutting down all emerge handling logic - pass + #try: + runtime_vars["deps_all"]=set([]) + runtime_vars["deps_buildtime"]=set([]) + for pkg in runtime_vars["mergelist"]: + runtime_vars["deps_all"]=runtime_vars["deps_all"].union( + portage_api.get_deps(pkg,["DEPEND", "RDEPEND"])) + runtime_vars["deps_buildtime"]=runtime_vars["deps_buildtime"].union( + portage_api.get_dep(pkg,["DEPEND"])) + + runtime_vars["deps_portage"]=portage_api.get_deps('portage',["DEPEND", "RDEPEND"]) + + + #pkgs=portage_log_parser.get_list_of_merged_packages( + # runtime_vars["starttime"],runtime_vars["endtime"] + # ) + #if len(pkgs) > 1: + # print "Several packages were installed. The report will be inaccurate" + #elif len(pkgs)==0: + # print "None packages have been installed sucessfully. The report will be inaccurate" + #runtime_vars["pkgs_installed"]=pkgs + #runtime_vars["deps_buildtime"]=[] + #runtime_vars["deps_all"]=[] + #for pkg in pkgs: + # runtime_vars["deps_buildtime"]+=portage_api.get_deps(pkg,["DEPEND"]) + # runtime_vars["deps_all"]+=portage_api.get_deps(pkg,["DEPEND","RDEPEND"]) + #except: + #print "Non-critical error while parsing logfile of emerge" + #runtime_vars["is_emerge"]=False # shutting down all emerge handling logic + #pass # get unique filenames filenames=set() @@ -259,8 +277,9 @@ for package in sorted(packagesinfo): if package in system_packages and not options.verbose: continue - is_attention_pkg=runtime_vars["is_emerge"] and package not in runtime_vars["deps_all"] - + is_pkg_in_dep=runtime_vars["is_emerge"] and package in runtime_vars["deps_all"] + is_pkg_in_portage_dep=runtime_vars["is_emerge"] and package in runtime_vars["deps_portage"] + is_pkg_python="dev-lang/python" in package stages=[] for stage in sorted(packagesinfo[package].keys(), key=stagesorder.get): @@ -274,13 +293,29 @@ for package in sorted(packagesinfo): if len(packagesinfo[package][stage][filename]["found"])!=0: was_readed,was_writed=packagesinfo[package][stage][filename]["found"] if not filename in filenames: - filenames[filename]=[was_readed,was_writed] + filenames[filename]=['ok',was_readed,was_writed] + else: + status, old_was_readed, old_was_writed=filenames[filename] + filenames[filename]=[ + 'ok',old_was_readed | was_readed, old_was_writed | was_writed + ] + if len(packagesinfo[package][stage][filename]["notfound"])!=0: + was_notfound,was_blocked=packagesinfo[package][stage][filename]["notfound"] + if not filename in filenames: + filenames[filename]=['err',was_notfound,was_blocked] else: - old_was_readed, old_was_writed=filenames[filename] - filenames[filename]=[old_was_readed | was_readed, old_was_writed | was_writed ] + status, old_was_notfound, old_was_blocked=filenames[filename] + filenames[filename]=[ + 'err',old_was_notfound | was_notfound, old_was_blocked | was_blocked + ] + - if not is_attention_pkg: + if not runtime_vars["is_emerge"] or is_pkg_in_dep: color_printer.printmsg("text","[OK]") + elif is_pkg_in_portage_dep: + color_printer.printmsg("text","[PORTAGE DEP]") + elif is_pkg_python: + color_printer.printmsg("text","[INTERPRETER]") elif not events_analysis.is_package_useful(package,stages,filenames.keys()): color_printer.printmsg("text","[LIKELY OK]") else: @@ -292,10 +327,14 @@ for package in sorted(packagesinfo): # this is here for readability action={ - (False,False):"accessed", - (True,False):"readed", - (False,True):"writed", - (True,True):"readed and writed" + ('ok',False,False):"accessed", + ('ok',True,False):"readed", + ('ok',False,True):"writed", + ('ok',True,True):"readed and writed", + ('err',False,False):"other error", + ('err',True,False):"not found", + ('err',False,True):"blocked", + ('err',True,True):"not found and blocked" } filescounter=0 diff --git a/src/autodep/helpers/events_analysis.py b/src/autodep/helpers/events_analysis.py index ed5792b..eba903a 100644 --- a/src/autodep/helpers/events_analysis.py +++ b/src/autodep/helpers/events_analysis.py @@ -32,7 +32,7 @@ def is_package_useful(pkg,stages,files): continue # test 1: package is not useful if all files are *.desktop or *.xml or *.m4 - if not (f.endswith(".desktop") or f.endswith(".xml") or f.endswith(".m4")): + if not (f.endswith(".desktop") or f.endswith(".xml") or f.endswith(".m4") or f.endswith(".pc")): break else: return False # we get here if cycle ends not with break diff --git a/src/autodep/package_utils/portage_misc_functions.py b/src/autodep/package_utils/portage_misc_functions.py index 6afe2c3..95c4ce4 100644 --- a/src/autodep/package_utils/portage_misc_functions.py +++ b/src/autodep/package_utils/portage_misc_functions.py @@ -10,9 +10,9 @@ from _emerge.main import parse_opts # TODO: check if actions always here try: - from _emerge import actions + from _emerge import actions, Package from _emerge.create_depgraph_params import create_depgraph_params - from _emerge.depgraph import backtrack_depgraph, depgraph + from _emerge.depgraph import backtrack_depgraph, resume_depgraph, depgraph except ImportError, Err: # non-critical, just print warning(TODO: strerr) print "Error while loading modules: %s" % Err.message @@ -20,8 +20,13 @@ class portage_api: """ class for accessing the portage api """ def __init__(self): """ test """ - self.settings=portage.config(clone=portage.settings) - self.vartree=portage.db[portage.root]['vartree'] + settings,trees,mtimedb=actions.load_emerge_config() + + #import pdb; pdb.set_trace() + self.settings=settings + self.trees=trees + self.mtimedb=mtimedb + self.vartree=trees[portage.root]['vartree'] self.vardb=self.vartree.dbapi self.portdb=portage.portdb self.metadata_keys = [k for k in portage.auxdbkeys if not k.startswith("UNUSED_")] @@ -39,6 +44,7 @@ class portage_api: except: return '' + # trying to repeat action_build(...) logic in _emerge/actions.py def get_merge_list(self,emergeargs): """ Gets list of packages that emerge with emergeargs-arguments will merge @@ -48,20 +54,46 @@ class portage_api: :param emergeargs: list of raw args of emerge, for example, ['-1','bash'] """ - + try: - settings,trees,mtimedb=actions.load_emerge_config() action, opts, files = parse_opts(emergeargs, silent=True) + + resume = False + if "--resume" in opts and \ + ("resume" in self.mtimedb or "resume_backup" in self.mtimedb): + resume = True + if "resume" not in self.mtimedb: + self.mtimedb["resume"] = self.mtimedb["resume_backup"] + # "opts" is a list for backward compatibility. + resume_opts = self.mtimedb["resume"].get("myopts", []) + if isinstance(resume_opts, list): + resume_opts = dict((k,True) for k in resume_opts) + for opt in ("--ask", "--color", "--skipfirst", "--tree"): + resume_opts.pop(opt, None) + + # Current options always override resume_opts. + resume_opts.update(opts) + opts.clear() + opts.update(resume_opts) + + params=create_depgraph_params(opts,action) - success, mydepgraph, favorites = backtrack_depgraph( - settings, trees, opts, params, action, files, None) - if not success: - return [] + if resume: + success, mydepgraph, dropped_tasks = resume_depgraph( + self.settings, self.trees, self.mtimedb, opts, params, None) + if not success: + return [] + else: + success, mydepgraph, favorites = backtrack_depgraph( + self.settings, self.trees, opts, params, action, files, None) + if not success: + return [] ret=[] for pkg in mydepgraph.altlist(): - ret.append(pkg.cpv) + if type(pkg) is Package.Package: + ret.append(pkg.cpv) return ret except: diff --git a/src/autodep/tests/all_tests.py b/src/autodep/tests/all_tests.py index 3542ca8..0d52de7 100644 --- a/src/autodep/tests/all_tests.py +++ b/src/autodep/tests/all_tests.py @@ -2,7 +2,7 @@ import glob import unittest # change it if you don't want get all tests runned -testsglob='tests/test_*.py' +testsglob='tests/test_p*.py' def create_test_suite(): test_file_strings = glob.glob(testsglob) |