summaryrefslogtreecommitdiff
authorGiulio Cesare Solaroli <giulio.cesare@clipperz.com>2013-04-17 15:45:39 (UTC)
committer Giulio Cesare Solaroli <giulio.cesare@clipperz.com>2013-04-17 15:45:39 (UTC)
commit48c9280c9a255f2a85ad5729830df884e64a9c5d (patch) (side-by-side diff)
tree14787438153cdc0b4b445c66f046bccf3dd99ee2
parent4ce8041b11afc7f02c678565e0e96e59a5a557b6 (diff)
downloadclipperz-48c9280c9a255f2a85ad5729830df884e64a9c5d.zip
clipperz-48c9280c9a255f2a85ad5729830df884e64a9c5d.tar.gz
clipperz-48c9280c9a255f2a85ad5729830df884e64a9c5d.tar.bz2
Updated build script to handle 'checksum' target
The build script can now be invoked, for example, with the following options: > ./scripts/build checksum --frontend beta gamma
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--backend/checksum/properties/checksum.properties.json4
-rwxr-xr-x[-rw-r--r--]scripts/builder/backendBuilder.py2
-rwxr-xr-xscripts/builder/backends/checksumBuilder.py50
-rwxr-xr-x[-rw-r--r--]scripts/builder/backends/devBuilder.py8
-rwxr-xr-xscripts/builder/main.py7
-rwxr-xr-x[-rw-r--r--]scripts/builder/repository.py0
6 files changed, 62 insertions, 9 deletions
diff --git a/backend/checksum/properties/checksum.properties.json b/backend/checksum/properties/checksum.properties.json
new file mode 100644
index 0000000..1c2dae5
--- a/dev/null
+++ b/backend/checksum/properties/checksum.properties.json
@@ -0,0 +1,4 @@
+{
+ "request.path": "json",
+ "should.pay.toll": "true"
+} \ No newline at end of file
diff --git a/scripts/builder/backendBuilder.py b/scripts/builder/backendBuilder.py
index 20b4bd0..b4ee990 100644..100755
--- a/scripts/builder/backendBuilder.py
+++ b/scripts/builder/backendBuilder.py
@@ -1,143 +1,145 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys, os, json
import shutil
import hashlib
from functools import reduce
from operator import add
from itertools import izip
import main
#===================================================================
class BackendBuilder(object):
def __init__ (self, projectTargetDir, frontends, versions, settings):
self.projectTargetDir = projectTargetDir
self.frontends = frontends
self.versions = versions
self.settings = settings
# --------------------------------------------------------------------------
def name (self):
raise NotImplementedError()
def relativePath (self):
raise NotImplementedError()
def compileCode (self):
raise NotImplementedError()
def createPackage (self):
raise NotImplementedError()
# --------------------------------------------------------------------------
def sourceFolder (self):
return os.path.join(main.projectBaseDir() , 'backend', self.relativePath(), 'src')
def tempFolder (self):
return os.path.join(self.projectTargetDir, '.tmp', self.relativePath())
def frontEndTempFolder (self):
return self.tempFolder()
def developmentTargetFolder (self):
return os.path.join(self.projectTargetDir, 'development')
def targetFolder (self):
return os.path.join(self.projectTargetDir, self.relativePath())
# --------------------------------------------------------------------------
def writeToFolder (self, folder, filename, content):
file = open(os.path.join(folder, filename), 'w')
file.write(content.encode('utf-8'))
file.close()
def configureIndexContent (self, indexContent, requestPathPrefix = ".."):
result = indexContent
result = result.replace( '@request.path@', requestPathPrefix + '/' + self.settings['request.path'] )
result = result.replace( '@should.pay.toll@', self.settings['should.pay.toll'] )
return result
def formatMAC (self, value):
x = iter(value)
return ' '.join([reduce(add, tup) for tup in izip(x, x, x, x)])
def logChecksums (self, content, message):
md5Digest = self.formatMAC(hashlib.md5(content.encode('utf-8')).hexdigest())
shaDigest = self.formatMAC(hashlib.sha1(content.encode('utf-8')).hexdigest())
sha256Digest = self.formatMAC(hashlib.sha256(content.encode('utf-8')).hexdigest())
+ print "-----"
print message + ": " + md5Digest + " (md5)"
print message + ": " + shaDigest + " (sha1)"
print message + ": " + sha256Digest + " (sha256)"
+ print "====="
def shouldCompileCode (self):
return ('debug' in self.versions) or ('install' in self.versions)
def run (self):
print self.name() + " - RUN"
if self.shouldCompileCode():
self.compileCode()
for frontend in self.frontends:
if (frontend.module == frontend.submodule):
submoduleExtension = ''
else:
submoduleExtension = '.' + frontend.submodule
main.createFolder(os.path.join(self.frontEndTempFolder(), frontend.module))
if 'debug' in self.versions:
frontend.copyResourcesToFolder(self.frontEndTempFolder())
index = self.configureIndexContent(frontend.assemble(assemblyMode='DEBUG', versionType='DEBUG'))
self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index_debug' + submoduleExtension + '.html'), index)
if 'install' in self.versions:
index = self.configureIndexContent(frontend.assemble())
self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index' + submoduleExtension + '.html'), index)
self.logChecksums(index, "[" + self.name() + " - " + frontend.module + "] index" + submoduleExtension + ".html checksum")
self.createPackage()
# if 'development' in self.versions:
# for frontend in self.frontends:
# if (frontend.module == frontend.submodule):
# submoduleExtension = ''
# else:
# submoduleExtension = '.' + frontend.submodule
#
# print "FRONTEND module: " + frontend.module
# print "FRONTEND submodule: " + frontend.submodule
#
## main.createFolder(os.path.join(self.developmentTargetFolder(), frontend.module))
# main.createFolder(self.developmentTargetFolder())
#
# index = self.configureIndexContent(frontend.assemble(assemblyMode='DEVELOPMENT', versionType='DEBUG'), self.settings['development.settings']['url'])
## self.writeToFolder(self.developmentTargetFolder(), os.path.join(frontend.module, 'index_development' + submoduleExtension + '.html'), index)
# self.writeToFolder(self.developmentTargetFolder(), os.path.join(frontend.module + submoduleExtension + '.html'), index)
#===================================================================
diff --git a/scripts/builder/backends/checksumBuilder.py b/scripts/builder/backends/checksumBuilder.py
new file mode 100755
index 0000000..5f44c8a
--- a/dev/null
+++ b/scripts/builder/backends/checksumBuilder.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+import os
+import shutil
+import subprocess
+import main
+
+from backendBuilder import BackendBuilder
+
+class ChecksumBuilder(BackendBuilder):
+
+ def name(self):
+ return "Checksum builder"
+
+
+ def relativePath(self):
+ return 'checksum'
+
+
+ def compileCode (self):
+ pass
+
+
+ def createPackage (self):
+ src = self.tempFolder()
+ dst = self.targetFolder()
+
+ shutil.copytree(src, dst)
+
+
+ def run (self):
+ print self.name() + " - RUN (checksum)"
+
+ for frontend in self.frontends:
+ if (frontend.module == frontend.submodule):
+ submoduleExtension = ''
+ else:
+ submoduleExtension = '.' + frontend.submodule
+
+ main.createFolder(os.path.join(self.frontEndTempFolder(), frontend.module))
+
+ index = self.configureIndexContent(frontend.assemble())
+ self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index' + submoduleExtension + '.html'), index)
+ self.logChecksums(index, "[" + self.name() + " - " + frontend.module + "] index" + submoduleExtension + ".html checksum")
+ print ""
+
+ self.createPackage()
+
+
diff --git a/scripts/builder/backends/devBuilder.py b/scripts/builder/backends/devBuilder.py
index 671765e..354e014 100644..100755
--- a/scripts/builder/backends/devBuilder.py
+++ b/scripts/builder/backends/devBuilder.py
@@ -1,56 +1,48 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
import shutil
import subprocess
import main
from backendBuilder import BackendBuilder
class DevBuilder(BackendBuilder):
def name(self):
return "Dev builder"
def relativePath(self):
return 'dev'
-# def frontEndTempFolder (self):
-# return os.path.join(self.tempFolder(), 'src', 'main', 'webapp')
-
-
-# def targetFolder (self):
-# return self.projectTargetDir
-
-
def compileCode (self):
pass
def createPackage (self):
src = self.tempFolder()
dst = self.targetFolder()
shutil.copytree(src, dst)
def run (self):
print self.name() + " - RUN (dev)"
for frontend in self.frontends:
if (frontend.module == frontend.submodule):
submoduleExtension = ''
else:
submoduleExtension = '.' + frontend.submodule
main.createFolder(os.path.join(self.frontEndTempFolder(), frontend.module))
index = self.configureIndexContent(frontend.assemble(assemblyMode='DEBUG', versionType='DEBUG'))
self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index' + submoduleExtension + '.html'), index)
self.createPackage()
diff --git a/scripts/builder/main.py b/scripts/builder/main.py
index b9fe04a..ecdbf6a 100755
--- a/scripts/builder/main.py
+++ b/scripts/builder/main.py
@@ -59,133 +59,138 @@ def loadSettings (component, module):
# 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)
builderModuleName = backend + 'Builder'
builderClassName = backend.capitalize() + 'Builder'
#print ("BUILD BACKENDS - module: " + builderModuleName + " , class: " + builderClassName)
builderModule = __import__(builderModuleName)
builderClass = getattr(builderModule, builderClassName)
backendBuilder = builderClass(projectTargetDir(), frontends, versions, settings)
backendBuilder.run()
#====================================================================
def build (settings, repository):
frontends = []
if repository.areTherePendingChanges():
if 'install' in settings['versions']:
raise Exception("repository has pending changes, can't 'install'")
else:
print "\nWARNING: repository has pending changes\n"
for frontend in settings['frontends']:
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)
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 clean"
# print "build clean install"
print "build install --ALL"
print "build install debug --ALL"
print "build install debug development --ALL"
# 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"
exit(1)
#--------------------------------------------------------------------
def allFrontends ():
return ['beta', 'gamma', 'gamma.mobile']
def allBackends ():
return ['php', 'python']
#--------------------------------------------------------------------
def main ():
settings = {}
parameters = list(itertools.islice(sys.argv, 1, None))
sys.path.append(os.path.join(scriptDir(), 'backends'))
sys.path.append(os.path.join(scriptDir(), 'frontends'))
currentRepository = repository.repositoryWithPath(projectBaseDir())
clean()
versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters))
- settings['versions'] = versions; #['debug', 'install', 'development']
+ settings['versions'] = versions; #['debug', 'install', 'development', 'checksum']
parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters))
if len(parameters) > 0:
parameter = parameters.popleft()
if parameter == "--ALL":
settings['frontends'] = allFrontends()
settings['backends'] = allBackends()
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 'checksum' in settings['versions']:
+ if not 'backends' in settings:
+ settings['backends'] = []
+ settings['backends'].append('checksum')
+
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, currentRepository)
else:
usage("Suggestions on how to call the 'build' script:")
if __name__ == "__main__":
main()
diff --git a/scripts/builder/repository.py b/scripts/builder/repository.py
index 2d4a12b..2d4a12b 100644..100755
--- a/scripts/builder/repository.py
+++ b/scripts/builder/repository.py