author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-02-11 23:48:42 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-02-11 23:48:42 (UTC) |
commit | a0661c3b02aa26d6b08ff13dc321e09478868159 (patch) (unidiff) | |
tree | 87bd0af25a0732adb9d14a34d25f9d5479fdf5ee /scripts/builder | |
parent | 96d01919d3ff42c3fdd7f6186a0500caccd3c140 (diff) | |
parent | 7804333809bf725e32a08c531a06acd7d668e190 (diff) | |
download | clipperz-a0661c3b02aa26d6b08ff13dc321e09478868159.zip clipperz-a0661c3b02aa26d6b08ff13dc321e09478868159.tar.gz clipperz-a0661c3b02aa26d6b08ff13dc321e09478868159.tar.bz2 |
Merge pull request #25 from gcsolaroli/master
Initial integration of /beta and /gamma with a single backend
-rw-r--r-- | scripts/builder/backendBuilder.py | 101 | ||||
-rw-r--r-- | scripts/builder/backends/phpBuilder.py (renamed from scripts/builder/phpBuilder.py) | 7 | ||||
-rw-r--r-- | scripts/builder/backends/pythonBuilder.py | 27 | ||||
-rw-r--r-- | scripts/builder/backends/scriptLanguageBuilder.py | 20 | ||||
-rw-r--r-- | scripts/builder/frontendBuilder.py | 141 | ||||
-rwxr-xr-x | scripts/builder/main.py | 85 | ||||
-rw-r--r-- | scripts/builder/pythonBuilder.py | 14 | ||||
-rw-r--r-- | scripts/builder/repository.py | 75 |
8 files changed, 304 insertions, 166 deletions
diff --git a/scripts/builder/backendBuilder.py b/scripts/builder/backendBuilder.py index 16dbe2f..5ecdda0 100644 --- a/scripts/builder/backendBuilder.py +++ b/scripts/builder/backendBuilder.py | |||
@@ -5,6 +5,10 @@ import sys, os, json | |||
5 | import shutil | 5 | import shutil |
6 | import main | ||
7 | import hashlib | 6 | import hashlib |
8 | 7 | ||
9 | class BackendBuilder: | 8 | import main |
9 | |||
10 | #=================================================================== | ||
11 | |||
12 | |||
13 | class BackendBuilder(object): | ||
10 | 14 | ||
@@ -15,2 +19,4 @@ class BackendBuilder: | |||
15 | self.settings = settings | 19 | self.settings = settings |
20 | |||
21 | # -------------------------------------------------------------------------- | ||
16 | 22 | ||
@@ -18,2 +24,3 @@ class BackendBuilder: | |||
18 | raise NotImplementedError() | 24 | raise NotImplementedError() |
25 | |||
19 | 26 | ||
@@ -21,30 +28,35 @@ class BackendBuilder: | |||
21 | raise NotImplementedError() | 28 | raise NotImplementedError() |
29 | |||
22 | 30 | ||
23 | def compileCode (self): | 31 | def compileCode (self): |
24 | pass | 32 | raise NotImplementedError() |
33 | |||
25 | 34 | ||
26 | def copyCompiledCodeToTargetDir (self): | 35 | def createPackage (self): |
27 | src = self.sourceFolder() | 36 | raise NotImplementedError() |
28 | dst = self.targetFolder() | 37 | |
29 | main.createFolder(os.path.dirname(dst)) | 38 | # -------------------------------------------------------------------------- |
30 | shutil.copytree(src, dst) | ||
31 | 39 | ||
32 | def sourceFolder (self): | 40 | def sourceFolder (self): |
33 | return main.projectBaseDir() + '/backend/' + self.relativePath() + '/src' | 41 | return os.path.join(main.projectBaseDir() , 'backend', self.relativePath(), 'src') |
34 | |||
35 | 42 | ||
36 | def targetFolder (self): | ||
37 | return self.projectTargetDir + self.relativePath() | ||
38 | |||
39 | def createTargetFolder (self): | ||
40 | main.createFolder(self.targetFolder()) | ||
41 | |||
42 | 43 | ||
43 | #def copyFrontendResources (self, frontend): | 44 | def tempFolder (self): |
44 | # print "copying resources for frontend: " + frontend | 45 | return os.path.join(self.projectTargetDir, '.tmp', self.relativePath()) |
45 | # print "SETTINGS: " + str(self.settings) | 46 | |
46 | 47 | ||
48 | def frontEndTempFolder (self): | ||
49 | return self.tempFolder() | ||
50 | |||
47 | 51 | ||
48 | def writeToTargetFolder (self, filename, content): | 52 | def developmentTargetFolder (self): |
49 | file = open(self.targetFolder() + '/' + filename, 'w') | 53 | return os.path.join(self.projectTargetDir, 'development', self.relativePath()) |
54 | |||
55 | def targetFolder (self): | ||
56 | return os.path.join(self.projectTargetDir, self.relativePath()) | ||
57 | |||
58 | # -------------------------------------------------------------------------- | ||
59 | |||
60 | def writeToFolder (self, folder, filename, content): | ||
61 | file = open(os.path.join(folder, filename), 'w') | ||
50 | file.write(content.encode('utf-8')) | 62 | file.write(content.encode('utf-8')) |
@@ -53,5 +65,5 @@ class BackendBuilder: | |||
53 | 65 | ||
54 | def configureIndexContent (self, indexContent): | 66 | def configureIndexContent (self, indexContent, requestPathPrefix = ".."): |
55 | result = indexContent | 67 | result = indexContent |
56 | result = result.replace( '@request.path@', self.settings['request.path'] ) | 68 | result = result.replace( '@request.path@', requestPathPrefix + '/' + self.settings['request.path'] ) |
57 | result = result.replace( '@should.pay.toll@', self.settings['should.pay.toll'] ) | 69 | result = result.replace( '@should.pay.toll@', self.settings['should.pay.toll'] ) |
@@ -70,2 +82,5 @@ class BackendBuilder: | |||
70 | 82 | ||
83 | def shouldCompileCode (self): | ||
84 | return ('debug' in self.versions) or ('install' in self.versions) | ||
85 | |||
71 | 86 | ||
@@ -74,16 +89,30 @@ class BackendBuilder: | |||
74 | 89 | ||
75 | self.compileCode() | 90 | if self.shouldCompileCode(): |
76 | self.copyCompiledCodeToTargetDir() | 91 | self.compileCode() |
77 | 92 | ||
78 | for frontend in self.frontends: | 93 | for frontend in self.frontends: |
79 | frontendPath = frontend.module + '/' | 94 | main.createFolder(os.path.join(self.frontEndTempFolder(), frontend.module)) |
80 | if 'debug' in self.versions: | 95 | |
81 | frontend.copyResourcesToTargetFolder(self.targetFolder()) | 96 | if 'debug' in self.versions: |
82 | #self.writeToTargetFolder(frontendPath + 'index_debug.html', self.configureIndexContent(frontend.assembleDebugVersion())) | 97 | frontend.copyResourcesToFolder(self.frontEndTempFolder()) |
83 | self.writeToTargetFolder(frontendPath + 'index_debug.html', self.configureIndexContent(frontend.assemble(assemblyMode='DEBUG', versionType='DEBUG'))) | 98 | |
99 | index = self.configureIndexContent(frontend.assemble(assemblyMode='DEBUG', versionType='DEBUG')) | ||
100 | self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index_debug.html'), index) | ||
101 | |||
102 | if 'install' in self.versions: | ||
103 | index = self.configureIndexContent(frontend.assemble()) | ||
104 | self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index.html'), index) | ||
105 | |||
106 | self.logChecksums(index, "[" + self.name() + " - " + frontend.module + "] index.html checksum") | ||
84 | 107 | ||
85 | if 'install' in self.versions: | 108 | self.createPackage() |
86 | index = self.configureIndexContent(frontend.assemble()) | 109 | |
87 | self.writeToTargetFolder(frontendPath + 'index.html', index) | 110 | if 'development' in self.versions: |
88 | self.logChecksums(index, "[" + self.name() + " - " + frontend.module + "] index.html checksum") | 111 | for frontend in self.frontends: |
112 | main.createFolder(os.path.join(self.developmentTargetFolder(), frontend.module)) | ||
113 | |||
114 | index = self.configureIndexContent(frontend.assemble(assemblyMode='DEVELOPMENT', versionType='DEBUG'), self.settings['development.settings']['url']) | ||
115 | self.writeToFolder(self.developmentTargetFolder(), os.path.join(frontend.module, 'index_development.html'), index) | ||
116 | |||
89 | 117 | ||
118 | #=================================================================== | ||
diff --git a/scripts/builder/phpBuilder.py b/scripts/builder/backends/phpBuilder.py index cb4661d..c928aa0 100644 --- a/scripts/builder/phpBuilder.py +++ b/scripts/builder/backends/phpBuilder.py | |||
@@ -3,5 +3,5 @@ | |||
3 | 3 | ||
4 | from backendBuilder import BackendBuilder | 4 | from scriptLanguageBuilder import ScriptLanguageBuilder |
5 | 5 | ||
6 | class PhpBuilder(BackendBuilder): | 6 | class PhpBuilder(ScriptLanguageBuilder): |
7 | 7 | ||
@@ -9,2 +9,3 @@ class PhpBuilder(BackendBuilder): | |||
9 | return "PHP builder" | 9 | return "PHP builder" |
10 | |||
10 | 11 | ||
@@ -12,3 +13 @@ class PhpBuilder(BackendBuilder): | |||
12 | return 'php' | return 'php' | |
13 | |||
14 | |||
diff --git a/scripts/builder/backends/pythonBuilder.py b/scripts/builder/backends/pythonBuilder.py new file mode 100644 index 0000000..1e44209 --- a/dev/null +++ b/scripts/builder/backends/pythonBuilder.py | |||
@@ -0,0 +1,27 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # -*- coding: UTF-8 -*- | ||
3 | |||
4 | from scriptLanguageBuilder import ScriptLanguageBuilder | ||
5 | |||
6 | class PythonBuilder(ScriptLanguageBuilder): | ||
7 | |||
8 | def name(self): | ||
9 | return "Python builder" | ||
10 | |||
11 | |||
12 | def relativePath(self): | ||
13 | return 'python' | ||
14 | |||
15 | |||
16 | def compileCode (self): | ||
17 | src = self.sourceFolder() | ||
18 | dst = self.targetFolder() | ||
19 | |||
20 | shutil.copytree(src, dst) | ||
21 | |||
22 | |||
23 | #def copyCompiledCodeToTargetDir (self): | ||
24 | # src = self.sourceFolder() | ||
25 | # dst = self.targetFolder() | ||
26 | # | ||
27 | # shutil.copytree(src, dst) | ||
diff --git a/scripts/builder/backends/scriptLanguageBuilder.py b/scripts/builder/backends/scriptLanguageBuilder.py new file mode 100644 index 0000000..7d5b31c --- a/dev/null +++ b/scripts/builder/backends/scriptLanguageBuilder.py | |||
@@ -0,0 +1,20 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # -*- coding: UTF-8 -*- | ||
3 | |||
4 | import shutil | ||
5 | from backendBuilder import BackendBuilder | ||
6 | |||
7 | class ScriptLanguageBuilder(BackendBuilder): | ||
8 | |||
9 | def compileCode (self): | ||
10 | src = self.sourceFolder() | ||
11 | dst = self.tempFolder() | ||
12 | |||
13 | shutil.copytree(src, dst) | ||
14 | |||
15 | |||
16 | def createPackage (self): | ||
17 | src = self.tempFolder() | ||
18 | dst = self.targetFolder() | ||
19 | |||
20 | shutil.copytree(src, dst) | ||
diff --git a/scripts/builder/frontendBuilder.py b/scripts/builder/frontendBuilder.py index 55054ee..dae837b 100644 --- a/scripts/builder/frontendBuilder.py +++ b/scripts/builder/frontendBuilder.py | |||
@@ -11,13 +11,7 @@ import urllib | |||
11 | 11 | ||
12 | #from mercurial import ui, hg | ||
13 | #from mercurial.node import hex | ||
14 | from dulwich.repo import Repo | ||
15 | |||
16 | import main | 12 | import main |
17 | 13 | ||
14 | class FrontendBuilder(object): | ||
18 | 15 | ||
19 | 16 | def __init__ (self, frontend, settings, repositoryVersion): | |
20 | class FrontendBuilder: | ||
21 | |||
22 | def __init__ (self, frontend, settings): | ||
23 | if '.' in frontend: | 17 | if '.' in frontend: |
@@ -32,2 +26,4 @@ class FrontendBuilder: | |||
32 | self.projectDir = main.projectBaseDir() | 26 | self.projectDir = main.projectBaseDir() |
27 | # self.repository = repository.repositoryWithPath(self.projectDir) | ||
28 | self.repositoryVersion = repositoryVersion | ||
33 | self.processedFiles = {} | 29 | self.processedFiles = {} |
@@ -35,36 +31,2 @@ class FrontendBuilder: | |||
35 | 31 | ||
36 | def mercurialRepositoryVersion (self): | ||
37 | repo = hg.repository(ui.ui(), self.projectDir) | ||
38 | context = repo['tip'] | ||
39 | result = str(context) | ||
40 | |||
41 | return result | ||
42 | |||
43 | |||
44 | def gitRepositoryVersion (self): | ||
45 | repo = Repo(self.projectDir) | ||
46 | #if repo.is_dirty(): | ||
47 | #print "WARNING: build run with dirty repository" | ||
48 | result = repo.refs['HEAD'] | ||
49 | |||
50 | return result | ||
51 | |||
52 | |||
53 | |||
54 | def repositoryVersion (self): | ||
55 | cacheKey = 'repositoryVersion' | ||
56 | if not self.processedFiles.has_key(cacheKey): | ||
57 | #result = self.mercurialRepositoryVersion() | ||
58 | result = self.gitRepositoryVersion() | ||
59 | self.processedFiles[cacheKey] = result | ||
60 | else: | ||
61 | result = self.processedFiles[cacheKey] | ||
62 | |||
63 | return result | ||
64 | |||
65 | |||
66 | #def relativePath (self): | ||
67 | #return self.module | ||
68 | # | ||
69 | |||
70 | def log (self, message): | 32 | def log (self, message): |
@@ -73,4 +35,8 @@ class FrontendBuilder: | |||
73 | 35 | ||
74 | def absolutePathForSourceFile (self, folder, basePath, file): | 36 | def absolutePathForSources (self): |
75 | return folder + '/frontend/' + self.module + '/' + basePath + '/' + file | 37 | return os.path.join(self.projectDir, 'frontend', self.module) |
38 | |||
39 | |||
40 | def absolutePathForSourceFile (self, basePath, file): | ||
41 | return os.path.join(self.absolutePathForSources(), basePath, file) | ||
76 | 42 | ||
@@ -78,3 +44,4 @@ class FrontendBuilder: | |||
78 | def absolutePathForTargetFile (self, folder, basePath, file): | 44 | def absolutePathForTargetFile (self, folder, basePath, file): |
79 | return folder + '/' + self.module + '/' + basePath + '/' + file | 45 | return os.path.join(folder, self.module, basePath, file) |
46 | |||
80 | 47 | ||
@@ -94,3 +61,3 @@ class FrontendBuilder: | |||
94 | for file in self.filterFiles(self.settings[fileType]): | 61 | for file in self.filterFiles(self.settings[fileType]): |
95 | src = self.absolutePathForSourceFile(sourceFolder, fileType, file) | 62 | src = self.absolutePathForSourceFile(fileType, file) |
96 | dst = self.absolutePathForTargetFile(destinationFolder, fileType, file) | 63 | dst = self.absolutePathForTargetFile(destinationFolder, fileType, file) |
@@ -100,3 +67,3 @@ class FrontendBuilder: | |||
100 | 67 | ||
101 | def copyResourcesToTargetFolder (self, targetFolder): | 68 | def copyResourcesToFolder (self, targetFolder): |
102 | self.copyResources(self.projectDir, targetFolder, 'css') | 69 | self.copyResources(self.projectDir, targetFolder, 'css') |
@@ -110,3 +77,3 @@ class FrontendBuilder: | |||
110 | try: | 77 | try: |
111 | fileHandler = codecs.open(self.absolutePathForSourceFile(self.projectDir, basePath, file), 'r', 'utf-8') | 78 | fileHandler = codecs.open(self.absolutePathForSourceFile(basePath, file), 'r', 'utf-8') |
112 | except: | 79 | except: |
@@ -183,4 +150,4 @@ class FrontendBuilder: | |||
183 | 150 | ||
184 | def compressJS_jsmin (self, js): | 151 | def compressJS_jsmin (self, js, description): |
185 | self.log("compressing JS code") | 152 | self.log("compressing " + description + " code") |
186 | original = StringIO.StringIO(js) | 153 | original = StringIO.StringIO(js) |
@@ -198,3 +165,3 @@ class FrontendBuilder: | |||
198 | 165 | ||
199 | def compressJS_closureCompiler (self, js): | 166 | def compressJS_closureCompiler (self, js, description): |
200 | #Googles Closure compiler | 167 | #Googles Closure compiler |
@@ -207,5 +174,5 @@ class FrontendBuilder: | |||
207 | 174 | ||
208 | def compressJS (self, js): | 175 | def compressJS (self, js, description): |
209 | return self.compressJS_jsmin(js) | 176 | return self.compressJS_jsmin(js, description) |
210 | #return self.compressJS_closureCompiler(js) | 177 | #return self.compressJS_closureCompiler(js, description) |
211 | 178 | ||
@@ -214,3 +181,3 @@ class FrontendBuilder: | |||
214 | 181 | ||
215 | def packBookmarklet (self, bookmakeletCode): | 182 | def packBookmarklet (self, bookmakeletCode, version): |
216 | replacers = [ | 183 | replacers = [ |
@@ -229,3 +196,3 @@ class FrontendBuilder: | |||
229 | ] | 196 | ] |
230 | result = self.compressJS(bookmakeletCode) | 197 | result = self.compressJS(bookmakeletCode, version + " bookmarklet") |
231 | 198 | ||
@@ -302,3 +269,3 @@ class FrontendBuilder: | |||
302 | if not self.processedFiles.has_key(cacheKey): | 269 | if not self.processedFiles.has_key(cacheKey): |
303 | result = 'bookmarklet="' + self.packBookmarklet(self.loadFilesContent('js', ['Bookmarklet.js'])) + '";bookmarklet_ie="' + self.packBookmarklet(self.loadFilesContent('js', ['Bookmarklet_IE.js'])) + '";' | 270 | result = 'bookmarklet="' + self.packBookmarklet(self.loadFilesContent('js', ['Bookmarklet.js']), "regular") + '";bookmarklet_ie="' + self.packBookmarklet(self.loadFilesContent('js', ['Bookmarklet_IE.js']), "IE") + '";' |
304 | self.processedFiles[cacheKey] = result | 271 | self.processedFiles[cacheKey] = result |
@@ -310,3 +277,3 @@ class FrontendBuilder: | |||
310 | 277 | ||
311 | def replaceTemplatePlaceholders (self, assemblyMode, pageTitle, copyright, css, code, version, versionType): | 278 | def replaceTemplatePlaceholders (self, pageTitle, copyright, css, code, jsLoadMode, version, versionType): |
312 | result = self.template() | 279 | result = self.template() |
@@ -319,3 +286,3 @@ class FrontendBuilder: | |||
319 | result = result.replace('@application.version.type@', versionType,1) | 286 | result = result.replace('@application.version.type@', versionType,1) |
320 | result = result.replace('@js_' + assemblyMode + '@', code, 1) | 287 | result = result.replace('@js_' + jsLoadMode + '@', code, 1) |
321 | 288 | ||
@@ -345,3 +312,3 @@ class FrontendBuilder: | |||
345 | #<link rel="stylesheet" type="text/css" href="./css/reset-min.css" /> | 312 | #<link rel="stylesheet" type="text/css" href="./css/reset-min.css" /> |
346 | return '\n'.join(map(lambda file: '<link rel="stylesheet" type="text/css" href="./' + basePath + '/' + file + '" />', files)) | 313 | return '\n'.join(map(lambda file: '<link rel="stylesheet" type="text/css" href="' + basePath + '/' + file + '" />', files)) |
347 | 314 | ||
@@ -354,3 +321,3 @@ class FrontendBuilder: | |||
354 | #<script type='text/javascript' src='./js/src/bookmarklet.js'></script> | 321 | #<script type='text/javascript' src='./js/src/bookmarklet.js'></script> |
355 | return '\n'.join(map(lambda file: '<script type="text/javascript" src="./' + basePath + '/' + file + '"></script>', files)) | 322 | return '\n'.join(map(lambda file: '<script type="text/javascript" src="' + basePath + '/' + file + '"></script>', files)) |
356 | 323 | ||
@@ -361,6 +328,6 @@ class FrontendBuilder: | |||
361 | 328 | ||
362 | def assembleVersion (self, assemblyMode, pageTitle, copyright, css, js, version, versionType): | 329 | def assembleVersion (self, pageTitle, copyright, css, js, jsLoadMode, version, versionType): |
363 | cacheKey = version + "-" + versionType | 330 | cacheKey = version + "-" + versionType |
364 | if not self.processedFiles.has_key(cacheKey): | 331 | if not self.processedFiles.has_key(cacheKey): |
365 | result = self.replaceTemplatePlaceholders(assemblyMode, pageTitle, copyright, css, js, version, versionType) | 332 | result = self.replaceTemplatePlaceholders(pageTitle, copyright, css, js, jsLoadMode, version, versionType) |
366 | self.processedFiles[cacheKey] = result | 333 | self.processedFiles[cacheKey] = result |
@@ -374,20 +341,44 @@ class FrontendBuilder: | |||
374 | def assemble (self, assemblyMode='INSTALL', versionType='LIVE'): | 341 | def assemble (self, assemblyMode='INSTALL', versionType='LIVE'): |
375 | pageTitle = "Clipperz - " + self.module | 342 | |
376 | if versionType != 'LIVE': | 343 | if versionType == 'LIVE': |
377 | pageTitle += " [" + versionType + " - " + assemblyMode +"]" | 344 | pageTitle = "Clipperz - " + self.module |
378 | 345 | else: | |
346 | pageTitle = "Clipperz - " + self.module + " [" + versionType + " - " + assemblyMode +"]" | ||
347 | |||
379 | if assemblyMode == 'INSTALL': | 348 | if assemblyMode == 'INSTALL': |
380 | css= self.cssTagForContent(self.compressCSS(self.loadFilesContent('css', self.settings['css']))) | 349 | copyright = self.assembleCopyrightHeader() |
381 | js= self.scriptTagForContent(self.bookmarklet() + '\n' + self.compressJS(self.loadFilesContent('js', self.settings['js']))) | 350 | css =self.cssTagForContent(self.compressCSS(self.loadFilesContent('css', self.settings['css']))) |
351 | js =self.scriptTagForContent( | ||
352 | self.bookmarklet() + | ||
353 | '\n' + | ||
354 | self.compressJS(self.loadFilesContent('js', self.settings['js']), "application") | ||
355 | ) | ||
356 | jsLoadMode = 'EMBEDDED' | ||
357 | |||
358 | elif assemblyMode == 'DEBUG': | ||
359 | copyright = self.assembleCopyrightHeader() | ||
360 | css =self.cssTagsForFiles('./css', self.filterFiles(self.settings['css'])) | ||
361 | js =self.scriptTagForContent(self.bookmarklet()) + \ | ||
362 | '\n' + \ | ||
363 | self.scriptTagsForFiles('./js', self.filterFiles(self.settings['js'])) | ||
364 | jsLoadMode = 'LINKED' | ||
365 | |||
366 | elif assemblyMode == 'DEVELOPMENT': | ||
367 | copyright = "" | ||
368 | css =self.cssTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'css')), self.filterFiles(self.settings['css'])) | ||
369 | js =self.scriptTagForContent(self.bookmarklet()) + \ | ||
370 | '\n' + \ | ||
371 | self.scriptTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'js')), self.filterFiles(self.settings['js'])) | ||
372 | jsLoadMode = 'LINKED' | ||
373 | |||
382 | else: | 374 | else: |
383 | css= self.cssTagsForFiles('css', self.filterFiles(self.settings['css'])) | 375 | raise NotImplementedError() |
384 | js= self.scriptTagForContent(self.bookmarklet()) + '\n' + self.scriptTagsForFiles('js', self.filterFiles(self.settings['js'])) | 376 | |
385 | |||
386 | return self.assembleVersion( | 377 | return self.assembleVersion( |
387 | assemblyMode= assemblyMode, | ||
388 | pageTitle = pageTitle, | 378 | pageTitle = pageTitle, |
389 | copyright = self.assembleCopyrightHeader(), | 379 | copyright = copyright, |
390 | css = css, | 380 | css = css, |
391 | js = js, | 381 | js = js, |
392 | version = self.repositoryVersion(), | 382 | jsLoadMode = jsLoadMode, |
383 | version = self.repositoryVersion, | ||
393 | versionType = versionType | 384 | versionType = versionType |
diff --git a/scripts/builder/main.py b/scripts/builder/main.py index 94f738f..6fce65d 100755 --- a/scripts/builder/main.py +++ b/scripts/builder/main.py | |||
@@ -3,12 +3,13 @@ | |||
3 | 3 | ||
4 | import sys, os, json | 4 | import sys |
5 | import os | ||
6 | import json | ||
5 | import shutil | 7 | import shutil |
6 | import pprint | 8 | import pprint |
7 | import frontendBuilder | ||
8 | import codecs | 9 | import codecs |
9 | import itertools | 10 | import itertools |
10 | |||
11 | from collections import deque | 11 | from collections import deque |
12 | from phpBuilder import PhpBuilder | 12 | |
13 | from pythonBuilder import PythonBuilder | 13 | import frontendBuilder |
14 | import repository | ||
14 | 15 | ||
@@ -36,3 +37,3 @@ def createFolder (path): | |||
36 | def loadSettings (component, module): | 37 | def loadSettings (component, module): |
37 | print "MODULE: " + module | 38 | # print "MODULE: " + module |
38 | 39 | ||
@@ -45,3 +46,4 @@ def loadSettings (component, module): | |||
45 | 46 | ||
46 | settings = codecs.open(projectBaseDir() + '/' + component + '/' + module + '/properties/' + submodule + '.properties.json', 'r', 'utf-8') | 47 | #settings = codecs.open(projectBaseDir() + os.sep + component + os.sep + module + os.sep + 'properties' + os.sep + submodule + '.properties.json', 'r', 'utf-8') |
48 | settings = codecs.open(os.path.join(projectBaseDir(), component, module, 'properties', submodule + '.properties.json'), 'r', 'utf-8') | ||
47 | result = json.load(settings) | 49 | result = json.load(settings) |
@@ -73,11 +75,9 @@ def assembleBackend (backend, frontends, versions): | |||
73 | 75 | ||
74 | if backend == 'php': | 76 | builderModuleName = backend + 'Builder' |
75 | backendBuilder = PhpBuilder(projectTargetDir(), frontends, versions, settings) | 77 | builderClassName = backend.capitalize() + 'Builder' |
76 | elif backend == 'python': | 78 | |
77 | backendBuilder = PythonBuilder(projectTargetDir(), frontends, versions, settings) | 79 | builderModule = __import__(builderModuleName) |
78 | #elif backend == 'java': | 80 | builderClass = getattr(builderModule, builderClassName) |
79 | #buildJavaBackend (frontends, versions, settings) | 81 | |
80 | else: | 82 | backendBuilder = builderClass(projectTargetDir(), frontends, versions, settings) |
81 | raise Exception('unrecognized backend: ' + backend) | ||
82 | |||
83 | backendBuilder.run() | 83 | backendBuilder.run() |
@@ -86,7 +86,10 @@ def assembleBackend (backend, frontends, versions): | |||
86 | 86 | ||
87 | def build (settings): | 87 | def build (settings, repository): |
88 | frontends = [] | 88 | frontends = [] |
89 | 89 | ||
90 | if repository.areTherePendingChanges(): | ||
91 | print "\nWARNING: repository has pending changes\n" | ||
92 | |||
90 | for frontend in settings['frontends']: | 93 | for frontend in settings['frontends']: |
91 | frontends.append(frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend))) | 94 | frontends.append(frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend), repository.version())) |
92 | 95 | ||
@@ -98,3 +101,3 @@ def build (settings): | |||
98 | def clean (): | 101 | def clean (): |
99 | print "cleaning up …" | 102 | # print "cleaning up …" |
100 | if os.path.exists(projectTargetDir()): | 103 | if os.path.exists(projectTargetDir()): |
@@ -109,9 +112,9 @@ def usage (message): | |||
109 | 112 | ||
110 | print "build.py clean" | 113 | # print "build clean" |
111 | print "build.py clean install" | 114 | # print "build clean install" |
112 | print "build.py install --ALL" | 115 | print "build install --ALL" |
113 | print "build.py install debug --ALL" | 116 | print "build install debug --ALL" |
114 | print "build.py clean install debug --ALL" | 117 | # print "build clean install debug --ALL" |
115 | print "build.ph install, debug --backends php java --frontends beta gamma" | 118 | print "build install debug --backends php python --frontends beta gamma" |
116 | print "build.ph install, debug --backends php java --frontends beta gamma gamma.mobile" | 119 | print "build install debug development --backends php python --frontends beta gamma gamma.mobile" |
117 | exit(1) | 120 | exit(1) |
@@ -120,2 +123,10 @@ def usage (message): | |||
120 | 123 | ||
124 | def allFrontends (): | ||
125 | return ['beta', 'gamma', 'mobile'] | ||
126 | |||
127 | def allBackends (): | ||
128 | return ['php', 'python'] | ||
129 | |||
130 | #-------------------------------------------------------------------- | ||
131 | |||
121 | def main (): | 132 | def main (): |
@@ -123,10 +134,9 @@ def main (): | |||
123 | parameters = list(itertools.islice(sys.argv, 1, None)) | 134 | parameters = list(itertools.islice(sys.argv, 1, None)) |
124 | 135 | ||
125 | shouldClean = len(filter(lambda x: x == 'clean', parameters)) > 0 | 136 | sys.path.append(os.path.join(scriptDir(), 'backends')) |
126 | if (shouldClean): | 137 | currentRepository = repository.repositoryWithPath(projectBaseDir()) |
127 | clean () | 138 | |
128 | 139 | clean() | |
129 | parameters = filter(lambda x: x != 'clean', parameters) | ||
130 | versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) | 140 | versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) |
131 | settings['versions'] = versions; #['debug', 'install'] | 141 | settings['versions'] = versions; #['debug', 'install', 'development'] |
132 | parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) | 142 | parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) |
@@ -136,4 +146,4 @@ def main (): | |||
136 | if parameter == "--ALL": | 146 | if parameter == "--ALL": |
137 | settings['frontends'] = ['beta', 'gamma', 'mobile'] | 147 | settings['frontends'] = allFrontends() |
138 | settings['backends'] = ['php', 'python', 'java'] | 148 | settings['backends'] = allBackends() |
139 | else: | 149 | else: |
@@ -160,4 +170,5 @@ def main (): | |||
160 | 170 | ||
161 | build (settings) | 171 | build(settings, currentRepository) |
162 | 172 | else: | |
173 | usage("Suggestions on how to call the 'build' script:") | ||
163 | 174 | ||
diff --git a/scripts/builder/pythonBuilder.py b/scripts/builder/pythonBuilder.py deleted file mode 100644 index a84598d..0000000 --- a/scripts/builder/pythonBuilder.py +++ b/dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # -*- coding: UTF-8 -*- | ||
3 | |||
4 | from backendBuilder import BackendBuilder | ||
5 | |||
6 | class PythonBuilder(BackendBuilder): | ||
7 | |||
8 | def name(self): | ||
9 | return "Python builder" | ||
10 | |||
11 | def relativePath(self): | ||
12 | return 'python' | ||
13 | |||
14 | |||
diff --git a/scripts/builder/repository.py b/scripts/builder/repository.py new file mode 100644 index 0000000..89db9a5 --- a/dev/null +++ b/scripts/builder/repository.py | |||
@@ -0,0 +1,75 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # -*- coding: UTF-8 -*- | ||
3 | |||
4 | |||
5 | def repositoryWithPath (path): | ||
6 | try: | ||
7 | from dulwich.repo import Repo | ||
8 | |||
9 | repo = Repo(path) | ||
10 | result = GitRepository(repo, path) | ||
11 | except: | ||
12 | from mercurial import ui, hg | ||
13 | |||
14 | repo = hg.repository(ui.ui(), path) | ||
15 | result = HgRepository(repo, path) | ||
16 | |||
17 | return result | ||
18 | |||
19 | |||
20 | #=================================================================== | ||
21 | |||
22 | |||
23 | class Repository(object): | ||
24 | |||
25 | def __init__ (self, repository, path): | ||
26 | self.repository = repository | ||
27 | self.path = path | ||
28 | |||
29 | |||
30 | def revision (self): | ||
31 | raise NotImplementedError() | ||
32 | |||
33 | |||
34 | def areTherePendingChanges (self): | ||
35 | raise NotImplementedError() | ||
36 | |||
37 | |||
38 | def version (self): | ||
39 | result = self.revision() | ||
40 | if self.areTherePendingChanges(): | ||
41 | result = '>>> ' + result + ' <<<' | ||
42 | |||
43 | # print "VERSION: " + result | ||
44 | return result | ||
45 | |||
46 | |||
47 | #=================================================================== | ||
48 | |||
49 | |||
50 | class GitRepository(Repository): | ||
51 | |||
52 | def revision (self): | ||
53 | return repository.refs['HEAD'] | ||
54 | |||
55 | |||
56 | def areTherePendingChanges (self): | ||
57 | return repository.is_dirty() | ||
58 | |||
59 | |||
60 | #=================================================================== | ||
61 | |||
62 | |||
63 | class HgRepository(Repository): | ||
64 | #http://mercurial.selenic.com/wiki/MercurialApi | ||
65 | |||
66 | def revision (self): | ||
67 | return 'hg:' + str(self.repository['tip']) | ||
68 | |||
69 | |||
70 | def areTherePendingChanges (self): | ||
71 | # TODO: FIXME: repository.status() does not report 'unknown(?)' files. :( | ||
72 | return not all(map(lambda fileList: len(fileList) == 0, self.repository.status())) | ||
73 | |||
74 | |||
75 | #=================================================================== | ||