2011-10-05 10:24:32 +02:00
|
|
|
#!/usr/bin/env python
|
2011-10-03 01:56:18 +02:00
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import json
|
2011-10-03 01:56:18 +02:00
|
|
|
import shutil
|
|
|
|
import pprint
|
|
|
|
import codecs
|
|
|
|
import itertools
|
|
|
|
from collections import deque
|
2012-02-12 00:34:25 +01:00
|
|
|
|
2013-01-08 16:12:19 +01:00
|
|
|
#import frontendBuilder
|
2012-02-12 00:34:25 +01:00
|
|
|
import repository
|
2011-10-03 01:56:18 +02:00
|
|
|
|
|
|
|
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):
|
2012-02-12 00:34:25 +01:00
|
|
|
# print "MODULE: " + module
|
2011-10-03 01:56:18 +02:00
|
|
|
|
|
|
|
if '.' in module:
|
|
|
|
moduleComponents = module.split('.')
|
|
|
|
module = moduleComponents[0]
|
|
|
|
submodule = moduleComponents[1]
|
|
|
|
else:
|
|
|
|
submodule = module
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
#settings = codecs.open(projectBaseDir() + os.sep + component + os.sep + module + os.sep + 'properties' + os.sep + submodule + '.properties.json', 'r', 'utf-8')
|
|
|
|
settings = codecs.open(os.path.join(projectBaseDir(), component, module, 'properties', submodule + '.properties.json'), 'r', 'utf-8')
|
2011-10-03 01:56:18 +02:00
|
|
|
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)
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
builderModuleName = backend + 'Builder'
|
|
|
|
builderClassName = backend.capitalize() + 'Builder'
|
2013-01-08 16:12:19 +01:00
|
|
|
#print ("BUILD BACKENDS - module: " + builderModuleName + " , class: " + builderClassName)
|
2012-02-12 00:34:25 +01:00
|
|
|
builderModule = __import__(builderModuleName)
|
|
|
|
builderClass = getattr(builderModule, builderClassName)
|
|
|
|
|
|
|
|
backendBuilder = builderClass(projectTargetDir(), frontends, versions, settings)
|
2011-10-03 01:56:18 +02:00
|
|
|
backendBuilder.run()
|
|
|
|
|
|
|
|
#====================================================================
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
def build (settings, repository):
|
2011-10-03 01:56:18 +02:00
|
|
|
frontends = []
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
if repository.areTherePendingChanges():
|
2013-01-08 16:12:19 +01:00
|
|
|
if 'install' in settings['versions']:
|
2014-07-28 18:07:48 +02:00
|
|
|
# print "\nWARNING: repository has pending changes\n"
|
2013-01-08 16:12:19 +01:00
|
|
|
raise Exception("repository has pending changes, can't 'install'")
|
|
|
|
else:
|
|
|
|
print "\nWARNING: repository has pending changes\n"
|
2012-02-12 00:34:25 +01:00
|
|
|
|
2011-10-03 01:56:18 +02:00
|
|
|
for frontend in settings['frontends']:
|
2013-01-08 16:12:19 +01:00
|
|
|
normalizedFrontendName = frontend.replace(".", "_")
|
|
|
|
builderModuleName = normalizedFrontendName + 'Builder'
|
|
|
|
builderClassName = normalizedFrontendName.title() + 'Builder'
|
|
|
|
|
|
|
|
#print ("BUILD FRONTEND - module: " + builderModuleName + " , class: " + builderClassName)
|
|
|
|
builderModule = __import__(builderModuleName)
|
|
|
|
builderClass = getattr(builderModule, builderClassName)
|
|
|
|
builder = builderClass(frontend, loadSettings('frontend', frontend), repository.version())
|
|
|
|
#builder = frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend), repository.version())
|
|
|
|
frontends.append(builder)
|
2011-10-03 01:56:18 +02:00
|
|
|
|
|
|
|
for backend in settings['backends']:
|
|
|
|
assembleBackend(backend, frontends, settings['versions'])
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
|
|
|
|
def clean ():
|
2012-02-12 00:34:25 +01:00
|
|
|
# print "cleaning up …"
|
2011-10-03 01:56:18 +02:00
|
|
|
if os.path.exists(projectTargetDir()):
|
|
|
|
shutil.rmtree(projectTargetDir())
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
|
|
|
|
def usage (message):
|
|
|
|
if message != None:
|
|
|
|
print "ERROR: " + message
|
|
|
|
|
|
|
|
print
|
2012-02-12 00:34:25 +01:00
|
|
|
# print "build clean"
|
|
|
|
# print "build clean install"
|
|
|
|
print "build install --ALL"
|
|
|
|
print "build install debug --ALL"
|
2013-01-08 16:12:19 +01:00
|
|
|
print "build install debug development --ALL"
|
2012-02-12 00:34:25 +01:00
|
|
|
# print "build clean install debug --ALL"
|
|
|
|
print "build install debug --backends php python --frontends beta gamma"
|
|
|
|
print "build install debug development --backends php python --frontends beta gamma gamma.mobile"
|
2011-10-03 01:56:18 +02:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
def allFrontends ():
|
2014-07-28 18:07:48 +02:00
|
|
|
return ['beta', 'gamma', 'delta']
|
2012-02-12 00:34:25 +01:00
|
|
|
|
|
|
|
def allBackends ():
|
|
|
|
return ['php', 'python']
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
|
2011-10-03 01:56:18 +02:00
|
|
|
def main ():
|
|
|
|
settings = {}
|
|
|
|
parameters = list(itertools.islice(sys.argv, 1, None))
|
2012-02-12 00:34:25 +01:00
|
|
|
|
|
|
|
sys.path.append(os.path.join(scriptDir(), 'backends'))
|
2013-01-08 16:12:19 +01:00
|
|
|
sys.path.append(os.path.join(scriptDir(), 'frontends'))
|
2012-02-12 00:34:25 +01:00
|
|
|
currentRepository = repository.repositoryWithPath(projectBaseDir())
|
|
|
|
|
|
|
|
clean()
|
2011-10-03 01:56:18 +02:00
|
|
|
versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters))
|
2013-04-17 17:45:39 +02:00
|
|
|
settings['versions'] = versions; #['debug', 'install', 'development', 'checksum']
|
2011-10-03 01:56:18 +02:00
|
|
|
parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters))
|
|
|
|
|
|
|
|
if len(parameters) > 0:
|
|
|
|
parameter = parameters.popleft()
|
|
|
|
if parameter == "--ALL":
|
2012-02-12 00:34:25 +01:00
|
|
|
settings['frontends'] = allFrontends()
|
|
|
|
settings['backends'] = allBackends()
|
2011-10-03 01:56:18 +02:00
|
|
|
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
|
|
|
|
|
2013-04-17 17:45:39 +02:00
|
|
|
if 'checksum' in settings['versions']:
|
|
|
|
if not 'backends' in settings:
|
|
|
|
settings['backends'] = []
|
|
|
|
settings['backends'].append('checksum')
|
|
|
|
|
2011-10-03 01:56:18 +02:00
|
|
|
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'")
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
build(settings, currentRepository)
|
|
|
|
else:
|
|
|
|
usage("Suggestions on how to call the 'build' script:")
|
2011-10-03 01:56:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2013-01-08 16:12:19 +01:00
|
|
|
main()
|