-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.py
75 lines (63 loc) · 2.26 KB
/
profile.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
import os
from access import *
class PortageProfile(object):
# While the Portage profile is traditinally stored within the Portage
# repository, it makes sense to not impose this restriction on the
# PortageProfile object. This PortageProfile object can exist anywhere
# on the filesystem.
def __repr__(self):
return "PortageProfile(%s)" % self.path
def __init__(self, path):
# self.path is a FilePath object (defined in access.py).
# self.path.base_path would point to e.g. "/usr/portage/profiles".
# self.path.path would point to e.g. "default/linux/x86/2008.0".
# self.path.diskpath would point to "/usr/portage/profiles/default/linux/x86/2008.0".
self.path = path
self._cascaded_items = {}
self.parents = [ ]
parent = self.path.adjpath("parent")
if parent.exists():
entries = parent.grabfile()
for entry in entries:
self.parents.append(PortageProfile(self.path.adjpath(entry)))
def __getitem__(self,path):
if path in self._cascaded_items:
return self._cascaded_items[path]
else:
return self._cascade(path)
def _cascade(self,filename):
# _cascade() will recursively look at the parent profiles and
# the current profile and create a list of all files that have
# a certain filename. This function is used to get a list of
# all "virtuals" files, or all "make.defaults" files. The
# absolute physical disk path to these files is returned in
# list form. Already-computed lists are stored in
# self._cascaded_items[filename], in case they are requested
# multiple times.
if filename not in self._cascaded_items:
found = []
for parent in self.parents:
parent_items = parent[filename]
if parent_items != None:
found.extend(parent_items)
myf = self.path.adjpath(filename)
if myf.exists():
found.append(myf)
self._cascaded_items[filename] = found
return self._cascaded_items[filename]
#@property
#def virtuals(self):
# virts = self._cascade("virtuals")
# return self.access.collapse_files(virts)
if __name__ == "__main__":
a=PortageProfile(FilePath("default/linux/amd64/2008.0",base_path="/var/git/portage-mini-2010/profiles"))
print "PROFILE PARENTS"
print "==============="
print
print a.parents
print
print "make.defaults"
print "============="
print
print a["make.defaults"]
print