aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Bersenev <bay@hackerdom.ru>2011-09-24 01:50:12 +0000
committerAlexander Bersenev <bay@hackerdom.ru>2011-09-24 01:50:12 +0000
commit8f102b8a531973df8bb1239f9a054386e0b9aead (patch)
tree0e57016e117e5cc751c819d2425a923d01ecf134 /src
parentunicode fixes (diff)
downloadautodep-8f102b8a531973df8bb1239f9a054386e0b9aead.tar.gz
autodep-8f102b8a531973df8bb1239f9a054386e0b9aead.tar.bz2
autodep-8f102b8a531973df8bb1239f9a054386e0b9aead.zip
python3 fixes and indenting
Diffstat (limited to 'src')
-rwxr-xr-xsrc/autodep/autodep702
-rw-r--r--src/autodep/logfs/logger_hooklib.py2
-rw-r--r--src/autodep/package_utils/portage_utils.py20
3 files changed, 367 insertions, 357 deletions
diff --git a/src/autodep/autodep b/src/autodep/autodep
index 8d22e00..c0b9172 100755
--- a/src/autodep/autodep
+++ b/src/autodep/autodep
@@ -11,190 +11,190 @@ from helpers import colorize_output, events_analysis
from package_utils import portage_utils, portage_misc_functions, portage_log_parser
def parse_args():
- """
- This function parses an input args
- It dies if bad args passed
- """
-
- args_parser=optparse.OptionParser("%prog [options] <command>")
- args_parser.add_option("-b","--block",action="store_true",
- dest="strict_block", default="",
- help="strict mode: Deny all access to files from non-dependency packages.")
- args_parser.add_option("--blockpkgs",action="store", type="string",
- dest="packages", default="",
- help="Block access to files from these packages.")
- args_parser.add_option("-f","--files", action="store_true", dest="show_files",
- default=False, help="Show all files, accessed and missing ( not founded).")
- args_parser.add_option("-v","--verbose", action="store_true", dest="verbose",
- default=False, help="Show non-important packages, "
- "unknown package and unknown stage")
- args_parser.add_option("-n","--numfiles",action="store", type="int",
- dest="numfiles",
- default=10,
- help="Maximum number of files from each package to show (default is 10)")
- args_parser.add_option("-C","--nocolor",action="store_true", dest="nocolor",
- default=False, help="Don't colorize output")
-
- args_parser.add_option("--hooklib",action="store_const", dest="approach",
- const="hooklib", help="Use ld_preload logging approach (default)")
- args_parser.add_option("--fusefs",action="store_const", dest="approach",
- const="fusefs", help="Use FUSE logging approach (slow, but reliable)")
- args_parser.set_defaults(approach="hooklib")
-
- 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:
- args_parser.print_help()
- exit(1)
-
- return options,args
+ """
+ This function parses an input args
+ It dies if bad args passed
+ """
+
+ args_parser=optparse.OptionParser("%prog [options] <command>")
+ args_parser.add_option("-b","--block",action="store_true",
+ dest="strict_block", default="",
+ help="strict mode: Deny all access to files from non-dependency packages.")
+ args_parser.add_option("--blockpkgs",action="store", type="string",
+ dest="packages", default="",
+ help="Block access to files from these packages.")
+ args_parser.add_option("-f","--files", action="store_true", dest="show_files",
+ default=False, help="Show all files, accessed and missing ( not founded).")
+ args_parser.add_option("-v","--verbose", action="store_true", dest="verbose",
+ default=False, help="Show non-important packages, "
+ "unknown package and unknown stage")
+ args_parser.add_option("-n","--numfiles",action="store", type="int",
+ dest="numfiles",
+ default=10,
+ help="Maximum number of files from each package to show (default is 10)")
+ args_parser.add_option("-C","--nocolor",action="store_true", dest="nocolor",
+ default=False, help="Don't colorize output")
+
+ args_parser.add_option("--hooklib",action="store_const", dest="approach",
+ const="hooklib", help="Use ld_preload logging approach (default)")
+ args_parser.add_option("--fusefs",action="store_const", dest="approach",
+ const="fusefs", help="Use FUSE logging approach (slow, but reliable)")
+ args_parser.set_defaults(approach="hooklib")
+
+ 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:
+ args_parser.print_help()
+ exit(1)
+
+ return options,args
def init_environment():
- portage_api=portage_misc_functions.portage_api()
- system_packages = portage_api.get_system_packages_list()
- system_deps = portage_api.get_system_packages_rdeps()
+ portage_api=portage_misc_functions.portage_api()
+ system_packages = portage_api.get_system_packages_list()
+ system_deps = portage_api.get_system_packages_rdeps()
- return portage_api, system_packages, system_deps
+ return portage_api, system_packages, system_deps
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 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
- runtime_vars["deps_all"]=[]
-
- # find a full path to the program
- program_path=None
- program_name=args[0]
- def is_exe(fpath):
- return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
-
- fpath, fname = os.path.split(program_name)
- if fpath:
- if is_exe(program_name):
- program_path=program_name
+ 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 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:
- for path in os.environ["PATH"].split(os.pathsep):
- exe_file = os.path.join(path, program_name)
- if is_exe(exe_file):
- program_path=exe_file
-
- if program_path==None:
- print("Failed to find the program %s. Check its existance."
- % program_name)
- exit(1)
+ runtime_vars["is_emerge"]=False
+ runtime_vars["deps_all"]=[]
+
+ # find a full path to the program
+ program_path=None
+ program_name=args[0]
+ def is_exe(fpath):
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+ fpath, fname = os.path.split(program_name)
+ if fpath:
+ if is_exe(program_name):
+ program_path=program_name
+ else:
+ for path in os.environ["PATH"].split(os.pathsep):
+ exe_file = os.path.join(path, program_name)
+ if is_exe(exe_file):
+ program_path=exe_file
+
+ if program_path==None:
+ print("Failed to find the program %s. Check its existance."
+ % program_name)
+ exit(1)
- runtime_vars["full_path"]=program_path
+ runtime_vars["full_path"]=program_path
- return runtime_vars
+ return runtime_vars
def get_filter_function(options,args,system_packages,system_deps,portage_api):
- # handling --block
- # exits if package name is bad
- if not options.packages and not options.strict_block:
- return lambda eventname,filename,stage: True
- elif not options.strict_block and options.packages:
- packages=options.packages.split(",")
- files_to_block=[]
- for package in packages:
- files_in_package=portage_utils.getfilesbypackage(package)
- if len(files_in_package)==0:
- print "Bad package name: %s. Exiting" % package
- exit(1)
- files_to_block+=files_in_package
- files_to_block={}.fromkeys(files_to_block)
- # new filter function
- 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: # this option is very strict
- # because blocking logic is complex
-
- print "Building a list of files to block. This may take some time"
- # we get list of all files and substract list of allowed files from it
- allfiles=portage_utils.get_all_packages_files()
- allowedpkgs=[]
- allowedpkgs+=system_packages
- allowedpkgs+=system_deps
-
- if runtime_vars["is_emerge"]: # blocking logic for emerge
- print "Notice: you can use emerge_strict command instead of autodep emerge."
- print "Using this command allows to build any number of a packages.\n"
-
- # including all dependencies of portage
- allowedpkgs+=list(portage_api.get_dep("portage",["RDEPEND"]))
- (emergeaction ,emergeopts, emergefiles)=runtime_vars["emerge_parameters"]
- if len(emergefiles)>1:
- print "You can't install several packages with option -b"
- exit(1)
- 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 without any other "\
- "packages with emerge --nodeps option or you can install these "\
- "packages first"
-
- exit(1)
- pkg=runtime_vars["mergelist"][0]
- depslist=list(portage_api.get_deps_for_package_building(pkg))
- allowedpkgs+=depslist
- # manually add all python interpreters to this list
- allowedpkgs+=["dev-lang/python"]
- else:
- program_path=runtime_vars["full_path"]
- file_to_package=portage_utils.getpackagesbyfiles([program_path])
- if program_path not in file_to_package:
- print "Failed to find a package for %s" % program_path
- else:
- allowedpkgs+=[file_to_package[program_path]]
- depslist=list(
- portage_api.get_deps(file_to_package[program_path],["RDEPEND"]))
- allowedpkgs+=depslist
+ # handling --block
+ # exits if package name is bad
+ if not options.packages and not options.strict_block:
+ return lambda eventname,filename,stage: True
+ elif not options.strict_block and options.packages:
+ packages=options.packages.split(",")
+ files_to_block=[]
+ for package in packages:
+ files_in_package=portage_utils.getfilesbypackage(package)
+ if len(files_in_package)==0:
+ print("Bad package name: %s. Exiting" % package)
+ exit(1)
+ files_to_block+=files_in_package
+ files_to_block={}.fromkeys(files_to_block)
+ # new filter function
+ 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: # this option is very strict
+ # because blocking logic is complex
+
+ print("Building a list of files to block. This may take some time")
+ # we get list of all files and substract list of allowed files from it
+ allfiles=portage_utils.get_all_packages_files()
+ allowedpkgs=[]
+ allowedpkgs+=system_packages
+ allowedpkgs+=system_deps
- # Do not forget to add self
- allowedpkgs+=["app-portage/autodep"]
- # remember the allowedpkgs in deps_all. It is bad to do it here.
- runtime_vars["deps_all"]=allowedpkgs
-
- allowedfiles=[]
- for pkg in allowedpkgs:
- allowedfiles+=portage_utils.getfilesbypackage(pkg)
-
- allowedfiles=set(allowedfiles)
-
- deniedfiles=allfiles-allowedfiles
-
- print "The list size is about %dM" % (int(sys.getsizeof(deniedfiles))/1024/1024)
- def filter(eventname,filename,stage):
- if filename in deniedfiles:
- return False
- return True
- return filter
+ if runtime_vars["is_emerge"]: # blocking logic for emerge
+ print("Notice: you can use emerge_strict command instead of autodep emerge.")
+ print("Using this command allows to build any number of a packages.\n")
+
+ # including all dependencies of portage
+ allowedpkgs+=list(portage_api.get_dep("portage",["RDEPEND"]))
+ (emergeaction ,emergeopts, emergefiles)=runtime_vars["emerge_parameters"]
+ if len(emergefiles)>1:
+ print("You can't install several packages with option -b")
+ exit(1)
+ 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 without any other "\
+ "packages with emerge --nodeps option or you can install these "\
+ "packages first")
+
+ exit(1)
+ pkg=runtime_vars["mergelist"][0]
+ depslist=list(portage_api.get_deps_for_package_building(pkg))
+ allowedpkgs+=depslist
+ # manually add all python interpreters to this list
+ allowedpkgs+=["dev-lang/python"]
+ else:
+ program_path=runtime_vars["full_path"]
+ file_to_package=portage_utils.getpackagesbyfiles([program_path])
+ if program_path not in file_to_package:
+ print("Failed to find a package for %s" % program_path)
+ else:
+ allowedpkgs+=[file_to_package[program_path]]
+ depslist=list(
+ portage_api.get_deps(file_to_package[program_path],["RDEPEND"]))
+ allowedpkgs+=depslist
+
+ # Do not forget to add self
+ allowedpkgs+=["app-portage/autodep"]
+ # remember the allowedpkgs in deps_all. It is bad to do it here.
+ runtime_vars["deps_all"]=allowedpkgs
+
+ allowedfiles=[]
+ for pkg in allowedpkgs:
+ allowedfiles+=portage_utils.getfilesbypackage(pkg)
+ allowedfiles=set(allowedfiles)
+
+ deniedfiles=allfiles-allowedfiles
+
+ print("The list size is about %dM" % (int(sys.getsizeof(deniedfiles))/1024/1024))
+ def filter(eventname,filename,stage):
+ if filename in deniedfiles:
+ return False
+ return True
+ return filter
+
portage_api, system_packages, system_deps=init_environment()
options,args=parse_args()
runtime_vars=init_runtime_vars(portage_api,options,args)
@@ -206,57 +206,57 @@ filter_function=get_filter_function(options,args,system_packages,system_deps,por
# launching program
events=logfs.fstracer.getfsevents(args[0], args,approach=options.approach,filterproc=filter_function)
runtime_vars["endtime"]=int(time.time())
-print "Program finished, analyzing dependencies"
+print("Program finished, analyzing dependencies")
if runtime_vars["is_emerge"]:
- # try to get information about packages merged sucessfully
- #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_for_package_building(pkg))
- runtime_vars["deps_buildtime"]=runtime_vars["deps_buildtime"].union(
- portage_api.get_dep(pkg,["DEPEND"]))
-
- runtime_vars["deps_portage"]=portage_api.get_dep('portage',["RDEPEND"])
+ # try to get information about packages merged sucessfully
+ #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_for_package_building(pkg))
+ runtime_vars["deps_buildtime"]=runtime_vars["deps_buildtime"].union(
+ portage_api.get_dep(pkg,["DEPEND"]))
+
+ runtime_vars["deps_portage"]=portage_api.get_dep('portage',["RDEPEND"])
else:
- if runtime_vars["deps_all"]==[]:
- # we mostly repeating block logic here
- program_path=runtime_vars["full_path"]
- file_to_package=portage_utils.getpackagesbyfiles([program_path])
- if program_path not in file_to_package:
- print "Failed to find a package for %s" % program_path
- else:
- depslist=[file_to_package[program_path]]+list(
- portage_api.get_deps(file_to_package[program_path],["RDEPEND"]))
- runtime_vars["deps_all"]=depslist
-
- #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
+ if runtime_vars["deps_all"]==[]:
+ # we mostly repeating block logic here
+ program_path=runtime_vars["full_path"]
+ file_to_package=portage_utils.getpackagesbyfiles([program_path])
+ if program_path not in file_to_package:
+ print("Failed to find a package for %s" % program_path)
+ else:
+ depslist=[file_to_package[program_path]]+list(
+ portage_api.get_deps(file_to_package[program_path],["RDEPEND"]))
+ runtime_vars["deps_all"]=depslist
+
+ #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()
for stage in events:
- succ_events=set(events[stage][0])
- fail_events=set(events[stage][1])
- filenames=filenames.union(succ_events)
- filenames=filenames.union(fail_events)
+ succ_events=set(events[stage][0])
+ fail_events=set(events[stage][1])
+ filenames=filenames.union(succ_events)
+ filenames=filenames.union(fail_events)
filenames=list(filenames)
file_to_package=portage_utils.getpackagesbyfiles(filenames)
@@ -270,41 +270,41 @@ file_to_package=portage_utils.getpackagesbyfiles(filenames)
packagesinfo={}
for stage in sorted(events):
- succ_events=events[stage][0]
- fail_events=events[stage][1]
-
- for filename in succ_events:
- if filename in file_to_package:
- package=file_to_package[filename]
- else:
- package="unknown"
-
- if not package in packagesinfo:
- packagesinfo[package]={}
- stageinfo=packagesinfo[package]
- if not stage in stageinfo:
- stageinfo[stage]={}
-
- filesinfo=stageinfo[stage]
- if not filename in filesinfo:
- filesinfo[filename]={"found":[],"notfound":[]}
- filesinfo[filename]["found"]=succ_events[filename]
+ succ_events=events[stage][0]
+ fail_events=events[stage][1]
- for filename in fail_events:
- if filename in file_to_package:
- package=file_to_package[filename]
- else:
- package="unknown"
- if not package in packagesinfo:
- packagesinfo[package]={}
- stageinfo=packagesinfo[package]
- if not stage in stageinfo:
- stageinfo[stage]={}
+ for filename in succ_events:
+ if filename in file_to_package:
+ package=file_to_package[filename]
+ else:
+ package="unknown"
+
+ if not package in packagesinfo:
+ packagesinfo[package]={}
+ stageinfo=packagesinfo[package]
+ if not stage in stageinfo:
+ stageinfo[stage]={}
+
+ filesinfo=stageinfo[stage]
+ if not filename in filesinfo:
+ filesinfo[filename]={"found":[],"notfound":[]}
+ filesinfo[filename]["found"]=succ_events[filename]
- filesinfo=stageinfo[stage]
- if not filename in filesinfo:
- filesinfo[filename]={"found":[],"notfound":[]}
- filesinfo[filename]["notfound"]=fail_events[filename]
+ for filename in fail_events:
+ if filename in file_to_package:
+ package=file_to_package[filename]
+ else:
+ package="unknown"
+ if not package in packagesinfo:
+ packagesinfo[package]={}
+ stageinfo=packagesinfo[package]
+ if not stage in stageinfo:
+ stageinfo[stage]={}
+
+ filesinfo=stageinfo[stage]
+ if not filename in filesinfo:
+ filesinfo[filename]={"found":[],"notfound":[]}
+ filesinfo[filename]["notfound"]=fail_events[filename]
# generating output
stagesorder={"clean":1,"setup":2,"unpack":3,"prepare":4,"configure":5,"compile":6,"test":7,
@@ -312,113 +312,113 @@ stagesorder={"clean":1,"setup":2,"unpack":3,"prepare":4,"configure":5,"compile":
# print information grouped by package
for package in sorted(packagesinfo):
- # not showing special directory package
- if package=="directory":
- continue
-
- if package=="unknown" and not options.verbose:
- continue
-
-
- is_pkg_in_dep=package in runtime_vars["deps_all"]
- is_pkg_in_system=package in system_packages
- is_pkg_in_system_deps=package in system_deps
-
- is_pkg_in_portage_dep=runtime_vars["is_emerge"] and package in runtime_vars["deps_portage"]
- is_pkg_self="app-portage/autodep" in package
- is_pkg_python="dev-lang/python" in package
-
- stages=[]
- for stage in sorted(packagesinfo[package].keys(), key=stagesorder.get):
- if stage!="unknown" or options.verbose or not runtime_vars["is_emerge"]:
- stages.append(stage)
+ # not showing special directory package
+ if package=="directory":
+ continue
+
+ if package=="unknown" and not options.verbose:
+ continue
- if len(stages)!=0:
- filenames={}
- for stage in stages:
- for filename in packagesinfo[package][stage]:
- if len(packagesinfo[package][stage][filename]["found"])!=0:
- was_readed,was_writed=packagesinfo[package][stage][filename]["found"]
- if not filename in filenames:
- 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:
- status, old_was_notfound, old_was_blocked=filenames[filename]
- filenames[filename]=[
- 'err',old_was_notfound | was_notfound, old_was_blocked | was_blocked
- ]
-
- if is_pkg_in_dep:
- color_printer.printmsg("text","[OK]")
- elif is_pkg_in_system:
- color_printer.printmsg("text","[SYSTEM]")
- elif is_pkg_in_portage_dep:
- color_printer.printmsg("text","[PORTAGE DEP]")
- elif is_pkg_in_system_deps:
- color_printer.printmsg("text","[SYSTEM DEP]")
- elif is_pkg_self:
- color_printer.printmsg("text","[AUTODEP]")
- 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:
- color_printer.printmsg("warning","[NOT IN DEPS]")
- # show information about accessed files
-
- print "%-40s: %s"%(package,stages)
-# if options.show_files:
-
- # this is here for readability
- action={
- ('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"
- }
+ is_pkg_in_dep=package in runtime_vars["deps_all"]
+ is_pkg_in_system=package in system_packages
+ is_pkg_in_system_deps=package in system_deps
- filescounter=0
-
- for filename in filenames:
- event_info=tuple(filenames[filename])
- print " %-56s %-21s" % (filename,action[event_info])
- filescounter+=1
- if options.show_files:
- continue
- elif filescounter>options.numfiles:
- print " ... and %d more ...\n" % (len(filenames)-options.numfiles)
- break
+ is_pkg_in_portage_dep=runtime_vars["is_emerge"] and package in runtime_vars["deps_portage"]
+ is_pkg_self="app-portage/autodep" in package
+ is_pkg_python="dev-lang/python" in package
+
+ stages=[]
+ for stage in sorted(packagesinfo[package].keys(), key=stagesorder.get):
+ if stage!="unknown" or options.verbose or not runtime_vars["is_emerge"]:
+ stages.append(stage)
+
+ if len(stages)!=0:
+ filenames={}
+ for stage in stages:
+ for filename in packagesinfo[package][stage]:
+ if len(packagesinfo[package][stage][filename]["found"])!=0:
+ was_readed,was_writed=packagesinfo[package][stage][filename]["found"]
+ if not filename in filenames:
+ 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:
+ status, old_was_notfound, old_was_blocked=filenames[filename]
+ filenames[filename]=[
+ 'err',old_was_notfound | was_notfound, old_was_blocked | was_blocked
+ ]
+
+
+ if is_pkg_in_dep:
+ color_printer.printmsg("text","[OK]")
+ elif is_pkg_in_system:
+ color_printer.printmsg("text","[SYSTEM]")
+ elif is_pkg_in_portage_dep:
+ color_printer.printmsg("text","[PORTAGE DEP]")
+ elif is_pkg_in_system_deps:
+ color_printer.printmsg("text","[SYSTEM DEP]")
+ elif is_pkg_self:
+ color_printer.printmsg("text","[AUTODEP]")
+ 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:
+ color_printer.printmsg("warning","[NOT IN DEPS]")
+ # show information about accessed files
+
+ print("%-40s: %s"%(package,stages))
+ # if options.show_files:
+
+ # this is here for readability
+ action={
+ ('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
+
+ for filename in filenames:
+ event_info=tuple(filenames[filename])
+ print(" %-56s %-21s" % (filename,action[event_info]))
+ filescounter+=1
+ if options.show_files:
+ continue
+ elif filescounter>options.numfiles:
+ print(" ... and %d more ...\n" % (len(filenames)-options.numfiles))
+ break
# print not founded files with stages
if options.show_files:
- filenames={}
- print "\nNot founded files:"
- for stage in sorted(events, key=stagesorder.get):
- print "%s:" % stage
-
- action={
- (True,False):"file not found",
- (True,True):"blocked and not found",
- (False,True):"blocked",
- (False,False):"other error"
- }
-
- fail_events=events[stage][1]
-
- for filename in sorted(fail_events, key=file_to_package.get):
- reason=tuple(fail_events[filename])
- print " %-56s %-21s" % (filename,action[reason])
+ filenames={}
+ print("\nNot founded files:")
+ for stage in sorted(events, key=stagesorder.get):
+ print("%s:" % stage)
+
+ action={
+ (True,False):"file not found",
+ (True,True):"blocked and not found",
+ (False,True):"blocked",
+ (False,False):"other error"
+ }
+
+ fail_events=events[stage][1]
+
+ for filename in sorted(fail_events, key=file_to_package.get):
+ reason=tuple(fail_events[filename])
+ print(" %-56s %-21s" % (filename,action[reason]))
diff --git a/src/autodep/logfs/logger_hooklib.py b/src/autodep/logfs/logger_hooklib.py
index 80f0cd4..8a8e2ca 100644
--- a/src/autodep/logfs/logger_hooklib.py
+++ b/src/autodep/logfs/logger_hooklib.py
@@ -7,7 +7,7 @@ class logger:
socketname=''
# we can't use just file_hook.so here
# because program may change LD_LIBRARY_PATH
- #hooklibpath='/home/bay/gsoc/src/hook_lib/file_hook.so'
+ #hooklibpath='/home/bay/autodep/src/hook_lib/file_hook.so'
hooklibpath='/usr/lib/file_hook.so'
def __init__(self,socketname):
diff --git a/src/autodep/package_utils/portage_utils.py b/src/autodep/package_utils/portage_utils.py
index d33ada6..8bf3463 100644
--- a/src/autodep/package_utils/portage_utils.py
+++ b/src/autodep/package_utils/portage_utils.py
@@ -23,19 +23,29 @@ def getpackagesbyfiles(files):
stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE,
bufsize=4096)
- out,err=proc.communicate("\n".join(listtocheck))
+ out,err=proc.communicate(b"\n".join(listtocheck))
if err!=None:
print "Noncritical error while launch qfile %s"%err;
- lines=out.split("\n")
+ lines=out.split(b"\n")
#print lines
line_re=re.compile(r"^([^ ]+)\s+\(([^)]+)\)$")
for line in lines:
+ try:
+ line=line.decode("utf-8")
+ except UnicodeDecodeError:
+ portage.util.writemsg("Util qfile returned non-utf8 string: %s\n" % line)
+
if len(line)==0:
continue
match=line_re.match(line)
if match:
- ret[match.group(2)]=match.group(1)
+ try:
+ ret[match.group(2).encode("utf-8")]=match.group(1)
+ except UnicodeEncodeError:
+ portage.util.writemsg(
+ "Util qfile failed to encode string %s to unicode\n" %
+ match.group(2))
else:
print "Util qfile returned unparsable string: %s" % line
@@ -61,7 +71,7 @@ def getfilesbypackage(packagename):
if err!=None and len(err)!=0 :
print "Noncritical error while launch qlist: %s" % err;
- ret=out.split("\n")
+ ret=out.split(b"\n")
if ret==['']:
ret=[]
except OSError,e:
@@ -85,7 +95,7 @@ def get_all_packages_files():
if err!=None and len(err)!=0 :
print "Noncritical error while launch qlist: %s" % err;
- ret=out.split("\n")
+ ret=out.split(b"\n")
except OSError,e:
print "Error while launching qfile: %s" % e