summaryrefslogtreecommitdiff
path: root/scripts/builder/main.py
Unidiff
Diffstat (limited to 'scripts/builder/main.py') (more/less context) (ignore whitespace changes)
-rwxr-xr-xscripts/builder/main.py85
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
4import sys, os, json 4import sys
5import os
6import json
5import shutil 7import shutil
6import pprint 8import pprint
7import frontendBuilder
8import codecs 9import codecs
9import itertools 10import itertools
10
11from collections import deque 11from collections import deque
12from phpBuilder import PhpBuilder 12
13from pythonBuilder import PythonBuilder 13import frontendBuilder
14import repository
14 15
15pp = pprint.PrettyPrinter(indent=4, depth=4) 16pp = pprint.PrettyPrinter(indent=4, depth=4)
16 17
@@ -34,7 +35,7 @@ def createFolder (path):
34#-------------------------------------------------------------------- 35#--------------------------------------------------------------------
35 36
36def loadSettings (component, module): 37def 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):
71def assembleBackend (backend, frontends, versions): 73def 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
87def build (settings): 87def 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
98def clean (): 101def 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 print 112 print
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
124def allFrontends ():
125 return ['beta', 'gamma', 'mobile']
126
127def allBackends ():
128 return ['php', 'python']
129
130#--------------------------------------------------------------------
131
121def main (): 132def 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
165if __name__ == "__main__": 176if __name__ == "__main__":