Diffstat (limited to 'scripts/builder/frontendBuilder.py') (more/less context) (show whitespace changes)
-rw-r--r-- | scripts/builder/frontendBuilder.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/scripts/builder/frontendBuilder.py b/scripts/builder/frontendBuilder.py index 1f0f92f..fc603c4 100644 --- a/scripts/builder/frontendBuilder.py +++ b/scripts/builder/frontendBuilder.py @@ -1,94 +1,123 @@ #!/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 copyStaticResources (self, targetFolder): + raise NotImplementedError() + + #--------------------------------------------------------------------------- def log (self, message): - print "frontend [" + self.module + "]: " + 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.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] @@ -350,41 +379,42 @@ class FrontendBuilder(object): 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()) + \ '\n' + \ 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()) + \ '\n' + \ 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 ) |