-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
92 lines (73 loc) · 3.68 KB
/
__init__.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
import Grimoire.Performer, Grimoire.Utils, Grimoire.Types, Grimoire.Types.Ability, os
comp = Grimoire.Performer.Composer
pref = Grimoire.Performer.Prefixer
iso = Grimoire.Performer.Isolator
Physical = Grimoire.Performer.Physical
Logical = Grimoire.Performer.Logical
# Serious boot-strapping
import Grimoire.root.trees.local.load
__ = Logical(Grimoire.root.trees.local.load.Performer()).load('Grimoire.root')
_ = Logical(__)
__._insert(pref(['introspection'], _.trees.introspection()), True)
serverTreesAbility = Grimoire.Types.Ability.List(
[(Grimoire.Types.Ability.Allow, ['introspection']),
(Grimoire.Types.Ability.Deny, ['trees', 'local', 'unprotected']),
(Grimoire.Types.Ability.Allow, ['trees', 'local']),
])
noIntrospectionAbility = Grimoire.Types.Ability.List(
[(Grimoire.Types.Ability.Deny, ['introspection']),
(Grimoire.Types.Ability.Allow, []),
])
serverTrees = Grimoire.Performer.Restrictor(
comp(pref(['introspection'], _.trees.introspection()),
iso(_)),
serverTreesAbility)
cfgDirs = [Grimoire.Types.defaultLocalRoot + ['etc', 'Grimoire']]
if 'HOME' in os.environ:
cfgDirs += [Grimoire.Types.LocalPath(os.environ['HOME']) + ['.Grimoire']]
if 'CHOICES' in os.environ:
cfgDirs += [Grimoire.Types.LocalPath(path) + ['Grimoire'] for path in os.environ['CHOICES'].split(':')]
_.directory.set.parameters(['directories'], cfgDirs)
cfgFiles = [path + ['Config.py'] for path in cfgDirs if os.access(unicode(path + ['Config.py']), os.F_OK)]
_.directory.set.parameters(['files'], cfgFiles)
cfgTrees = [path + ['Config.d'] for path in cfgDirs if os.access(unicode(path + ['Config.d']), os.F_OK)]
_.directory.set.parameters(['trees'], cfgTrees)
class Set(Grimoire.Performer.SubMethod):
def _call(self, path, keyPath, *arg, **kw):
__._getpath(path = list(['directory', 'set'] + configPath + path))(list(configKeyPath + keyPath), *arg, **kw)
def _dir(self, path, depth):
return __._getpath(path = ['introspection', 'dir', 'directory', 'set'] + configPath + path)(path, depth)
def _params(self, path):
return __._getpath(path = ['introspection', 'params', 'directory', 'set'] + configPath + path)(path)
set = Logical(Set())
class Get(Grimoire.Performer.SubMethod):
def _call(self, path, keyPath, *arg, **kw):
return __._getpath(path = ['directory', 'get'] + configPath + path)(configKeyPath + keyPath, *arg, **kw)
def _dir(self, path, depth):
return __._getpath(path = ['introspection', 'dir', 'directory', 'get'] + configPath + path)(path, depth)
def _params(self, path):
return __._getpath(path = ['introspection', 'params', 'directory', 'get'] + configPath + path)(path)
get = Logical(Get())
def treevar(varname, value):
_.directory.set.treevar(['treevar', varname], value)
configPath = configKeyPath = []
for configFilePath in _.directory.get.parameters(['files']):
try:
execfile(unicode(configFilePath))
except IOError:
pass
for configTree in _.directory.get.parameters(['trees']):
for dirpath, dirnames, filenames in os.walk(unicode(configTree)):
for filename in filenames:
configFilePath = Grimoire.Types.LocalPath(os.path.join(dirpath, filename))
keyPath = configFilePath[len(configTree):]['relative']
if keyPath[-1].endswith('.py'):
keyPath[-1] = keyPath[-1][:-3] # Remove .py"
if keyPath[-1] == '__init__':
del keyPath[-1]
configPath, configKeyPath = Grimoire.Utils.splitList(keyPath, '_settings', 2)
try:
execfile(unicode(configFilePath))
except IOError:
pass
configPath = configKeyPath = []