-rwxr-xr-x | scripts/builder/main.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/scripts/builder/main.py b/scripts/builder/main.py index 6fce65d..b9fe04a 100755 --- a/scripts/builder/main.py +++ b/scripts/builder/main.py | |||
@@ -1,29 +1,29 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
2 | # -*- coding: UTF-8 -*- | 2 | # -*- coding: UTF-8 -*- |
3 | 3 | ||
4 | import sys | 4 | import sys |
5 | import os | 5 | import os |
6 | import json | 6 | import json |
7 | import shutil | 7 | import shutil |
8 | import pprint | 8 | import pprint |
9 | import codecs | 9 | import codecs |
10 | import itertools | 10 | import itertools |
11 | from collections import deque | 11 | from collections import deque |
12 | 12 | ||
13 | import frontendBuilder | 13 | #import frontendBuilder |
14 | import repository | 14 | import repository |
15 | 15 | ||
16 | pp = pprint.PrettyPrinter(indent=4, depth=4) | 16 | pp = pprint.PrettyPrinter(indent=4, depth=4) |
17 | 17 | ||
18 | #-------------------------------------------------------------------- | 18 | #-------------------------------------------------------------------- |
19 | 19 | ||
20 | def scriptDir (): | 20 | def scriptDir (): |
21 | return os.path.dirname(sys.argv[0]) | 21 | return os.path.dirname(sys.argv[0]) |
22 | 22 | ||
23 | def projectBaseDir (): | 23 | def projectBaseDir (): |
24 | return os.path.abspath(scriptDir() + '/../..') | 24 | return os.path.abspath(scriptDir() + '/../..') |
25 | 25 | ||
26 | def projectTargetDir(): | 26 | def projectTargetDir(): |
27 | return projectBaseDir() + '/target/' | 27 | return projectBaseDir() + '/target/' |
28 | 28 | ||
29 | #-------------------------------------------------------------------- | 29 | #-------------------------------------------------------------------- |
@@ -62,91 +62,105 @@ def loadSettings (component, module): | |||
62 | # if version == 'install': | 62 | # if version == 'install': |
63 | # result[version] = builder.assembleInstallVersion() | 63 | # result[version] = builder.assembleInstallVersion() |
64 | # elif version == 'debug': | 64 | # elif version == 'debug': |
65 | # result[version] = builder.assembleDebugVersion() | 65 | # result[version] = builder.assembleDebugVersion() |
66 | # else: | 66 | # else: |
67 | # raise Exception('unrecognized version: ' + version) | 67 | # raise Exception('unrecognized version: ' + version) |
68 | # | 68 | # |
69 | # return result | 69 | # return result |
70 | # | 70 | # |
71 | #==================================================================== | 71 | #==================================================================== |
72 | 72 | ||
73 | def assembleBackend (backend, frontends, versions): | 73 | def assembleBackend (backend, frontends, versions): |
74 | settings = loadSettings('backend', backend) | 74 | settings = loadSettings('backend', backend) |
75 | 75 | ||
76 | builderModuleName = backend + 'Builder' | 76 | builderModuleName = backend + 'Builder' |
77 | builderClassName = backend.capitalize() + 'Builder' | 77 | builderClassName = backend.capitalize() + 'Builder' |
78 | 78 | #print ("BUILD BACKENDS - module: " + builderModuleName + " , class: " + builderClassName) | |
79 | builderModule = __import__(builderModuleName) | 79 | builderModule = __import__(builderModuleName) |
80 | builderClass = getattr(builderModule, builderClassName) | 80 | builderClass = getattr(builderModule, builderClassName) |
81 | 81 | ||
82 | backendBuilder = builderClass(projectTargetDir(), frontends, versions, settings) | 82 | backendBuilder = builderClass(projectTargetDir(), frontends, versions, settings) |
83 | backendBuilder.run() | 83 | backendBuilder.run() |
84 | 84 | ||
85 | #==================================================================== | 85 | #==================================================================== |
86 | 86 | ||
87 | def build (settings, repository): | 87 | def build (settings, repository): |
88 | frontends = [] | 88 | frontends = [] |
89 | 89 | ||
90 | if repository.areTherePendingChanges(): | 90 | if repository.areTherePendingChanges(): |
91 | print "\nWARNING: repository has pending changes\n" | 91 | if 'install' in settings['versions']: |
92 | raise Exception("repository has pending changes, can't 'install'") | ||
93 | else: | ||
94 | print "\nWARNING: repository has pending changes\n" | ||
92 | 95 | ||
93 | for frontend in settings['frontends']: | 96 | for frontend in settings['frontends']: |
94 | frontends.append(frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend), repository.version())) | 97 | normalizedFrontendName = frontend.replace(".", "_") |
98 | builderModuleName = normalizedFrontendName + 'Builder' | ||
99 | builderClassName = normalizedFrontendName.title() + 'Builder' | ||
100 | |||
101 | #print ("BUILD FRONTEND - module: " + builderModuleName + " , class: " + builderClassName) | ||
102 | builderModule = __import__(builderModuleName) | ||
103 | builderClass = getattr(builderModule, builderClassName) | ||
104 | builder = builderClass(frontend, loadSettings('frontend', frontend), repository.version()) | ||
105 | #builder = frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend), repository.version()) | ||
106 | frontends.append(builder) | ||
95 | 107 | ||
96 | for backend in settings['backends']: | 108 | for backend in settings['backends']: |
97 | assembleBackend(backend, frontends, settings['versions']) | 109 | assembleBackend(backend, frontends, settings['versions']) |
98 | 110 | ||
99 | #-------------------------------------------------------------------- | 111 | #-------------------------------------------------------------------- |
100 | 112 | ||
101 | def clean (): | 113 | def clean (): |
102 | # print "cleaning up …" | 114 | # print "cleaning up …" |
103 | if os.path.exists(projectTargetDir()): | 115 | if os.path.exists(projectTargetDir()): |
104 | shutil.rmtree(projectTargetDir()) | 116 | shutil.rmtree(projectTargetDir()) |
105 | 117 | ||
106 | #-------------------------------------------------------------------- | 118 | #-------------------------------------------------------------------- |
107 | 119 | ||
108 | def usage (message): | 120 | def usage (message): |
109 | if message != None: | 121 | if message != None: |
110 | print "ERROR: " + message | 122 | print "ERROR: " + message |
111 | 123 | ||
112 | 124 | ||
113 | # print "build clean" | 125 | # print "build clean" |
114 | # print "build clean install" | 126 | # print "build clean install" |
115 | print "build install --ALL" | 127 | print "build install --ALL" |
116 | print "build install debug --ALL" | 128 | print "build install debug --ALL" |
129 | print "build install debug development --ALL" | ||
117 | # print "build clean install debug --ALL" | 130 | # print "build clean install debug --ALL" |
118 | print "build install debug --backends php python --frontends beta gamma" | 131 | print "build install debug --backends php python --frontends beta gamma" |
119 | print "build install debug development --backends php python --frontends beta gamma gamma.mobile" | 132 | print "build install debug development --backends php python --frontends beta gamma gamma.mobile" |
120 | exit(1) | 133 | exit(1) |
121 | 134 | ||
122 | #-------------------------------------------------------------------- | 135 | #-------------------------------------------------------------------- |
123 | 136 | ||
124 | def allFrontends (): | 137 | def allFrontends (): |
125 | return ['beta', 'gamma', 'mobile'] | 138 | return ['beta', 'gamma', 'gamma.mobile'] |
126 | 139 | ||
127 | def allBackends (): | 140 | def allBackends (): |
128 | return ['php', 'python'] | 141 | return ['php', 'python'] |
129 | 142 | ||
130 | #-------------------------------------------------------------------- | 143 | #-------------------------------------------------------------------- |
131 | 144 | ||
132 | def main (): | 145 | def main (): |
133 | settings = {} | 146 | settings = {} |
134 | parameters = list(itertools.islice(sys.argv, 1, None)) | 147 | parameters = list(itertools.islice(sys.argv, 1, None)) |
135 | 148 | ||
136 | sys.path.append(os.path.join(scriptDir(), 'backends')) | 149 | sys.path.append(os.path.join(scriptDir(), 'backends')) |
150 | sys.path.append(os.path.join(scriptDir(), 'frontends')) | ||
137 | currentRepository = repository.repositoryWithPath(projectBaseDir()) | 151 | currentRepository = repository.repositoryWithPath(projectBaseDir()) |
138 | 152 | ||
139 | clean() | 153 | clean() |
140 | versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) | 154 | versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) |
141 | settings['versions'] = versions; #['debug', 'install', 'development'] | 155 | settings['versions'] = versions; #['debug', 'install', 'development'] |
142 | parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) | 156 | parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) |
143 | 157 | ||
144 | if len(parameters) > 0: | 158 | if len(parameters) > 0: |
145 | parameter = parameters.popleft() | 159 | parameter = parameters.popleft() |
146 | if parameter == "--ALL": | 160 | if parameter == "--ALL": |
147 | settings['frontends'] = allFrontends() | 161 | settings['frontends'] = allFrontends() |
148 | settings['backends'] = allBackends() | 162 | settings['backends'] = allBackends() |
149 | else: | 163 | else: |
150 | while parameter != None: | 164 | while parameter != None: |
151 | values = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) | 165 | values = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) |
152 | 166 | ||
@@ -161,17 +175,17 @@ def main (): | |||
161 | else: | 175 | else: |
162 | parameter = None | 176 | parameter = None |
163 | 177 | ||
164 | if (not settings.has_key('versions')): | 178 | if (not settings.has_key('versions')): |
165 | usage("missing 'versions'") | 179 | usage("missing 'versions'") |
166 | if (not settings.has_key('frontends')): | 180 | if (not settings.has_key('frontends')): |
167 | usage("missing 'frontends'") | 181 | usage("missing 'frontends'") |
168 | if (not settings.has_key('backends')): | 182 | if (not settings.has_key('backends')): |
169 | usage("missing 'backends'") | 183 | usage("missing 'backends'") |
170 | 184 | ||
171 | build(settings, currentRepository) | 185 | build(settings, currentRepository) |
172 | else: | 186 | else: |
173 | usage("Suggestions on how to call the 'build' script:") | 187 | usage("Suggestions on how to call the 'build' script:") |
174 | 188 | ||
175 | 189 | ||
176 | if __name__ == "__main__": | 190 | if __name__ == "__main__": |
177 | main() | 191 | main() |