aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Bersenev <bay@hackerdom.ru>2011-10-03 15:22:30 +0000
committerAlexander Bersenev <bay@hackerdom.ru>2011-10-03 15:22:30 +0000
commite541c423ce50003e05b9a154a0893cafe8bd7445 (patch)
treeecb5ab4d5f478aedbfc2437d808f3e4c7bd1a950
parentupdate an overlay (diff)
downloadautodep-e541c423ce50003e05b9a154a0893cafe8bd7445.tar.gz
autodep-e541c423ce50003e05b9a154a0893cafe8bd7445.tar.bz2
autodep-e541c423ce50003e05b9a154a0893cafe8bd7445.zip
minor refactoring, fixed an error when deps weren't calculated
-rw-r--r--src/autodep/package_utils/portage_misc_functions.py82
1 files changed, 34 insertions, 48 deletions
diff --git a/src/autodep/package_utils/portage_misc_functions.py b/src/autodep/package_utils/portage_misc_functions.py
index 29fcfec..849c9c8 100644
--- a/src/autodep/package_utils/portage_misc_functions.py
+++ b/src/autodep/package_utils/portage_misc_functions.py
@@ -29,7 +29,8 @@ class portage_api:
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_")]
+ self.metadata_keys = [
+ k for k in portage.auxdbkeys if not k.startswith("UNUSED_")]
self.use=self.settings["USE"]
# This function is from portage and almost unchanged
@@ -96,15 +97,20 @@ class portage_api:
yield atom
- def get_best_visible_pkg(self,pkg):
+ def get_best_visible_pkg(self,pkg,db="portdb"):
"""
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:
- return self.portdb.xmatch("bestmatch-visible", pkg)
+ if db=="portdb":
+ return self.portdb.xmatch("bestmatch-visible", pkg)
+ elif db=="vardb":
+ return self.vardb.match(pkg)[0]
+ else:
+ return ''
except:
return ''
@@ -164,27 +170,34 @@ class portage_api:
return []
# non-recursive dependency getter
- def get_dep(self,pkg,dep_type=["RDEPEND","DEPEND"]):
+ def get_dep(self,pkg,dep_type=["RDEPEND","DEPEND"],db="portdb"):
"""
- Gets current dependencies of a package. Looks in portage db
+ Gets current dependencies of a package. Looks in portage db by default
: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)
+ pkg = self.get_best_visible_pkg(pkg,db)
if not pkg:
return ret
-
+
# we found the best visible match in common tree
#import pdb; pdb.set_trace()
- metadata = dict(zip(self.metadata_keys,
- self.portdb.aux_get(pkg, self.metadata_keys)))
+ if db=="portdb":
+ aux_get=self.portdb.aux_get
+ elif db=="vardb":
+ aux_get=self.vardb.aux_get
+ else:
+ return ret
+
+ metadata = dict(zip(self.metadata_keys, aux_get(pkg, self.metadata_keys)))
dep_str = " ".join(metadata[k] for k in dep_type)
# the IUSE default are very important for us
@@ -214,9 +227,9 @@ class portage_api:
ret.add(pkg)
return ret
-
+
# recursive dependency getter
- def get_deps(self,pkg,dep_type=["RDEPEND","DEPEND"]):
+ def get_deps(self,pkg,dep_type=["RDEPEND","DEPEND"],db="portdb"):
"""
Gets current dependencies of a package on any depth
All dependencies **must** be installed
@@ -224,22 +237,21 @@ class portage_api:
: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
"""
- #pkg="kde-meta"
- #print self.vardb.match("<sys-apps/paludis-0.26.0_alpha5")
- #metadata = dict(zip(self.metadata_keys, self.vardb.aux_get(pkg, self.metadata_keys)))
ret=set()
# get porttree dependencies on the first package
- pkg = self.portdb.xmatch("bestmatch-visible", pkg)
+ pkg = self.get_best_visible_pkg(pkg,db)
if not pkg:
return ret
+ #print "doing",pkg
known_packages=set()
- unknown_packages=self.get_dep(pkg,dep_type)
+ unknown_packages=self.get_dep(pkg,dep_type,db)
ret=ret.union(unknown_packages)
while unknown_packages:
@@ -249,36 +261,10 @@ class portage_api:
continue
known_packages.add(p)
- metadata = dict(zip(self.metadata_keys, self.vardb.aux_get(p, self.metadata_keys)))
-
- dep_str = " ".join(metadata[k] for k in dep_type)
+ current_deps=self.get_dep(p,dep_type,'vardb')
+ unknown_packages=unknown_packages.union(current_deps)
+ ret=ret.union(current_deps)
- # the IUSE default are very important for us
- iuse_defaults=[
- u[1:] for u in metadata.get("IUSE",'').split() if u.startswith("+")]
-
- use=self.use.split()
-
- 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,
- trees=portage.db, myroot=self.settings["ROOT"])
-
- if not success:
- continue
-
- for atom in atoms:
- atomname = self.vartree.dep_bestmatch(atom)
- #print atomname
- if not atomname:
- continue
-
- for unvirt_pkg in self.expand_new_virt('='+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):
@@ -286,10 +272,10 @@ class portage_api:
returns buildtime dependencies of current package and
all runtime dependencies of that buildtime dependencies
"""
- buildtime_deps=self.get_dep(pkg, ["DEPEND"])
+ buildtime_deps=self.get_dep(pkg, ["DEPEND"],"portdb")
runtime_deps=set()
for dep in buildtime_deps:
- runtime_deps=runtime_deps.union(self.get_deps(dep,["RDEPEND"]))
+ runtime_deps=runtime_deps.union(self.get_deps(dep,["RDEPEND"],"vardb"))
ret=buildtime_deps.union(runtime_deps)
return ret