diff options
Diffstat (limited to 'scripts/check-subslot-deps.py')
-rwxr-xr-x | scripts/check-subslot-deps.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/scripts/check-subslot-deps.py b/scripts/check-subslot-deps.py new file mode 100755 index 0000000..01ec212 --- /dev/null +++ b/scripts/check-subslot-deps.py @@ -0,0 +1,81 @@ +#!/usr/bin/python + +from portage.dbapi.porttree import portdbapi +from portage.versions import catpkgsplit +import io +import re + +class CheckSubSlot: + def __init__(self): + self.dbapi = portdbapi() + self.subslottedCp = [] + with open("subslotted-packages.txt", "r") as f: + for line in f: + self.subslottedCp.append(line[:-1]) + + def checkPackage(self, cpv): + deps = self._getDepend(cpv) + missingSubSlotDep = [] + for dep in deps: + cp = self._getCP(dep) + if cp in self.subslottedCp and not self._isSubSlotDep(dep): + missingSubSlotDep.append(cp) + if len(missingSubSlotDep) > 0: + missingSubSlotDep = set(missingSubSlotDep) + print("%s: %s" % (cpv, " ".join(missingSubSlotDep))) + + def _getDepend(self, cpv): + deps = self.dbapi.aux_get(cpv, ["DEPEND", "RDEPEND"]) + deps = deps[0] + " " + deps[1] + result = [] + for dep in deps.split(): + if self._isValidAtom(dep): + result.append(dep) + return set(result) + + def _isValidAtom(self, pkg): + result = False + try: + if pkg[0] == "!": + result = False + elif pkg.find("/") > 0: + result = True + except: + result = False + return result + + def _getCP(self, pkg): + # drop ><= from the beginning + if pkg[0] in (">", "<", "="): + pkg = pkg[1:] + if pkg[0] == "=": + pkg = pkg[1:] + + dotPos = pkg.find(":") + bracketPos = pkg.find("[") + if dotPos > 0: + pkg = pkg[0:dotPos] + elif bracketPos > 0: + pkg = pkg[0:bracketPos] + res = catpkgsplit(pkg) + if res: + return res[0] + "/" + res[1] + return pkg + + def _isSubSlotDep(self, pkg): + m = re.search(":[0-9]*?=", pkg) + return m is not None + + def getPackages(self, categories=None): + return self.dbapi.cp_all(categories=categories) + + def getPackageVersions(self, cp): + return self.dbapi.cp_list(cp) + +c = CheckSubSlot() +pkgs = c.getPackages() +for pkg in pkgs: + cpvs = c.getPackageVersions(pkg) + for cpv in cpvs: + c.checkPackage(cpv) + |