summaryrefslogtreecommitdiff
path: root/scripts/builder/main.py
blob: 94f738f0e8ab2af5ca4360e74db515a0e873b8f2 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys, os, json
import shutil
import pprint
import frontendBuilder
import codecs
import itertools

from collections   import deque
from phpBuilder    import PhpBuilder
from pythonBuilder import PythonBuilder

pp = pprint.PrettyPrinter(indent=4, depth=4)

#--------------------------------------------------------------------

def scriptDir ():
	return  os.path.dirname(sys.argv[0])

def projectBaseDir ():
	return os.path.abspath(scriptDir() + '/../..')

def projectTargetDir(): 
	return projectBaseDir() + '/target/'

#--------------------------------------------------------------------

def createFolder (path):
	if not os.path.exists(path):
		os.makedirs(path)

#--------------------------------------------------------------------

def loadSettings (component, module):
	print "MODULE: " + module

	if '.' in module:
		moduleComponents = module.split('.')
		module = moduleComponents[0]
		submodule = moduleComponents[1]
	else:
		submodule = module

	settings = codecs.open(projectBaseDir() + '/' + component + '/' + module + '/properties/' + submodule + '.properties.json', 'r', 'utf-8')
	result = json.load(settings)
	settings.close

	return result

#====================================================================
# 
# def assembleFrontend (frontend, versions):
# 	result = {}
# 	settings = loadSettings('frontend', frontend)
# 	builder = frontendBuilder.FrontendBuilder(frontend, settings, projectBaseDir())
# 	
# 	for version in versions:
# 		if version == 'install':
# 			result[version] = builder.assembleInstallVersion()
# 		elif version == 'debug':
# 			result[version] = builder.assembleDebugVersion()
# 		else:
# 			raise Exception('unrecognized version: ' + version)
# 	
# 	return result
# 
#====================================================================

def assembleBackend (backend, frontends, versions):
	settings = loadSettings('backend', backend)
	
	if backend == 'php':
		backendBuilder = PhpBuilder(projectTargetDir(), frontends, versions, settings)
	elif backend == 'python':
		backendBuilder = PythonBuilder(projectTargetDir(), frontends, versions, settings)
	#elif backend == 'java':
	#	buildJavaBackend (frontends, versions, settings)
	else:
		raise Exception('unrecognized backend: ' + backend)
		
	backendBuilder.run()	

#====================================================================

def build (settings):
	frontends = []
	
	for frontend in settings['frontends']:
		frontends.append(frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend)))

	for backend in settings['backends']:
		assembleBackend(backend, frontends, settings['versions'])

#--------------------------------------------------------------------

def clean ():
	print "cleaning up …"
	if os.path.exists(projectTargetDir()):
		shutil.rmtree(projectTargetDir())

#--------------------------------------------------------------------

def usage (message):
	if message != None:
		print "ERROR: " + message
	
	print
	print "build.py clean"
	print "build.py clean install"
	print "build.py install --ALL"
	print "build.py install debug --ALL"
	print "build.py clean install debug --ALL"
	print "build.ph install, debug --backends php java --frontends beta gamma"
	print "build.ph install, debug --backends php java --frontends beta gamma gamma.mobile"
	exit(1)

#--------------------------------------------------------------------

def main ():
	settings = {}
	parameters = list(itertools.islice(sys.argv, 1, None))
	
	shouldClean = len(filter(lambda x: x == 'clean', parameters)) > 0
	if (shouldClean):
		clean ()
	
	parameters = filter(lambda x: x != 'clean', parameters)
	versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters))
	settings['versions']  = versions;		#['debug',  'install']
	parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters))
	
	if len(parameters) > 0:
		parameter = parameters.popleft()
		if parameter == "--ALL":
			settings['frontends'] = ['beta', 'gamma',  'mobile']
			settings['backends']  = ['php',  'python', 'java']
		else:
			while parameter != None:
				values = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters))
			
				if parameter == "--backends":
					settings['backends'] = values
				elif parameter == "--frontends":
					settings['frontends'] = values
			
				parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters))
				if parameters:
					parameter = parameters.popleft()
				else:
					parameter = None
	
		if (not settings.has_key('versions')):
			usage("missing 'versions'")
		if (not settings.has_key('frontends')):
			usage("missing 'frontends'")
		if (not settings.has_key('backends')):
			usage("missing 'backends'")
		
		build (settings)
	


if __name__ == "__main__":
    main()