-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.py
65 lines (53 loc) · 1.71 KB
/
loader.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
"""
Jack Dwyer 19/12/2011
Uses:
http://pyyaml.org/wiki/PyYAMLDocumentation
easy_install pyYaml
"""
import yaml
import os, sys
def create():
#possible YAML config creator
print "create"
def load(config):
stream = file(config, 'r')
config = yaml.load(stream)
#get data file location and classes used
dataFile = config.get('file')
modules = config.get('modules')
moduleConfig = config.get('moduleConfig')
instanceDict, sequenceList = initModules(modules)
data = {}
run(instanceDict, dataFile, data, moduleConfig, sequenceList);
def initModules(modules):
instanceDict = {}
sequenceList = []
for class_ in modules:
module = __import__(class_)
mod = getattr(module, class_)
x = mod()
instanceDict[class_] = x
sequenceList.append(class_)
return instanceDict, sequenceList
def run(instanceDict, dataFile, data, moduleConfig, sequenceList):
for class_ in sequenceList:
try :
parms = moduleConfig[class_]
except :
parms = {}
data = instanceDict[class_].run(dataFile, data, **parms)
if __name__ == "__main__":
if (len(sys.argv) == 1):
print "Not Enough Arguments: python loader.py load|create [options]"
sys.exit(1)
if 'create' in sys.argv:
create()
if 'load' in sys.argv:
if (len(sys.argv) <= 2):
print "Not Enough Arguments: python loader.py load [configFile]"
sys.exit(1)
if (len(sys.argv) == 3):
load(sys.argv[2])
if (len(sys.argv) > 3):
print "Too Many Arguments: python loader.py load [configFile]"
sys.exit(1)