-rwxr-xr-x | scripts/builder/backendBuilder.py | 7 | ||||
-rw-r--r--[-rwxr-xr-x] | scripts/builder/backends/phpBuilder.py | 0 | ||||
-rw-r--r-- | scripts/builder/frontendBuilder.py | 69 | ||||
-rw-r--r-- | scripts/builder/frontends/betaBuilder.py | 3 | ||||
-rw-r--r-- | scripts/builder/frontends/deltaBuilder.py | 16 | ||||
-rw-r--r-- | scripts/builder/frontends/gammaBuilder.py | 3 | ||||
-rw-r--r-- | scripts/builder/frontends/gamma_mobileBuilder.py | 3 | ||||
-rwxr-xr-x | scripts/proxy/main.py | 19 |
8 files changed, 58 insertions, 62 deletions
diff --git a/scripts/builder/backendBuilder.py b/scripts/builder/backendBuilder.py index b4ee990..ad6595c 100755 --- a/scripts/builder/backendBuilder.py +++ b/scripts/builder/backendBuilder.py @@ -23,99 +23,102 @@ class BackendBuilder(object): # -------------------------------------------------------------------------- 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 = ".."): +# def configureIndexContent (self, indexContent, requestPathPrefix = ".."): + def configureIndexContent (self, indexContent): result = indexContent - result = result.replace( '@request.path@', requestPathPrefix + '/' + self.settings['request.path'] ) +# 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'] ) 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) diff --git a/scripts/builder/backends/phpBuilder.py b/scripts/builder/backends/phpBuilder.py index c928aa0..c928aa0 100755..100644 --- a/scripts/builder/backends/phpBuilder.py +++ b/scripts/builder/backends/phpBuilder.py diff --git a/scripts/builder/frontendBuilder.py b/scripts/builder/frontendBuilder.py index e52c31e..b72179f 100644 --- a/scripts/builder/frontendBuilder.py +++ b/scripts/builder/frontendBuilder.py @@ -1,146 +1,150 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- import sys, os, re import cssmin import jsmin import codecs import shutil import StringIO import urllib import main #=============================================================================== class FrontendBuilder(object): def __init__ (self, frontend, settings, repositoryVersion): if '.' in frontend: moduleComponents = frontend.split('.') self.module = moduleComponents[0] self.submodule = moduleComponents[1] else: self.module = frontend self.submodule = frontend self.settings = settings self.projectDir = main.projectBaseDir() # self.repository = repository.repositoryWithPath(self.projectDir) self.repositoryVersion = repositoryVersion self.processedFiles = {} #--------------------------------------------------------------------------- def name (self): raise NotImplementedError() + def projectResourceTypes (self): + raise NotImplementedError() def copyStaticResources (self, targetFolder): raise NotImplementedError() #--------------------------------------------------------------------------- def log (self, message): module = self.module if (self.module != self.submodule): module = module + "." + self.submodule print "frontend [" + module + "]: " + message def absolutePathForSources (self): return os.path.join(self.projectDir, 'frontend', self.module) def absolutePathForSourceFile (self, basePath, file): return os.path.join(self.absolutePathForSources(), basePath, file) def absolutePathForTargetFile (self, folder, basePath, file): return os.path.join(folder, self.module, basePath, file) def filterFiles (self, files): result = [] for file in files: if file.startswith('--'): pass else: result.append(file) return result def copyResources (self, sourceFolder, destinationFolder, fileType): if fileType in self.settings: for file in self.filterFiles(self.settings[fileType]): src = self.absolutePathForSourceFile(fileType, file) dst = self.absolutePathForTargetFile(destinationFolder, fileType, file) main.createFolder(os.path.dirname(dst)) shutil.copy2(src, dst) else: srcFolder = os.path.join(self.absolutePathForSources(), fileType) dstFolder = os.path.join(destinationFolder, self.module, fileType) if not(os.path.exists(dstFolder)): shutil.copytree(srcFolder, dstFolder) # try: # shutil.copytree(srcFolder, dstFolder) # except: # pass def copyResourcesToFolder (self, targetFolder): - self.copyResources(self.projectDir, targetFolder, 'css') - self.copyResources(self.projectDir, targetFolder, 'js') - self.copyResources(self.projectDir, targetFolder, 'images') +# self.copyResources(self.projectDir, targetFolder, 'css') +# self.copyResources(self.projectDir, targetFolder, 'js') +# self.copyResources(self.projectDir, targetFolder, 'images') + for resoureceType in self.projectResourceTypes(): + self.copyResources(self.projectDir, targetFolder, resoureceType) self.copyStaticResources(targetFolder) def loadFilesContent (self, basePath, files): result = "" for file in self.filterFiles(files): try: fileHandler = codecs.open(self.absolutePathForSourceFile(basePath, file), 'r', 'utf-8') except: print "FILE: " + file result += fileHandler.read() + '\n' fileHandler.close() return result def template (self): processedFile = 'html_template' if not self.processedFiles.has_key(processedFile): # self.processedFiles[processedFile] = self.loadFilesContent('html', ['index_template.html']) self.processedFiles[processedFile] = self.loadFilesContent('html', [self.settings['html.template']]) return self.processedFiles[processedFile] def cssminCompressor (self, css): # package found here: # - http://stackoverflow.com/questions/222581/python-script-for-minifying-css/2396777#2396777 # actual downloaded version: http://pypi.python.org/pypi/cssmin/0.1.4 return cssmin.cssmin(css) def regexCssCompressor (self, css): # http://stackoverflow.com/questions/222581/python-script-for-minifying-css/223689#223689 # remove comments - this will break a lot of hacks :-P css = re.sub( r'\s*/\*\s*\*/', "$$HACK1$$", css ) # preserve IE<6 comment hack css = re.sub( r'/\*[\s\S]*?\*/', "", css ) css = css.replace( "$$HACK1$$", '/**/' ) # preserve IE<6 comment hack # url() doesn't need quotes css = re.sub( r'url\((["\'])([^)]*)\1\)', r'url(\2)', css ) # spaces may be safely collapsed as generated content will collapse them anyway css = re.sub( r'\s+', ' ', css ) @@ -199,222 +203,179 @@ class FrontendBuilder(object): result = js return result def compressJS (self, js, description): return self.compressJS_jsmin(js, description) #return self.compressJS_closureCompiler(js, description) #========================================================================== def packBookmarklet (self, bookmakeletCode, version): replacers = [ ('isLoginForm', 'ilf'), ('findLoginForm', 'flf'), ('findLoginForm', 'flf'), ('formParameters', 'fp' ), ('pageParameters', 'pp' ), ('serializeJSON', 'sj' ), ('reprString', 'rs' ), ('logFormParameters', 'lfp'), ('loadClipperzBookmarklet', 'lcb'), ('loginForm', 'lf' ), ('parameters', 'p' ), ('inputElementValues', 'iev'), ] result = self.compressJS(bookmakeletCode, version + " bookmarklet") result = re.sub('\n', ' ', result) # Fit all in a single line # result = re.sub('\s+', ' ', result) # Collapse "redundant" spaces. WARNING: this could have some evil side effects on constant strings used inside to code!! # result = re.sub('\s?([,\+=\(\)\{\};])\s?', '\\1', result) for replacer in replacers: result = re.sub(replacer[0], replacer[1], result) # <!-- escaping required to handle the bookmarklet code within the javascript code --> result = re.sub('\://', '%3a%2f%2f', result) result = re.sub('/', '%2f', result) # result = re.sub('"', '%22', result) result = re.sub('"', '\\"', result) result = re.sub('\"', '%22', result) result = re.sub('\'', '%22', result) result = re.sub('\\\\', '%5c', result) result = result.strip() result = 'javascript:' + result -# replacers = [ -# ('aForm', '_1' ), -# ('inputFields', '_2' ), -# ('passwordFieldsFound', '_3' ), -# ('aDocument', '_6' ), -# ('aLevel', '_7' ), -# # ('result', '_8' ), -# ('documentForms', '_9' ), -# ('iFrames', '_c' ), -# ('anInputElement', '_d' ), -# ('options', '_f' ), -# ('option', '_12'), -# ('aLoginForm', '_13'), -# # ('action', '_17'), -# ('radioValues', '_18'), -# ('radioValueName', '_19'), -# ('inputElement', '_1a'), -# ('elementValues', '_1b'), -# ('radioValue', '_1c'), -# ('values', '_1d'), -# ('objtype', '_21'), -# ('useKey', '_27'), -# ('bookmarkletDiv', '_28'), -# ('someParameters', '_29'), -# ('anException', '_2a'), -# ('newDiv', '_2b'), -# ('base_url', '_2c'), -# ('help_url', '_2d'), -# ('logo_image_url', '_2e'), -# ('background_image_url','_2f'), -# ('close_image_url', '_30'), -# # ('bookmarklet_textarea','_31'), -# ('innerHTML', '_32'), -# ] -# for replacer in replacers: -# result = re.sub('([^\.])' + replacer[0], '\\1' + replacer[1], result) - -# replacers = [ -# ('headNode', '_1' ), -# ('clipperzScriptNode', '_2' ), -# ] -# for replacer in replacers: -# result = re.sub('([^\.])' + replacer[0], '\\1' + replacer[1], result) - -# result = re.sub(';', ';\n', result) - return result - def bookmarklet (self): cacheKey = 'bookmarklet' if not self.processedFiles.has_key(cacheKey): result = 'bookmarklet="' + self.packBookmarklet(self.loadFilesContent('js', ['Bookmarklet.js']), "regular") + '";bookmarklet_ie="' + self.packBookmarklet(self.loadFilesContent('js', ['Bookmarklet_IE.js']), "IE") + '";' self.processedFiles[cacheKey] = result else: result = self.processedFiles[cacheKey] return result def replaceTemplatePlaceholders (self, pageTitle, copyright, css, code, jsLoadMode, version, versionType): result = self.template() result = result.replace('@page.title@', pageTitle) result = result.replace('@copyright@', copyright) result = result.replace('@css@', css) #result = result.replace('@bookmarklet@', bookmarklet) result = result.replace('@application.version@', version) result = result.replace('@application.version.type@', versionType) result = result.replace('@js_' + jsLoadMode + '@', code) result = re.sub('@js_[^@]+@', '', result) return result def assembleCopyrightHeader (self): processedFile = 'copyright' if not self.processedFiles.has_key(processedFile): #self.log("assembling copyright header") copyrightValues = self.settings['copyright.values'] license = self.loadFilesContent('../../properties', ['license.txt']) result = self.loadFilesContent('properties', ['creditsAndCopyrights.txt']) result = re.sub('@clipperz.license@', license, result) for key in copyrightValues: result = re.sub('@'+key+'@', copyrightValues[key], result) self.processedFiles[processedFile] = result return self.processedFiles[processedFile] def cssTagsForFiles (self, basePath, files): #<link rel="stylesheet" type="text/css" href="./css/reset-min.css" /> return '\n'.join(map(lambda file: '<link rel="stylesheet" type="text/css" href="' + basePath + '/' + file + '" />', files)) def cssTagForContent (self, content): return '<style type="text/css">' + content + '</style>' def scriptTagsForFiles (self, basePath, files): #<script type='text/javascript' src='./js/src/bookmarklet.js'></script> return '\n'.join(map(lambda file: '<script type="text/javascript" src="' + basePath + '/' + file + '" charset="utf-8"></script>', files)) def scriptTagForContent (self, content): return '<script>' + content + '</script>' def assembleVersion (self, pageTitle, copyright, css, js, jsLoadMode, version, versionType): cacheKey = version + "-" + versionType if not self.processedFiles.has_key(cacheKey): result = self.replaceTemplatePlaceholders(pageTitle, copyright, css, js, jsLoadMode, version, versionType) self.processedFiles[cacheKey] = result else: result = self.processedFiles[cacheKey] #self.log("# cacheKey:\n" + result) return result def assemble (self, assemblyMode='INSTALL', versionType='LIVE'): if versionType == 'LIVE': pageTitle = "Clipperz - " + self.module else: pageTitle = "Clipperz - " + self.module + " [" + versionType + " - " + assemblyMode +"]" if assemblyMode == 'INSTALL': copyright = self.assembleCopyrightHeader() css = self.cssTagForContent(self.compressCSS(self.loadFilesContent('css', self.settings['css']))) js = self.scriptTagForContent( self.bookmarklet() + '\n' + self.compressJS(self.loadFilesContent('js', self.settings['js']), "application") ) jsLoadMode = 'EMBEDDED' elif assemblyMode == 'DEBUG': copyright = self.assembleCopyrightHeader() css = self.cssTagsForFiles('./css', self.filterFiles(self.settings['css'])) - js = self.scriptTagForContent(self.bookmarklet()) + \ + js = self.scriptTagForContent( + self.bookmarklet()) + \ '\n' + \ - self.scriptTagsForFiles('./js', self.filterFiles(self.settings['js'])) + self.scriptTagsForFiles('./js', self.filterFiles(self.settings['js']) + ) jsLoadMode = 'LINKED' elif assemblyMode == 'DEVELOPMENT': copyright = "" css = self.cssTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'css')), self.filterFiles(self.settings['css'])) - js = self.scriptTagForContent(self.bookmarklet()) + \ + js = self.scriptTagForContent( + self.bookmarklet()) + \ '\n' + \ - self.scriptTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'js')), self.filterFiles(self.settings['js'])) + self.scriptTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'js')), self.filterFiles(self.settings['js']) + ) jsLoadMode = 'LINKED' versionType = 'development' else: raise NotImplementedError() return self.assembleVersion( pageTitle = pageTitle, copyright = copyright, css = css, js = js, jsLoadMode = jsLoadMode, version = self.repositoryVersion, versionType = versionType ) diff --git a/scripts/builder/frontends/betaBuilder.py b/scripts/builder/frontends/betaBuilder.py index c5a3e76..9b32404 100644 --- a/scripts/builder/frontends/betaBuilder.py +++ b/scripts/builder/frontends/betaBuilder.py @@ -1,14 +1,17 @@ from frontendBuilder import FrontendBuilder import shutil class BetaBuilder(FrontendBuilder): def name(self): return "/beta builder" + def projectResourceTypes (self): + return ['js', 'css', 'images'] + def copyStaticResources (self, targetFolder): for file in self.filterFiles(self.settings['staticResources']): src = self.absolutePathForSourceFile('staticResources', file) dst = self.absolutePathForTargetFile(targetFolder, '', file) shutil.copy2(src, dst) diff --git a/scripts/builder/frontends/deltaBuilder.py b/scripts/builder/frontends/deltaBuilder.py new file mode 100644 index 0000000..a341a83 --- a/dev/null +++ b/scripts/builder/frontends/deltaBuilder.py @@ -0,0 +1,16 @@ +from frontendBuilder import FrontendBuilder +import shutil + +class DeltaBuilder(FrontendBuilder): + + def name(self): + return "/delta builder" + + def projectResourceTypes (self): + return ['js', 'css'] + + def copyStaticResources (self, targetFolder): + pass + + def bookmarklet (self): + return ""
\ No newline at end of file diff --git a/scripts/builder/frontends/gammaBuilder.py b/scripts/builder/frontends/gammaBuilder.py index a6ecb7b..c56fb1b 100644 --- a/scripts/builder/frontends/gammaBuilder.py +++ b/scripts/builder/frontends/gammaBuilder.py @@ -1,27 +1,30 @@ from frontendBuilder import FrontendBuilder import shutil class GammaBuilder(FrontendBuilder): def name(self): return "/gamma builder" + def projectResourceTypes (self): + return ['js', 'css', 'images'] + def copyStaticResources (self, targetFolder): resourcesToCopy = [ # {'folder': 'html', 'source': 'exit_template.html', 'target': 'exit.html'}, {'folder': 'html', 'source': 'exit_template.html', 'target': 'logout.html'}, {'folder': 'css', 'source': 'static.css', 'target': 'static.css'} ] for resource in resourcesToCopy: src = self.absolutePathForSourceFile(resource['folder'], resource['source']) dst = self.absolutePathForTargetFile(targetFolder, '', resource['target']) shutil.copy2(src, dst) # src = self.absolutePathForSourceFile('html', 'exit_template.html') # dst = self.absolutePathForTargetFile(targetFolder, '', 'exit.html') # shutil.copy2(src, dst) # src = self.absolutePathForSourceFile('css', 'static.css') # dst = self.absolutePathForTargetFile(targetFolder, '', 'static.css') # shutil.copy2(src, dst) diff --git a/scripts/builder/frontends/gamma_mobileBuilder.py b/scripts/builder/frontends/gamma_mobileBuilder.py index f2e80c9..677a2b0 100644 --- a/scripts/builder/frontends/gamma_mobileBuilder.py +++ b/scripts/builder/frontends/gamma_mobileBuilder.py @@ -1,9 +1,12 @@ from frontendBuilder import FrontendBuilder class Gamma_MobileBuilder(FrontendBuilder): def name(self): return "/gamma.mobile builder" + def projectResourceTypes (self): + return ['js', 'css', 'images'] + def copyStaticResources (self, targetFolder): pass diff --git a/scripts/proxy/main.py b/scripts/proxy/main.py index 107ba16..8ce4989 100755 --- a/scripts/proxy/main.py +++ b/scripts/proxy/main.py @@ -1,95 +1,102 @@ from twisted.internet import reactor from twisted.web import proxy, server, http, resource, static from posixpath import basename, dirname import copy import sys import os import pprint #-------------------------------------------------------------------- def scriptDir (): return os.path.dirname(sys.argv[0]) def projectBaseDir (): return os.path.abspath(scriptDir() + '/../..') def projectTargetDir(): return projectBaseDir() + '/target/' #-------------------------------------------------------------------- class ClipperzTestSite(server.Site): def __init__(self, resource, logPath=None, timeout=60 * 60 * 12): server.Site.__init__(self, resource, logPath, timeout) def getResourceFor(self, request): - if request.uri.startswith('/json') or request.uri.startswith('/dump'): + uri = request.uri + uri = uri.split("?", 1)[0] + uri = uri.split("#", 1)[0] + if uri.startswith('/json') or uri.startswith('/dump'): request.site = self request.sitepath = copy.copy(request.prepath) result = resource.getChildForRequest(self.resource, request) else: - pathParts = request.uri.split('/') + pathParts = uri.split('/') version = pathParts[1] if pathParts[2].startswith('index.'): contentType = 'text/html' absoluteFilePath = os.path.join(projectTargetDir(), 'dev', version, pathParts[2]) result = static.File(absoluteFilePath, contentType) - + elif pathParts[2].endswith('.webapp'): + contentType = 'application/x-web-app-manifest+json' +# absoluteFilePath = os.path.join(projectTargetDir(), 'dev', version, pathParts[2]) + absoluteFilePath = os.path.join(projectBaseDir(), 'frontend', version, 'properties', pathParts[2]) + result = static.File(absoluteFilePath, contentType) else: # http://homer.local:8888/beta/css/clipperz/images/loginInfoBackground.png # pathParts: ['', 'beta', 'css', 'clipperz', 'images', 'loginInfoBackground.png'] try: imagePathIndex = pathParts.index('images') resourceType = 'images' for _ in range(2, imagePathIndex): del pathParts[2] except: resourceType = pathParts[2] basePath = projectBaseDir() + '/frontend' if resourceType == 'images': - fileExtension = os.path.splitext(request.uri)[1] + fileExtension = os.path.splitext(uri)[1] if fileExtension == '.png': contentType = 'image/png' elif fileExtension == '.jpg': contentType = 'image/jpeg' elif fileExtension == '.gif': contentType = 'image/gif' else: print "ERROR - unknown image extension: " + fileExtension absoluteFilePath = basePath + '/'.join(pathParts) else: resourceType = pathParts[2] if resourceType == 'css': contentType = 'text/css' elif resourceType == 'js': contentType = 'text/javascript' else: contentType = 'text/html' - absoluteFilePath = basePath + request.uri + absoluteFilePath = basePath + uri result = static.File(absoluteFilePath, contentType) return result def main (): - site = ClipperzTestSite(proxy.ReverseProxyResource('localhost', 8084, '/java-backend')) + site = ClipperzTestSite(proxy.ReverseProxyResource('localhost', 8080, '/java-backend')) reactor.listenTCP(8888, site) reactor.run() if __name__ == "__main__": main() |