-
Notifications
You must be signed in to change notification settings - Fork 0
/
ports.py
109 lines (74 loc) · 2.15 KB
/
ports.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
repo = {
r"profiles/[\w-]+" : Profile,
r"[^/]+" : Category,
r"[^/]+/[^/]+" : CatPkg,
r"[^/]+/[^/]+/[^_]+" : PkgAtom,
}
disk = {
r"[^/]+" : Category,
r"[^/]+/[^/]+" : CatPkg,
r"[^/]+/[^/]+/[^_]+" : PkgAtom,
class Root(object):
def __init__(self,path):
self.path = path
def __hash__(self):
return hash(path)
def __eq__(self,other):
return self.path == other.path
class Path(object):
def __init__(self,root,path):
self.root = root
self.path = path
def __hash__(self):
return hash(self.fullpath)
def adjpath(self,change):
# This returns a new path -
# foo.adjpath("..") would return the previous directory.
# foo.adjpath("foo") would return a path to the current path plus "/foo"
# foo.adjpath("/foo") would return an absolute path "/foo.
# The path root for the new path is the same as this path.
if os.path.isabs(change):
return Path(root=self.root,path=change)
else:
return Path(root=self.root,path=os.path.normpath(os.path.join(self.path, change)))
def contents(self):
objs = set()
for file in os.path.listdir(self.fullpath):
objs.add(self.adjpath(file))
return objs
@property
def fullpath(self):
return os.path.join(self.root.path,self.path)
def exists(self):
return os.path.exists(self.fullpath)
def open(self,mode):
return open(self.fullpath,mode)
class PortageRepository(Path):
def contents(self):
cats = set(os.path.listdir(self.fullpath) & valid
objs = set()
for cat in cats:
objs.add(Category(root=self.root,path=cat))
return objs
@property
def valid(self):
return set(self.path.adjpath("profiles/categories").grabfile())
class Category(Path):
def contents(self):
objs = set()
for catpkg in os.path.listdir(self.fullpath):
objs.add(CatPkg(root=self.root,path="%s/%s" % (self.path, catpkg)))
return objs
class CatPkg(Path):
def contents(self):
objs = set()
for pkgatom in os.path.listdir(self.fullpath):
if pkgatom[-7:] != ".ebuild":
continue
vers = pkgatom[len(self.path):-7]
objs.add(PkgAtom(root=self.root,path="%s/%s" % (self.path, vers)))
return objs
class PkgAtom(Path):
def exists(self):
class GitPortageRoot(Root):
class ProfileRoot(Root):