aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'portage_with_autodep/pym/_emerge/EventsAnalyser.py')
-rw-r--r--portage_with_autodep/pym/_emerge/EventsAnalyser.py180
1 files changed, 60 insertions, 120 deletions
diff --git a/portage_with_autodep/pym/_emerge/EventsAnalyser.py b/portage_with_autodep/pym/_emerge/EventsAnalyser.py
index 7e416e7..65ece7b 100644
--- a/portage_with_autodep/pym/_emerge/EventsAnalyser.py
+++ b/portage_with_autodep/pym/_emerge/EventsAnalyser.py
@@ -18,51 +18,39 @@ class PortageUtils:
self.metadata_keys = [k for k in portage.auxdbkeys if not k.startswith("UNUSED_")]
self.use=self.settings["USE"]
- def get_best_visible_pkg(self,pkg,db="portdb"):
+ def get_best_visible_pkg(self,pkg):
"""
Gets best candidate on installing. Returns empty string if no found
:param pkg: package name
- :param db: name of db to look. Can be "vardb" or "portdb"
"""
try:
- if db=="portdb":
- return self.portdbapi.xmatch("bestmatch-visible", pkg)
- elif db=="vardb":
- return self.vardbapi.match(pkg)[0]
- else:
- return ''
+ return self.portdbapi.xmatch("bestmatch-visible", pkg)
except:
return ''
# non-recursive dependency getter
- def get_dep(self,pkg,dep_type=["RDEPEND","DEPEND"],db="portdb"):
+ def get_dep(self,pkg,dep_type=["RDEPEND","DEPEND"]):
"""
Gets current dependencies of a package. Looks in portage db
:param pkg: name of package
:param dep_type: type of dependencies to recurse. Can be ["DEPEND"] or
["RDEPEND", "DEPEND"]
- :param db: name of db to look. Can be "vardb" or "portdb"
:returns: **set** of packages names
"""
ret=set()
- pkg = self.get_best_visible_pkg(pkg,db)
+ pkg = self.get_best_visible_pkg(pkg)
if not pkg:
return ret
# we found the best visible match in common tree
- if db=="portdb":
- aux_get=self.portdbapi.aux_get
- elif db=="vardb":
- aux_get=self.vardbapi.aux_get
- else:
- return ret
- metadata = dict(zip(self.metadata_keys, aux_get(pkg, self.metadata_keys)))
+ metadata = dict(zip(self.metadata_keys,
+ self.portdbapi.aux_get(pkg, self.metadata_keys)))
dep_str = " ".join(metadata[k] for k in dep_type)
# the IUSE default are very important for us
@@ -94,7 +82,7 @@ class PortageUtils:
return ret
# recursive dependency getter
- def get_deps(self,pkg,dep_type=["RDEPEND","DEPEND"],db="portdb"):
+ def get_deps(self,pkg,dep_type=["RDEPEND","DEPEND"]):
"""
Gets current dependencies of a package on any depth
All dependencies **must** be installed
@@ -102,20 +90,19 @@ class PortageUtils:
:param pkg: name of package
:param dep_type: type of dependencies to recurse. Can be ["DEPEND"] or
["RDEPEND", "DEPEND"]
- :param db: name of db to look. Can be "vardb" or "portdb"
:returns: **set** of packages names
"""
ret=set()
- #import pdb; pdb.set_trace()
+
# get porttree dependencies on the first package
- pkg = self.get_best_visible_pkg(pkg,db)
+ pkg = self.portdbapi.xmatch("bestmatch-visible", pkg)
if not pkg:
return ret
known_packages=set()
- unknown_packages=self.get_dep(pkg,dep_type,db)
+ unknown_packages=self.get_dep(pkg,dep_type)
ret=ret.union(unknown_packages)
while unknown_packages:
@@ -124,40 +111,36 @@ class PortageUtils:
continue
known_packages.add(p)
- current_deps=self.get_dep(p,dep_type,'vardb')
- unknown_packages=unknown_packages.union(current_deps)
- ret=ret.union(current_deps)
-
- #metadata = dict(zip(self.metadata_keys, self.vardbapi.aux_get(p, self.metadata_keys)))
+ metadata = dict(zip(self.metadata_keys, self.vardbapi.aux_get(p, self.metadata_keys)))
- #dep_str = " ".join(metadata[k] for k in dep_type)
+ dep_str = " ".join(metadata[k] for k in dep_type)
# the IUSE default are very important for us
- #iuse_defaults=[
- # u[1:] for u in metadata.get("IUSE",'').split() if u.startswith("+")]
+ iuse_defaults=[
+ u[1:] for u in metadata.get("IUSE",'').split() if u.startswith("+")]
- #use=self.use.split()
+ use=self.use.split()
- #for u in iuse_defaults:
- # if u not in use:
- # use.append(u)
+ for u in iuse_defaults:
+ if u not in use:
+ use.append(u)
- #success, atoms = portage.dep_check(dep_str, None, self.settings,
- # myuse=use, myroot=self.settings["ROOT"],
- # trees={self.settings["ROOT"]:{"vartree":self.vartree,"porttree": self.vartree}})
-
- #if not success:
- # continue
-
- #for atom in atoms:
- # atomname = self.vartree.dep_bestmatch(atom)
- # if not atomname:
- # continue
- #
- # for unvirt_pkg in expand_new_virt(self.vardbapi,'='+atomname):
- # for pkg in self.vartree.dep_match(unvirt_pkg):
- # ret.add(pkg)
- # unknown_packages.add(pkg)
+ success, atoms = portage.dep_check(dep_str, None, self.settings,
+ myuse=use, myroot=self.settings["ROOT"],
+ trees={self.settings["ROOT"]:{"vartree":self.vartree,"porttree": self.vartree}})
+
+ if not success:
+ continue
+
+ for atom in atoms:
+ atomname = self.vartree.dep_bestmatch(atom)
+ if not atomname:
+ continue
+
+ for unvirt_pkg in expand_new_virt(self.vardbapi,'='+atomname):
+ for pkg in self.vartree.dep_match(unvirt_pkg):
+ ret.add(pkg)
+ unknown_packages.add(pkg)
return ret
def get_deps_for_package_building(self, pkg):
@@ -165,13 +148,12 @@ class PortageUtils:
returns buildtime dependencies of current package and
all runtime dependencies of that buildtime dependencies
"""
- buildtime_deps=self.get_dep(pkg, ["DEPEND"],"portdb")
+ buildtime_deps=self.get_dep(pkg, ["DEPEND"])
runtime_deps=set()
for dep in buildtime_deps:
- runtime_deps|=self.get_deps(dep,["RDEPEND","PDEPEND"],"vardb")
+ runtime_deps=runtime_deps.union(self.get_deps(dep,["RDEPEND"]))
- ret = buildtime_deps | runtime_deps
-
+ ret=buildtime_deps.union(runtime_deps)
return ret
def get_system_packages_list(self):
@@ -187,19 +169,7 @@ class PortageUtils:
for pkg in self.vartree.dep_match(unvirt_pkg):
ret.append(pkg)
return ret
-
- def get_system_packages_rdeps(self):
- """
- returns runtime dependencies of packages from system set
-
- :returns: **list** of package names
- """
- ret=set()
-
- for pkg in self.get_system_packages_list():
- ret=ret.union(self.get_deps(pkg,["RDEPEND"]))
- return list(ret)
-
+
class GentoolkitUtils:
"""
@@ -207,7 +177,7 @@ class GentoolkitUtils:
internals.
"""
- def getpackagesbyfiles(self,files):
+ def getpackagesbyfiles(files):
"""
:param files: list of filenames
:returns: **dictionary** file->package, if file doesn't belong to any
@@ -226,30 +196,17 @@ class GentoolkitUtils:
stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE,
bufsize=4096)
- out,err=proc.communicate(b"\n".join(listtocheck))
+ out,err=proc.communicate("\n".join(listtocheck).encode("utf8"))
- lines=out.split(b"\n")
+ lines=out.decode("utf8").split("\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)
-
- #import pdb; pdb.set_trace()
-
if len(line)==0:
continue
match=line_re.match(line)
if match:
- 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))
-
+ ret[match.group(2)]=match.group(1)
else:
portage.util.writemsg("Util qfile returned unparsable string: %s\n" % line)
@@ -259,7 +216,7 @@ class GentoolkitUtils:
return ret
- def getfilesbypackages(self,packagenames):
+ def getfilesbypackages(packagenames):
"""
:param packagename: name of package
@@ -273,7 +230,7 @@ class GentoolkitUtils:
out,err=proc.communicate()
- ret=out.split(b"\n")
+ ret=out.decode("utf8").split("\n")
if ret==['']:
ret=[]
except OSError as e:
@@ -281,7 +238,7 @@ class GentoolkitUtils:
return ret
- def get_all_packages_files(self):
+ def get_all_packages_files():
"""
Memory-hungry operation
@@ -295,7 +252,7 @@ class GentoolkitUtils:
out,err=proc.communicate()
- ret=out.split(b"\n")
+ ret=out.decode("utf8").split("\n")
except OSError as e:
portage.util.writemsg("Error while launching qfile: %s\n" % e)
@@ -306,28 +263,25 @@ class FilterProcGenerator:
portageutils=PortageUtils(settings=settings)
deps_all=portageutils.get_deps_for_package_building(pkgname)
- deps_portage=portageutils.get_dep('sys-apps/portage',["RDEPEND"])
+ deps_portage=portageutils.get_dep('portage',["RDEPEND"])
system_packages=portageutils.get_system_packages_list()
- system_deps=portageutils.get_system_packages_rdeps()
- allfiles=GentoolkitUtils().get_all_packages_files()
+ allfiles=GentoolkitUtils.get_all_packages_files()
portage.util.writemsg("All files list recieved, waiting for " \
"a list of allowed files\n")
- allowedpkgs=system_packages+system_deps
- allowedpkgs+=list(deps_portage)+list(deps_all)
- allowedpkgs+=["app-portage/autodep"]
+ allowedpkgs=system_packages+list(deps_portage)+list(deps_all)
- allowedfiles=GentoolkitUtils().getfilesbypackages(allowedpkgs)
+ allowedfiles=GentoolkitUtils.getfilesbypackages(allowedpkgs)
#for pkg in allowedpkgs:
# allowedfiles+=GentoolkitUtils.getfilesbypackage(pkg)
#import pdb; pdb.set_trace()
# manually add all python interpreters to this list
- allowedfiles+=GentoolkitUtils().getfilesbypackages(['python'])
+ allowedfiles+=GentoolkitUtils.getfilesbypackages(['python'])
allowedfiles=set(allowedfiles)
deniedfiles=allfiles-allowedfiles
@@ -350,10 +304,9 @@ class EventsAnalyser:
self.deps_all=self.portageutils.get_deps_for_package_building(pkgname)
self.deps_direct=self.portageutils.get_dep(pkgname,["DEPEND"])
- self.deps_portage=self.portageutils.get_dep('sys-apps/portage',["RDEPEND"])
-
+ self.deps_portage=self.portageutils.get_dep('portage',["RDEPEND"])
+
self.system_packages=self.portageutils.get_system_packages_list()
- self.system_deps=self.portageutils.get_system_packages_rdeps()
# All analyse work is here
# get unique filenames
@@ -365,7 +318,7 @@ class EventsAnalyser:
filenames=filenames.union(fail_events)
filenames=list(filenames)
- file_to_package=GentoolkitUtils().getpackagesbyfiles(filenames)
+ file_to_package=GentoolkitUtils.getpackagesbyfiles(filenames)
# This part is completly unreadable.
# It converting one complex struct(returned by getfsevents) to another complex
# struct which good for generating output.
@@ -420,8 +373,7 @@ class EventsAnalyser:
stagesorder={"clean":1,"setup":2,"unpack":3,"prepare":4,"configure":5,"compile":6,"test":7,
"install":8,"preinst":9,"postinst":10,"prerm":11,"postrm":12,"unknown":13}
packagesinfo=self.packagesinfo
- # print information grouped by package
- #print(packagesinfo.keys())
+ # print information grouped by package
for package in sorted(packagesinfo):
# not showing special directory package
if package=="directory":
@@ -429,14 +381,12 @@ class EventsAnalyser:
if package=="unknown":
continue
-
+
is_pkg_in_dep=package in self.deps_all
is_pkg_in_portage_dep=package in self.deps_portage
is_pkg_in_system=package in self.system_packages
- is_pkg_in_system_dep=package in self.system_deps
is_pkg_python="dev-lang/python" in package
- is_pkg_self="app-portage/autodep" in package
stages=[]
for stage in sorted(packagesinfo[package].keys(), key=stagesorder.get):
@@ -475,10 +425,6 @@ class EventsAnalyser:
portage.util.writemsg("[SYSTEM]")
elif is_pkg_in_portage_dep:
portage.util.writemsg("[PORTAGE DEP]")
- elif is_pkg_in_system_dep:
- portage.util.writemsg("[SYSTEM DEP]")
- elif is_pkg_self:
- portage.util.writemsg("[AUTODEP]")
elif is_pkg_python:
portage.util.writemsg("[INTERPRETER]")
elif not self.is_package_useful(package,stages,filenames.keys()):
@@ -505,12 +451,7 @@ class EventsAnalyser:
for filename in filenames:
event_info=tuple(filenames[filename])
- try:
- portage.util.writemsg(
- " %-56s %-21s\n" % (filename.decode('utf-8'),action[event_info]))
- except UnicodeDecodeError:
- portage.util.writemsg(
- " %-56s %-21s\n" % ('NON-UTF8-FILENAME',action[event_info]))
+ portage.util.writemsg(" %-56s %-21s\n" % (filename,action[event_info]))
filescounter+=1
if filescounter>10:
portage.util.writemsg(" ... and %d more ...\n" % (len(filenames)-10))
@@ -529,7 +470,7 @@ class EventsAnalyser:
""" some basic heuristics here to cut part of packages """
excluded_paths=set(
- [b'/etc/sandbox.d/']
+ ['/etc/sandbox.d/']
)
excluded_packages=set(
@@ -560,9 +501,8 @@ class EventsAnalyser:
continue
# test 1: package is not useful if all files are *.desktop or *.xml or *.m4
- if not (f.endswith(b".desktop") or f.endswith(b".xml") or
- f.endswith(b".m4") or f.endswith(b".pc")):
- break
+ 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