2011-10-05 10:24:32 +02:00
|
|
|
#!/usr/bin/env python
|
2011-10-03 01:56:18 +02:00
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
|
|
|
|
import sys, os, json
|
|
|
|
import shutil
|
|
|
|
import hashlib
|
|
|
|
|
2013-01-18 18:17:26 +01:00
|
|
|
from functools import reduce
|
|
|
|
from operator import add
|
|
|
|
from itertools import izip
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
import main
|
|
|
|
|
|
|
|
#===================================================================
|
|
|
|
|
|
|
|
class BackendBuilder(object):
|
2011-10-03 01:56:18 +02:00
|
|
|
|
|
|
|
def __init__ (self, projectTargetDir, frontends, versions, settings):
|
|
|
|
self.projectTargetDir = projectTargetDir
|
|
|
|
self.frontends = frontends
|
|
|
|
self.versions = versions
|
|
|
|
self.settings = settings
|
2012-02-12 00:34:25 +01:00
|
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
2011-10-03 01:56:18 +02:00
|
|
|
|
|
|
|
def name (self):
|
|
|
|
raise NotImplementedError()
|
2012-02-12 00:34:25 +01:00
|
|
|
|
2011-10-03 01:56:18 +02:00
|
|
|
|
|
|
|
def relativePath (self):
|
|
|
|
raise NotImplementedError()
|
2012-02-12 00:34:25 +01:00
|
|
|
|
2011-10-03 01:56:18 +02:00
|
|
|
|
|
|
|
def compileCode (self):
|
2012-02-12 00:34:25 +01:00
|
|
|
raise NotImplementedError()
|
|
|
|
|
2011-10-03 01:56:18 +02:00
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
def createPackage (self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
2011-10-03 01:56:18 +02:00
|
|
|
|
|
|
|
def sourceFolder (self):
|
2012-02-12 00:34:25 +01:00
|
|
|
return os.path.join(main.projectBaseDir() , 'backend', self.relativePath(), 'src')
|
2011-10-03 01:56:18 +02:00
|
|
|
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
def tempFolder (self):
|
|
|
|
return os.path.join(self.projectTargetDir, '.tmp', self.relativePath())
|
|
|
|
|
|
|
|
|
|
|
|
def frontEndTempFolder (self):
|
|
|
|
return self.tempFolder()
|
|
|
|
|
2011-10-03 01:56:18 +02:00
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
def developmentTargetFolder (self):
|
2013-01-08 16:12:19 +01:00
|
|
|
return os.path.join(self.projectTargetDir, 'development')
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
|
|
|
|
def targetFolder (self):
|
|
|
|
return os.path.join(self.projectTargetDir, self.relativePath())
|
2013-01-08 16:12:19 +01:00
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def writeToFolder (self, folder, filename, content):
|
|
|
|
file = open(os.path.join(folder, filename), 'w')
|
2011-10-03 01:56:18 +02:00
|
|
|
file.write(content.encode('utf-8'))
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
|
2013-08-30 17:56:53 +02:00
|
|
|
# def configureIndexContent (self, indexContent, requestPathPrefix = ".."):
|
|
|
|
def configureIndexContent (self, indexContent):
|
2011-10-03 01:56:18 +02:00
|
|
|
result = indexContent
|
2013-08-30 17:56:53 +02:00
|
|
|
# result = result.replace( '@request.path@', requestPathPrefix + '/' + self.settings['request.path'] )
|
|
|
|
result = result.replace( '@request.path@', self.settings['request.path'] )
|
|
|
|
result = result.replace( '@dump.path@', self.settings['dump.path'] )
|
2011-10-03 01:56:18 +02:00
|
|
|
result = result.replace( '@should.pay.toll@', self.settings['should.pay.toll'] )
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2013-01-18 18:17:26 +01:00
|
|
|
def formatMAC (self, value):
|
|
|
|
x = iter(value)
|
|
|
|
return ' '.join([reduce(add, tup) for tup in izip(x, x, x, x)])
|
|
|
|
|
|
|
|
|
2011-10-03 01:56:18 +02:00
|
|
|
def logChecksums (self, content, message):
|
2013-01-18 18:17:26 +01:00
|
|
|
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())
|
2013-04-17 17:45:39 +02:00
|
|
|
print "-----"
|
2011-10-03 01:56:18 +02:00
|
|
|
print message + ": " + md5Digest + " (md5)"
|
|
|
|
print message + ": " + shaDigest + " (sha1)"
|
|
|
|
print message + ": " + sha256Digest + " (sha256)"
|
2014-07-28 18:07:48 +02:00
|
|
|
print "file size: " + "{:,}".format(len(content))
|
2013-04-17 17:45:39 +02:00
|
|
|
print "====="
|
2011-10-03 01:56:18 +02:00
|
|
|
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
def shouldCompileCode (self):
|
|
|
|
return ('debug' in self.versions) or ('install' in self.versions)
|
|
|
|
|
2011-10-03 01:56:18 +02:00
|
|
|
|
|
|
|
def run (self):
|
|
|
|
print self.name() + " - RUN"
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
if self.shouldCompileCode():
|
|
|
|
self.compileCode()
|
2011-10-03 01:56:18 +02:00
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
for frontend in self.frontends:
|
2012-03-17 15:26:08 +01:00
|
|
|
if (frontend.module == frontend.submodule):
|
|
|
|
submoduleExtension = ''
|
|
|
|
else:
|
|
|
|
submoduleExtension = '.' + frontend.submodule
|
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
main.createFolder(os.path.join(self.frontEndTempFolder(), frontend.module))
|
2015-09-10 15:13:26 +02:00
|
|
|
frontend.copyResourcesToFolder(self.frontEndTempFolder(), self.settings)
|
2012-02-12 00:34:25 +01:00
|
|
|
|
|
|
|
if 'debug' in self.versions:
|
2014-07-28 18:07:48 +02:00
|
|
|
frontend.copyDebugResourcesToFolder(self.frontEndTempFolder())
|
2012-02-12 00:34:25 +01:00
|
|
|
index = self.configureIndexContent(frontend.assemble(assemblyMode='DEBUG', versionType='DEBUG'))
|
2012-03-17 15:26:08 +01:00
|
|
|
self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index_debug' + submoduleExtension + '.html'), index)
|
2013-01-08 16:12:19 +01:00
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
if 'install' in self.versions:
|
2015-09-10 15:13:26 +02:00
|
|
|
# frontend.copyResourcesToFolder(self.frontEndTempFolder(), self.settings)
|
2012-02-12 00:34:25 +01:00
|
|
|
index = self.configureIndexContent(frontend.assemble())
|
2012-03-17 15:26:08 +01:00
|
|
|
self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index' + submoduleExtension + '.html'), index)
|
2012-02-12 00:34:25 +01:00
|
|
|
|
2012-03-17 15:26:08 +01:00
|
|
|
self.logChecksums(index, "[" + self.name() + " - " + frontend.module + "] index" + submoduleExtension + ".html checksum")
|
2011-10-03 01:56:18 +02:00
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
self.createPackage()
|
|
|
|
|
2013-01-08 16:12:19 +01:00
|
|
|
# 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)
|
2012-02-12 00:34:25 +01:00
|
|
|
|
2011-10-03 01:56:18 +02:00
|
|
|
|
2012-02-12 00:34:25 +01:00
|
|
|
#===================================================================
|