-rwxr-xr-x | scripts/builder/main.py | 85 |
1 files changed, 48 insertions, 37 deletions
diff --git a/scripts/builder/main.py b/scripts/builder/main.py index 94f738f..6fce65d 100755 --- a/scripts/builder/main.py +++ b/scripts/builder/main.py | |||
@@ -1,16 +1,17 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
2 | # -*- coding: UTF-8 -*- | 2 | # -*- coding: UTF-8 -*- |
3 | 3 | ||
4 | import sys, os, json | 4 | import sys |
5 | import os | ||
6 | import json | ||
5 | import shutil | 7 | import shutil |
6 | import pprint | 8 | import pprint |
7 | import frontendBuilder | ||
8 | import codecs | 9 | import codecs |
9 | import itertools | 10 | import itertools |
10 | |||
11 | from collections import deque | 11 | from collections import deque |
12 | from phpBuilder import PhpBuilder | 12 | |
13 | from pythonBuilder import PythonBuilder | 13 | import frontendBuilder |
14 | import repository | ||
14 | 15 | ||
15 | pp = pprint.PrettyPrinter(indent=4, depth=4) | 16 | pp = pprint.PrettyPrinter(indent=4, depth=4) |
16 | 17 | ||
@@ -34,7 +35,7 @@ def createFolder (path): | |||
34 | #-------------------------------------------------------------------- | 35 | #-------------------------------------------------------------------- |
35 | 36 | ||
36 | def loadSettings (component, module): | 37 | def loadSettings (component, module): |
37 | print "MODULE: " + module | 38 | # print "MODULE: " + module |
38 | 39 | ||
39 | if '.' in module: | 40 | if '.' in module: |
40 | moduleComponents = module.split('.') | 41 | moduleComponents = module.split('.') |
@@ -43,7 +44,8 @@ def loadSettings (component, module): | |||
43 | else: | 44 | else: |
44 | submodule = module | 45 | submodule = module |
45 | 46 | ||
46 | settings = codecs.open(projectBaseDir() + '/' + component + '/' + module + '/properties/' + submodule + '.properties.json', 'r', 'utf-8') | 47 | #settings = codecs.open(projectBaseDir() + os.sep + component + os.sep + module + os.sep + 'properties' + os.sep + submodule + '.properties.json', 'r', 'utf-8') |
48 | settings = codecs.open(os.path.join(projectBaseDir(), component, module, 'properties', submodule + '.properties.json'), 'r', 'utf-8') | ||
47 | result = json.load(settings) | 49 | result = json.load(settings) |
48 | settings.close | 50 | settings.close |
49 | 51 | ||
@@ -71,24 +73,25 @@ def loadSettings (component, module): | |||
71 | def assembleBackend (backend, frontends, versions): | 73 | def assembleBackend (backend, frontends, versions): |
72 | settings = loadSettings('backend', backend) | 74 | settings = loadSettings('backend', backend) |
73 | 75 | ||
74 | if backend == 'php': | 76 | builderModuleName = backend + 'Builder' |
75 | backendBuilder = PhpBuilder(projectTargetDir(), frontends, versions, settings) | 77 | builderClassName = backend.capitalize() + 'Builder' |
76 | elif backend == 'python': | 78 | |
77 | backendBuilder = PythonBuilder(projectTargetDir(), frontends, versions, settings) | 79 | builderModule = __import__(builderModuleName) |
78 | #elif backend == 'java': | 80 | builderClass = getattr(builderModule, builderClassName) |
79 | #buildJavaBackend (frontends, versions, settings) | 81 | |
80 | else: | 82 | backendBuilder = builderClass(projectTargetDir(), frontends, versions, settings) |
81 | raise Exception('unrecognized backend: ' + backend) | ||
82 | |||
83 | backendBuilder.run() | 83 | backendBuilder.run() |
84 | 84 | ||
85 | #==================================================================== | 85 | #==================================================================== |
86 | 86 | ||
87 | def build (settings): | 87 | def build (settings, repository): |
88 | frontends = [] | 88 | frontends = [] |
89 | 89 | ||
90 | if repository.areTherePendingChanges(): | ||
91 | print "\nWARNING: repository has pending changes\n" | ||
92 | |||
90 | for frontend in settings['frontends']: | 93 | for frontend in settings['frontends']: |
91 | frontends.append(frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend))) | 94 | frontends.append(frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend), repository.version())) |
92 | 95 | ||
93 | for backend in settings['backends']: | 96 | for backend in settings['backends']: |
94 | assembleBackend(backend, frontends, settings['versions']) | 97 | assembleBackend(backend, frontends, settings['versions']) |
@@ -96,7 +99,7 @@ def build (settings): | |||
96 | #-------------------------------------------------------------------- | 99 | #-------------------------------------------------------------------- |
97 | 100 | ||
98 | def clean (): | 101 | def clean (): |
99 | print "cleaning up …" | 102 | # print "cleaning up …" |
100 | if os.path.exists(projectTargetDir()): | 103 | if os.path.exists(projectTargetDir()): |
101 | shutil.rmtree(projectTargetDir()) | 104 | shutil.rmtree(projectTargetDir()) |
102 | 105 | ||
@@ -107,35 +110,42 @@ def usage (message): | |||
107 | print "ERROR: " + message | 110 | print "ERROR: " + message |
108 | 111 | ||
109 | 112 | ||
110 | print "build.py clean" | 113 | # print "build clean" |
111 | print "build.py clean install" | 114 | # print "build clean install" |
112 | print "build.py install --ALL" | 115 | print "build install --ALL" |
113 | print "build.py install debug --ALL" | 116 | print "build install debug --ALL" |
114 | print "build.py clean install debug --ALL" | 117 | # print "build clean install debug --ALL" |
115 | print "build.ph install, debug --backends php java --frontends beta gamma" | 118 | print "build install debug --backends php python --frontends beta gamma" |
116 | print "build.ph install, debug --backends php java --frontends beta gamma gamma.mobile" | 119 | print "build install debug development --backends php python --frontends beta gamma gamma.mobile" |
117 | exit(1) | 120 | exit(1) |
118 | 121 | ||
119 | #-------------------------------------------------------------------- | 122 | #-------------------------------------------------------------------- |
120 | 123 | ||
124 | def allFrontends (): | ||
125 | return ['beta', 'gamma', 'mobile'] | ||
126 | |||
127 | def allBackends (): | ||
128 | return ['php', 'python'] | ||
129 | |||
130 | #-------------------------------------------------------------------- | ||
131 | |||
121 | def main (): | 132 | def main (): |
122 | settings = {} | 133 | settings = {} |
123 | parameters = list(itertools.islice(sys.argv, 1, None)) | 134 | parameters = list(itertools.islice(sys.argv, 1, None)) |
124 | 135 | ||
125 | shouldClean = len(filter(lambda x: x == 'clean', parameters)) > 0 | 136 | sys.path.append(os.path.join(scriptDir(), 'backends')) |
126 | if (shouldClean): | 137 | currentRepository = repository.repositoryWithPath(projectBaseDir()) |
127 | clean () | 138 | |
128 | 139 | clean() | |
129 | parameters = filter(lambda x: x != 'clean', parameters) | ||
130 | versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) | 140 | versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) |
131 | settings['versions'] = versions; #['debug', 'install'] | 141 | settings['versions'] = versions; #['debug', 'install', 'development'] |
132 | parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) | 142 | parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) |
133 | 143 | ||
134 | if len(parameters) > 0: | 144 | if len(parameters) > 0: |
135 | parameter = parameters.popleft() | 145 | parameter = parameters.popleft() |
136 | if parameter == "--ALL": | 146 | if parameter == "--ALL": |
137 | settings['frontends'] = ['beta', 'gamma', 'mobile'] | 147 | settings['frontends'] = allFrontends() |
138 | settings['backends'] = ['php', 'python', 'java'] | 148 | settings['backends'] = allBackends() |
139 | else: | 149 | else: |
140 | while parameter != None: | 150 | while parameter != None: |
141 | values = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) | 151 | values = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) |
@@ -158,8 +168,9 @@ def main (): | |||
158 | if (not settings.has_key('backends')): | 168 | if (not settings.has_key('backends')): |
159 | usage("missing 'backends'") | 169 | usage("missing 'backends'") |
160 | 170 | ||
161 | build (settings) | 171 | build(settings, currentRepository) |
162 | 172 | else: | |
173 | usage("Suggestions on how to call the 'build' script:") | ||
163 | 174 | ||
164 | 175 | ||
165 | if __name__ == "__main__": | 176 | if __name__ == "__main__": |