summaryrefslogtreecommitdiff
authorClipperz <info@clipperz.com>2013-01-18 17:17:26 (UTC)
committer Clipperz <info@clipperz.com>2013-01-18 17:17:26 (UTC)
commit1e19202f478ca4ab25c6566bf1c17dc7f3698824 (patch) (unidiff)
tree9b2792add41f98cc8aea44077a40a5064c793610
parent969b9f94a25931a765a4cd4765177979f66c1585 (diff)
downloadclipperz-1e19202f478ca4ab25c6566bf1c17dc7f3698824.zip
clipperz-1e19202f478ca4ab25c6566bf1c17dc7f3698824.tar.gz
clipperz-1e19202f478ca4ab25c6566bf1c17dc7f3698824.tar.bz2
Improved the reporting of the MAC while building
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,134 +1,143 @@
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):
40 return os.path.join(main.projectBaseDir() , 'backend', self.relativePath(), 'src') 44 return os.path.join(main.projectBaseDir() , 'backend', self.relativePath(), 'src')
41 45
42 46
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)
111 120
112 self.logChecksums(index, "[" + self.name() + " - " + frontend.module + "] index" + submoduleExtension + ".html checksum") 121 self.logChecksums(index, "[" + self.name() + " - " + frontend.module + "] index" + submoduleExtension + ".html checksum")
113 122
114 self.createPackage() 123 self.createPackage()
115 124
116 # if 'development' in self.versions: 125 # if 'development' in self.versions:
117 # for frontend in self.frontends: 126 # for frontend in self.frontends:
118 # if (frontend.module == frontend.submodule): 127 # if (frontend.module == frontend.submodule):
119 # submoduleExtension = '' 128 # submoduleExtension = ''
120 # else: 129 # else:
121 # submoduleExtension = '.' + frontend.submodule 130 # submoduleExtension = '.' + frontend.submodule
122# 131#
123 # print "FRONTEND module: " + frontend.module 132 # print "FRONTEND module: " + frontend.module
124 # print "FRONTEND submodule: " + frontend.submodule 133 # print "FRONTEND submodule: " + frontend.submodule
125# 134#
126 ## main.createFolder(os.path.join(self.developmentTargetFolder(), frontend.module)) 135 ## main.createFolder(os.path.join(self.developmentTargetFolder(), frontend.module))
127 # main.createFolder(self.developmentTargetFolder()) 136 # main.createFolder(self.developmentTargetFolder())
128# 137#
129 # index = self.configureIndexContent(frontend.assemble(assemblyMode='DEVELOPMENT', versionType='DEBUG'), self.settings['development.settings']['url']) 138 # index = self.configureIndexContent(frontend.assemble(assemblyMode='DEVELOPMENT', versionType='DEBUG'), self.settings['development.settings']['url'])
130 ## self.writeToFolder(self.developmentTargetFolder(), os.path.join(frontend.module, 'index_development' + submoduleExtension + '.html'), index) 139 ## self.writeToFolder(self.developmentTargetFolder(), os.path.join(frontend.module, 'index_development' + submoduleExtension + '.html'), index)
131 # self.writeToFolder(self.developmentTargetFolder(), os.path.join(frontend.module + submoduleExtension + '.html'), index) 140 # self.writeToFolder(self.developmentTargetFolder(), os.path.join(frontend.module + submoduleExtension + '.html'), index)
132 141
133 142
134#=================================================================== 143#===================================================================