-rwxr-xr-x | scripts/builder/main.py | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/scripts/builder/main.py b/scripts/builder/main.py new file mode 100755 index 0000000..ba0c72a --- a/dev/null +++ b/scripts/builder/main.py | |||
@@ -0,0 +1,166 @@ | |||
1 | #!/usr/bin/python | ||
2 | # -*- coding: UTF-8 -*- | ||
3 | |||
4 | import sys, os, json | ||
5 | import shutil | ||
6 | import pprint | ||
7 | import frontendBuilder | ||
8 | import codecs | ||
9 | import itertools | ||
10 | |||
11 | from collections import deque | ||
12 | from phpBuilder import PhpBuilder | ||
13 | from pythonBuilder import PythonBuilder | ||
14 | |||
15 | pp = pprint.PrettyPrinter(indent=4, depth=4) | ||
16 | |||
17 | #-------------------------------------------------------------------- | ||
18 | |||
19 | def scriptDir (): | ||
20 | return os.path.dirname(sys.argv[0]) | ||
21 | |||
22 | def projectBaseDir (): | ||
23 | return os.path.abspath(scriptDir() + '/../..') | ||
24 | |||
25 | def projectTargetDir(): | ||
26 | return projectBaseDir() + '/target/' | ||
27 | |||
28 | #-------------------------------------------------------------------- | ||
29 | |||
30 | def createFolder (path): | ||
31 | if not os.path.exists(path): | ||
32 | os.makedirs(path) | ||
33 | |||
34 | #-------------------------------------------------------------------- | ||
35 | |||
36 | def loadSettings (component, module): | ||
37 | print "MODULE: " + module | ||
38 | |||
39 | if '.' in module: | ||
40 | moduleComponents = module.split('.') | ||
41 | module = moduleComponents[0] | ||
42 | submodule = moduleComponents[1] | ||
43 | else: | ||
44 | submodule = module | ||
45 | |||
46 | settings = codecs.open(projectBaseDir() + '/' + component + '/' + module + '/properties/' + submodule + '.properties.json', 'r', 'utf-8') | ||
47 | result = json.load(settings) | ||
48 | settings.close | ||
49 | |||
50 | return result | ||
51 | |||
52 | #==================================================================== | ||
53 | # | ||
54 | # def assembleFrontend (frontend, versions): | ||
55 | # result = {} | ||
56 | # settings = loadSettings('frontend', frontend) | ||
57 | # builder = frontendBuilder.FrontendBuilder(frontend, settings, projectBaseDir()) | ||
58 | # | ||
59 | # for version in versions: | ||
60 | # if version == 'install': | ||
61 | # result[version] = builder.assembleInstallVersion() | ||
62 | # elif version == 'debug': | ||
63 | # result[version] = builder.assembleDebugVersion() | ||
64 | # else: | ||
65 | # raise Exception('unrecognized version: ' + version) | ||
66 | # | ||
67 | # return result | ||
68 | # | ||
69 | #==================================================================== | ||
70 | |||
71 | def assembleBackend (backend, frontends, versions): | ||
72 | settings = loadSettings('backend', backend) | ||
73 | |||
74 | if backend == 'php': | ||
75 | backendBuilder = PhpBuilder(projectTargetDir(), frontends, versions, settings) | ||
76 | elif backend == 'python': | ||
77 | backendBuilder = PythonBuilder(projectTargetDir(), frontends, versions, settings) | ||
78 | #elif backend == 'java': | ||
79 | #buildJavaBackend (frontends, versions, settings) | ||
80 | else: | ||
81 | raise Exception('unrecognized backend: ' + backend) | ||
82 | |||
83 | backendBuilder.run() | ||
84 | |||
85 | #==================================================================== | ||
86 | |||
87 | def build (settings): | ||
88 | frontends = [] | ||
89 | |||
90 | for frontend in settings['frontends']: | ||
91 | frontends.append(frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend))) | ||
92 | |||
93 | for backend in settings['backends']: | ||
94 | assembleBackend(backend, frontends, settings['versions']) | ||
95 | |||
96 | #-------------------------------------------------------------------- | ||
97 | |||
98 | def clean (): | ||
99 | print "cleaning up …" | ||
100 | if os.path.exists(projectTargetDir()): | ||
101 | shutil.rmtree(projectTargetDir()) | ||
102 | |||
103 | #-------------------------------------------------------------------- | ||
104 | |||
105 | def usage (message): | ||
106 | if message != None: | ||
107 | print "ERROR: " + message | ||
108 | |||
109 | |||
110 | print "build.py clean" | ||
111 | print "build.py clean install" | ||
112 | print "build.py install --ALL" | ||
113 | print "build.py install debug --ALL" | ||
114 | print "build.py clean install debug --ALL" | ||
115 | print "build.ph install, debug --backends php java --frontends beta gamma" | ||
116 | print "build.ph install, debug --backends php java --frontends beta gamma gamma.mobile" | ||
117 | exit(1) | ||
118 | |||
119 | #-------------------------------------------------------------------- | ||
120 | |||
121 | def main (): | ||
122 | settings = {} | ||
123 | parameters = list(itertools.islice(sys.argv, 1, None)) | ||
124 | |||
125 | shouldClean = len(filter(lambda x: x == 'clean', parameters)) > 0 | ||
126 | if (shouldClean): | ||
127 | clean () | ||
128 | |||
129 | parameters = filter(lambda x: x != 'clean', parameters) | ||
130 | versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) | ||
131 | settings['versions'] = versions; #['debug', 'install'] | ||
132 | parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) | ||
133 | |||
134 | if len(parameters) > 0: | ||
135 | parameter = parameters.popleft() | ||
136 | if parameter == "--ALL": | ||
137 | settings['frontends'] = ['beta', 'gamma', 'mobile'] | ||
138 | settings['backends'] = ['php', 'python', 'java'] | ||
139 | else: | ||
140 | while parameter != None: | ||
141 | values = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) | ||
142 | |||
143 | if parameter == "--backends": | ||
144 | settings['backends'] = values | ||
145 | elif parameter == "--frontends": | ||
146 | settings['frontends'] = values | ||
147 | |||
148 | parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) | ||
149 | if parameters: | ||
150 | parameter = parameters.popleft() | ||
151 | else: | ||
152 | parameter = None | ||
153 | |||
154 | if (not settings.has_key('versions')): | ||
155 | usage("missing 'versions'") | ||
156 | if (not settings.has_key('frontends')): | ||
157 | usage("missing 'frontends'") | ||
158 | if (not settings.has_key('backends')): | ||
159 | usage("missing 'backends'") | ||
160 | |||
161 | build (settings) | ||
162 | |||
163 | |||
164 | |||
165 | if __name__ == "__main__": | ||
166 | main() \ No newline at end of file | ||