1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#!/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, ["RDEPEND"])[0]
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, trees=["/usr/portage"], categories=None):
return self.dbapi.cp_all(categories=categories, trees=trees)
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)
|