summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--scripts/builder/backendBuilder.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/scripts/builder/backendBuilder.py b/scripts/builder/backendBuilder.py
index 36b28ca..20b4bd0 100644
--- a/scripts/builder/backendBuilder.py
+++ b/scripts/builder/backendBuilder.py
@@ -1,39 +1,43 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2# -*- coding: UTF-8 -*- 2# -*- coding: UTF-8 -*-
3 3
4import sys, os, json 4import sys, os, json
5import shutil 5import shutil
6import hashlib 6import hashlib
7 7
8from functools import reduce
9from operator import add
10from itertools import izip
11
8import main 12import main
9 13
10#=================================================================== 14#===================================================================
11 15
12class BackendBuilder(object): 16class BackendBuilder(object):
13 17
14 def __init__ (self, projectTargetDir, frontends, versions, settings): 18 def __init__ (self, projectTargetDir, frontends, versions, settings):
15 self.projectTargetDir = projectTargetDir 19 self.projectTargetDir = projectTargetDir
16 self.frontends = frontends 20 self.frontends = frontends
17 self.versions = versions 21 self.versions = versions
18 self.settings = settings 22 self.settings = settings
19 23
20 # -------------------------------------------------------------------------- 24 # --------------------------------------------------------------------------
21 25
22 def name (self): 26 def name (self):
23 raise NotImplementedError() 27 raise NotImplementedError()
24 28
25 29
26 def relativePath (self): 30 def relativePath (self):
27 raise NotImplementedError() 31 raise NotImplementedError()
28 32
29 33
30 def compileCode (self): 34 def compileCode (self):
31 raise NotImplementedError() 35 raise NotImplementedError()
32 36
33 37
34 def createPackage (self): 38 def createPackage (self):
35 raise NotImplementedError() 39 raise NotImplementedError()
36 40
37 # -------------------------------------------------------------------------- 41 # --------------------------------------------------------------------------
38 42
39 def sourceFolder (self): 43 def sourceFolder (self):
@@ -43,68 +47,73 @@ class BackendBuilder(object):
43 def tempFolder (self): 47 def tempFolder (self):
44 return os.path.join(self.projectTargetDir, '.tmp', self.relativePath()) 48 return os.path.join(self.projectTargetDir, '.tmp', self.relativePath())
45 49
46 50
47 def frontEndTempFolder (self): 51 def frontEndTempFolder (self):
48 return self.tempFolder() 52 return self.tempFolder()
49 53
50 54
51 def developmentTargetFolder (self): 55 def developmentTargetFolder (self):
52 return os.path.join(self.projectTargetDir, 'development') 56 return os.path.join(self.projectTargetDir, 'development')
53 57
54 58
55 def targetFolder (self): 59 def targetFolder (self):
56 return os.path.join(self.projectTargetDir, self.relativePath()) 60 return os.path.join(self.projectTargetDir, self.relativePath())
57 61
58 62
59 # -------------------------------------------------------------------------- 63 # --------------------------------------------------------------------------
60 64
61 def writeToFolder (self, folder, filename, content): 65 def writeToFolder (self, folder, filename, content):
62 file = open(os.path.join(folder, filename), 'w') 66 file = open(os.path.join(folder, filename), 'w')
63 file.write(content.encode('utf-8')) 67 file.write(content.encode('utf-8'))
64 file.close() 68 file.close()
65 69
66 70
67 def configureIndexContent (self, indexContent, requestPathPrefix = ".."): 71 def configureIndexContent (self, indexContent, requestPathPrefix = ".."):
68 result = indexContent 72 result = indexContent
69 result = result.replace( '@request.path@', requestPathPrefix + '/' + self.settings['request.path'] ) 73 result = result.replace( '@request.path@', requestPathPrefix + '/' + self.settings['request.path'] )
70 result = result.replace( '@should.pay.toll@', self.settings['should.pay.toll'] ) 74 result = result.replace( '@should.pay.toll@', self.settings['should.pay.toll'] )
71 75
72 return result 76 return result
73 77
74 78
79 def formatMAC (self, value):
80 x = iter(value)
81 return ' '.join([reduce(add, tup) for tup in izip(x, x, x, x)])
82
83
75 def logChecksums (self, content, message): 84 def logChecksums (self, content, message):
76 md5Digest = hashlib.md5(content.encode('utf-8')).hexdigest() 85 md5Digest = self.formatMAC(hashlib.md5(content.encode('utf-8')).hexdigest())
77 shaDigest = hashlib.sha1(content.encode('utf-8')).hexdigest() 86 shaDigest = self.formatMAC(hashlib.sha1(content.encode('utf-8')).hexdigest())
78 sha256Digest= hashlib.sha256(content.encode('utf-8')).hexdigest() 87 sha256Digest= self.formatMAC(hashlib.sha256(content.encode('utf-8')).hexdigest())
79 print message + ": " + md5Digest + " (md5)" 88 print message + ": " + md5Digest + " (md5)"
80 print message + ": " + shaDigest + " (sha1)" 89 print message + ": " + shaDigest + " (sha1)"
81 print message + ": " + sha256Digest + " (sha256)" 90 print message + ": " + sha256Digest + " (sha256)"
82 91
83 92
84 def shouldCompileCode (self): 93 def shouldCompileCode (self):
85 return ('debug' in self.versions) or ('install' in self.versions) 94 return ('debug' in self.versions) or ('install' in self.versions)
86 95
87 96
88 def run (self): 97 def run (self):
89 print self.name() + " - RUN" 98 print self.name() + " - RUN"
90 99
91 if self.shouldCompileCode(): 100 if self.shouldCompileCode():
92 self.compileCode() 101 self.compileCode()
93 102
94 for frontend in self.frontends: 103 for frontend in self.frontends:
95 if (frontend.module == frontend.submodule): 104 if (frontend.module == frontend.submodule):
96 submoduleExtension = '' 105 submoduleExtension = ''
97 else: 106 else:
98 submoduleExtension = '.' + frontend.submodule 107 submoduleExtension = '.' + frontend.submodule
99 108
100 main.createFolder(os.path.join(self.frontEndTempFolder(), frontend.module)) 109 main.createFolder(os.path.join(self.frontEndTempFolder(), frontend.module))
101 110
102 if 'debug' in self.versions: 111 if 'debug' in self.versions:
103 frontend.copyResourcesToFolder(self.frontEndTempFolder()) 112 frontend.copyResourcesToFolder(self.frontEndTempFolder())
104 113
105 index = self.configureIndexContent(frontend.assemble(assemblyMode='DEBUG', versionType='DEBUG')) 114 index = self.configureIndexContent(frontend.assemble(assemblyMode='DEBUG', versionType='DEBUG'))
106 self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index_debug' + submoduleExtension + '.html'), index) 115 self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index_debug' + submoduleExtension + '.html'), index)
107 116
108 if 'install' in self.versions: 117 if 'install' in self.versions:
109 index = self.configureIndexContent(frontend.assemble()) 118 index = self.configureIndexContent(frontend.assemble())
110 self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index' + submoduleExtension + '.html'), index) 119 self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index' + submoduleExtension + '.html'), index)