author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-02-11 23:34:25 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-02-11 23:34:25 (UTC) |
commit | 185949cb778dd13a566781bbfa8ef7ed344cc705 (patch) (unidiff) | |
tree | 8fc4ff8cf1efead7610e4141041dd440eb9febbd /scripts/builder/backendBuilder.py | |
parent | 17efce23d9f205f56f5ebbe8e4f4ca581ea47bcb (diff) | |
download | clipperz-185949cb778dd13a566781bbfa8ef7ed344cc705.zip clipperz-185949cb778dd13a566781bbfa8ef7ed344cc705.tar.gz clipperz-185949cb778dd13a566781bbfa8ef7ed344cc705.tar.bz2 |
Improved build scripts
Signed-off-by: Giulio Cesare Solaroli <giulio.cesare@clipperz.com>
Diffstat (limited to 'scripts/builder/backendBuilder.py') (more/less context) (ignore whitespace changes)
-rw-r--r-- | scripts/builder/backendBuilder.py | 101 |
1 files changed, 65 insertions, 36 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 | |||
@@ -4,8 +4,12 @@ | |||
4 | import sys, os, json | 4 | 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 | ||
11 | def __init__ (self, projectTargetDir, frontends, versions, settings): | 15 | def __init__ (self, projectTargetDir, frontends, versions, settings): |
@@ -14,45 +18,53 @@ class BackendBuilder: | |||
14 | self.versions = versions | 18 | self.versions = versions |
15 | self.settings = settings | 19 | self.settings = settings |
20 | |||
21 | # -------------------------------------------------------------------------- | ||
16 | 22 | ||
17 | def name (self): | 23 | def name (self): |
18 | raise NotImplementedError() | 24 | raise NotImplementedError() |
25 | |||
19 | 26 | ||
20 | def relativePath (self): | 27 | def relativePath (self): |
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')) |
51 | file.close() | 63 | file.close() |
52 | 64 | ||
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'] ) |
58 | 70 | ||
@@ -69,21 +81,38 @@ class BackendBuilder: | |||
69 | 81 | ||
70 | 82 | ||
83 | def shouldCompileCode (self): | ||
84 | return ('debug' in self.versions) or ('install' in self.versions) | ||
85 | |||
71 | 86 | ||
72 | def run (self): | 87 | def run (self): |
73 | print self.name() + " - RUN" | 88 | print self.name() + " - RUN" |
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 | #=================================================================== | ||