author | Clipperz <info@clipperz.com> | 2013-01-09 10:37:39 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-09 10:37:39 (UTC) |
commit | 5996ee475c193f08a713eb53338e4769c2716aa7 (patch) (unidiff) | |
tree | 18947a78d3946635ace383bfc3bacdabda11aafd /scripts | |
parent | 813c3245eebfebf9d951e082b9a7473d0116b63a (diff) | |
download | clipperz-5996ee475c193f08a713eb53338e4769c2716aa7.zip clipperz-5996ee475c193f08a713eb53338e4769c2716aa7.tar.gz clipperz-5996ee475c193f08a713eb53338e4769c2716aa7.tar.bz2 |
Fixed build script
Changed the build script in order to replace placeholders even if present multiple times
-rw-r--r-- | scripts/builder/frontendBuilder.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/scripts/builder/frontendBuilder.py b/scripts/builder/frontendBuilder.py index fc603c4..e52c31e 100644 --- a/scripts/builder/frontendBuilder.py +++ b/scripts/builder/frontendBuilder.py | |||
@@ -1,420 +1,420 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
2 | # -*- coding: UTF-8 -*- | 2 | # -*- coding: UTF-8 -*- |
3 | 3 | ||
4 | import sys, os, re | 4 | import sys, os, re |
5 | import cssmin | 5 | import cssmin |
6 | import jsmin | 6 | import jsmin |
7 | import codecs | 7 | import codecs |
8 | import shutil | 8 | import shutil |
9 | import StringIO | 9 | import StringIO |
10 | import urllib | 10 | import urllib |
11 | 11 | ||
12 | import main | 12 | import main |
13 | 13 | ||
14 | #=============================================================================== | 14 | #=============================================================================== |
15 | 15 | ||
16 | class FrontendBuilder(object): | 16 | class FrontendBuilder(object): |
17 | 17 | ||
18 | def __init__ (self, frontend, settings, repositoryVersion): | 18 | def __init__ (self, frontend, settings, repositoryVersion): |
19 | if '.' in frontend: | 19 | if '.' in frontend: |
20 | moduleComponents = frontend.split('.') | 20 | moduleComponents = frontend.split('.') |
21 | self.module = moduleComponents[0] | 21 | self.module = moduleComponents[0] |
22 | self.submodule = moduleComponents[1] | 22 | self.submodule = moduleComponents[1] |
23 | else: | 23 | else: |
24 | self.module = frontend | 24 | self.module = frontend |
25 | self.submodule = frontend | 25 | self.submodule = frontend |
26 | 26 | ||
27 | self.settings = settings | 27 | self.settings = settings |
28 | self.projectDir = main.projectBaseDir() | 28 | self.projectDir = main.projectBaseDir() |
29 | # self.repository = repository.repositoryWithPath(self.projectDir) | 29 | # self.repository = repository.repositoryWithPath(self.projectDir) |
30 | self.repositoryVersion = repositoryVersion | 30 | self.repositoryVersion = repositoryVersion |
31 | self.processedFiles = {} | 31 | self.processedFiles = {} |
32 | 32 | ||
33 | #--------------------------------------------------------------------------- | 33 | #--------------------------------------------------------------------------- |
34 | 34 | ||
35 | def name (self): | 35 | def name (self): |
36 | raise NotImplementedError() | 36 | raise NotImplementedError() |
37 | 37 | ||
38 | 38 | ||
39 | def copyStaticResources (self, targetFolder): | 39 | def copyStaticResources (self, targetFolder): |
40 | raise NotImplementedError() | 40 | raise NotImplementedError() |
41 | 41 | ||
42 | #--------------------------------------------------------------------------- | 42 | #--------------------------------------------------------------------------- |
43 | 43 | ||
44 | def log (self, message): | 44 | def log (self, message): |
45 | module = self.module | 45 | module = self.module |
46 | if (self.module != self.submodule): | 46 | if (self.module != self.submodule): |
47 | module = module + "." + self.submodule | 47 | module = module + "." + self.submodule |
48 | print "frontend [" + module + "]: " + message | 48 | print "frontend [" + module + "]: " + message |
49 | 49 | ||
50 | 50 | ||
51 | def absolutePathForSources (self): | 51 | def absolutePathForSources (self): |
52 | return os.path.join(self.projectDir, 'frontend', self.module) | 52 | return os.path.join(self.projectDir, 'frontend', self.module) |
53 | 53 | ||
54 | 54 | ||
55 | def absolutePathForSourceFile (self, basePath, file): | 55 | def absolutePathForSourceFile (self, basePath, file): |
56 | return os.path.join(self.absolutePathForSources(), basePath, file) | 56 | return os.path.join(self.absolutePathForSources(), basePath, file) |
57 | 57 | ||
58 | 58 | ||
59 | def absolutePathForTargetFile (self, folder, basePath, file): | 59 | def absolutePathForTargetFile (self, folder, basePath, file): |
60 | return os.path.join(folder, self.module, basePath, file) | 60 | return os.path.join(folder, self.module, basePath, file) |
61 | 61 | ||
62 | 62 | ||
63 | def filterFiles (self, files): | 63 | def filterFiles (self, files): |
64 | result = [] | 64 | result = [] |
65 | 65 | ||
66 | for file in files: | 66 | for file in files: |
67 | if file.startswith('--'): | 67 | if file.startswith('--'): |
68 | pass | 68 | pass |
69 | else: | 69 | else: |
70 | result.append(file) | 70 | result.append(file) |
71 | 71 | ||
72 | return result | 72 | return result |
73 | 73 | ||
74 | 74 | ||
75 | def copyResources (self, sourceFolder, destinationFolder, fileType): | 75 | def copyResources (self, sourceFolder, destinationFolder, fileType): |
76 | if fileType in self.settings: | 76 | if fileType in self.settings: |
77 | for file in self.filterFiles(self.settings[fileType]): | 77 | for file in self.filterFiles(self.settings[fileType]): |
78 | src = self.absolutePathForSourceFile(fileType, file) | 78 | src = self.absolutePathForSourceFile(fileType, file) |
79 | dst = self.absolutePathForTargetFile(destinationFolder, fileType, file) | 79 | dst = self.absolutePathForTargetFile(destinationFolder, fileType, file) |
80 | main.createFolder(os.path.dirname(dst)) | 80 | main.createFolder(os.path.dirname(dst)) |
81 | shutil.copy2(src, dst) | 81 | shutil.copy2(src, dst) |
82 | else: | 82 | else: |
83 | srcFolder = os.path.join(self.absolutePathForSources(), fileType) | 83 | srcFolder = os.path.join(self.absolutePathForSources(), fileType) |
84 | dstFolder = os.path.join(destinationFolder, self.module, fileType) | 84 | dstFolder = os.path.join(destinationFolder, self.module, fileType) |
85 | if not(os.path.exists(dstFolder)): | 85 | if not(os.path.exists(dstFolder)): |
86 | shutil.copytree(srcFolder, dstFolder) | 86 | shutil.copytree(srcFolder, dstFolder) |
87 | 87 | ||
88 | # try: | 88 | # try: |
89 | # shutil.copytree(srcFolder, dstFolder) | 89 | # shutil.copytree(srcFolder, dstFolder) |
90 | # except: | 90 | # except: |
91 | # pass | 91 | # pass |
92 | 92 | ||
93 | 93 | ||
94 | 94 | ||
95 | def copyResourcesToFolder (self, targetFolder): | 95 | def copyResourcesToFolder (self, targetFolder): |
96 | self.copyResources(self.projectDir, targetFolder, 'css') | 96 | self.copyResources(self.projectDir, targetFolder, 'css') |
97 | self.copyResources(self.projectDir, targetFolder, 'js') | 97 | self.copyResources(self.projectDir, targetFolder, 'js') |
98 | self.copyResources(self.projectDir, targetFolder, 'images') | 98 | self.copyResources(self.projectDir, targetFolder, 'images') |
99 | self.copyStaticResources(targetFolder) | 99 | self.copyStaticResources(targetFolder) |
100 | 100 | ||
101 | 101 | ||
102 | def loadFilesContent (self, basePath, files): | 102 | def loadFilesContent (self, basePath, files): |
103 | result = "" | 103 | result = "" |
104 | 104 | ||
105 | for file in self.filterFiles(files): | 105 | for file in self.filterFiles(files): |
106 | try: | 106 | try: |
107 | fileHandler = codecs.open(self.absolutePathForSourceFile(basePath, file), 'r', 'utf-8') | 107 | fileHandler = codecs.open(self.absolutePathForSourceFile(basePath, file), 'r', 'utf-8') |
108 | except: | 108 | except: |
109 | print "FILE: " + file | 109 | print "FILE: " + file |
110 | 110 | ||
111 | result += fileHandler.read() + '\n' | 111 | result += fileHandler.read() + '\n' |
112 | fileHandler.close() | 112 | fileHandler.close() |
113 | 113 | ||
114 | return result | 114 | return result |
115 | 115 | ||
116 | 116 | ||
117 | def template (self): | 117 | def template (self): |
118 | processedFile = 'html_template' | 118 | processedFile = 'html_template' |
119 | if not self.processedFiles.has_key(processedFile): | 119 | if not self.processedFiles.has_key(processedFile): |
120 | #self.processedFiles[processedFile] = self.loadFilesContent('html', ['index_template.html']) | 120 | #self.processedFiles[processedFile] = self.loadFilesContent('html', ['index_template.html']) |
121 | self.processedFiles[processedFile] = self.loadFilesContent('html', [self.settings['html.template']]) | 121 | self.processedFiles[processedFile] = self.loadFilesContent('html', [self.settings['html.template']]) |
122 | 122 | ||
123 | return self.processedFiles[processedFile] | 123 | return self.processedFiles[processedFile] |
124 | 124 | ||
125 | 125 | ||
126 | def cssminCompressor (self, css): | 126 | def cssminCompressor (self, css): |
127 | # package found here: | 127 | # package found here: |
128 | # - http://stackoverflow.com/questions/222581/python-script-for-minifying-css/2396777#2396777 | 128 | # - http://stackoverflow.com/questions/222581/python-script-for-minifying-css/2396777#2396777 |
129 | # actual downloaded version: http://pypi.python.org/pypi/cssmin/0.1.4 | 129 | # actual downloaded version: http://pypi.python.org/pypi/cssmin/0.1.4 |
130 | return cssmin.cssmin(css) | 130 | return cssmin.cssmin(css) |
131 | 131 | ||
132 | 132 | ||
133 | def regexCssCompressor (self, css): | 133 | def regexCssCompressor (self, css): |
134 | # http://stackoverflow.com/questions/222581/python-script-for-minifying-css/223689#223689 | 134 | # http://stackoverflow.com/questions/222581/python-script-for-minifying-css/223689#223689 |
135 | 135 | ||
136 | # remove comments - this will break a lot of hacks :-P | 136 | # remove comments - this will break a lot of hacks :-P |
137 | css = re.sub( r'\s*/\*\s*\*/', "$$HACK1$$", css ) # preserve IE<6 comment hack | 137 | css = re.sub( r'\s*/\*\s*\*/', "$$HACK1$$", css ) # preserve IE<6 comment hack |
138 | css = re.sub( r'/\*[\s\S]*?\*/', "", css ) | 138 | css = re.sub( r'/\*[\s\S]*?\*/', "", css ) |
139 | css = css.replace( "$$HACK1$$", '/**/' ) # preserve IE<6 comment hack | 139 | css = css.replace( "$$HACK1$$", '/**/' ) # preserve IE<6 comment hack |
140 | 140 | ||
141 | # url() doesn't need quotes | 141 | # url() doesn't need quotes |
142 | css = re.sub( r'url\((["\'])([^)]*)\1\)', r'url(\2)', css ) | 142 | css = re.sub( r'url\((["\'])([^)]*)\1\)', r'url(\2)', css ) |
143 | 143 | ||
144 | # spaces may be safely collapsed as generated content will collapse them anyway | 144 | # spaces may be safely collapsed as generated content will collapse them anyway |
145 | css = re.sub( r'\s+', ' ', css ) | 145 | css = re.sub( r'\s+', ' ', css ) |
146 | 146 | ||
147 | # shorten collapsable colors: #aabbcc to #abc | 147 | # shorten collapsable colors: #aabbcc to #abc |
148 | css = re.sub( r'#([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3(\s|;)', r'#\1\2\3\4', css ) | 148 | css = re.sub( r'#([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3(\s|;)', r'#\1\2\3\4', css ) |
149 | 149 | ||
150 | # fragment values can loose zeros | 150 | # fragment values can loose zeros |
151 | css = re.sub( r':\s*0(\.\d+([cm]m|e[mx]|in|p[ctx]))\s*;', r':\1;', css ) | 151 | css = re.sub( r':\s*0(\.\d+([cm]m|e[mx]|in|p[ctx]))\s*;', r':\1;', css ) |
152 | 152 | ||
153 | for rule in re.findall( r'([^{]+){([^}]*)}', css ): | 153 | for rule in re.findall( r'([^{]+){([^}]*)}', css ): |
154 | 154 | ||
155 | # we don't need spaces around operators | 155 | # we don't need spaces around operators |
156 | selectors = [re.sub( r'(?<=[\[\(>+=])\s+|\s+(?=[=~^$*|>+\]\)])', r'', selector.strip() ) for selector in rule[0].split( ',' )] | 156 | selectors = [re.sub( r'(?<=[\[\(>+=])\s+|\s+(?=[=~^$*|>+\]\)])', r'', selector.strip() ) for selector in rule[0].split( ',' )] |
157 | 157 | ||
158 | # order is important, but we still want to discard repetitions | 158 | # order is important, but we still want to discard repetitions |
159 | properties = {} | 159 | properties = {} |
160 | porder = [] | 160 | porder = [] |
161 | for prop in re.findall( '(.*?):(.*?)(;|$)', rule[1] ): | 161 | for prop in re.findall( '(.*?):(.*?)(;|$)', rule[1] ): |
162 | key = prop[0].strip().lower() | 162 | key = prop[0].strip().lower() |
163 | if key not in porder: porder.append( key ) | 163 | if key not in porder: porder.append( key ) |
164 | properties[ key ] = prop[1].strip() | 164 | properties[ key ] = prop[1].strip() |
165 | 165 | ||
166 | # output rule if it contains any declarations | 166 | # output rule if it contains any declarations |
167 | if properties: | 167 | if properties: |
168 | print "%s{%s}" % ( ','.join( selectors ), ''.join(['%s:%s;' % (key, properties[key]) for key in porder])[:-1] ) | 168 | print "%s{%s}" % ( ','.join( selectors ), ''.join(['%s:%s;' % (key, properties[key]) for key in porder])[:-1] ) |
169 | 169 | ||
170 | return css | 170 | return css |
171 | 171 | ||
172 | 172 | ||
173 | def compressCSS (self, css): | 173 | def compressCSS (self, css): |
174 | self.log("compressing CSS") | 174 | self.log("compressing CSS") |
175 | #return self.regexCssCompressor(css) | 175 | #return self.regexCssCompressor(css) |
176 | return self.cssminCompressor(css) | 176 | return self.cssminCompressor(css) |
177 | 177 | ||
178 | 178 | ||
179 | #========================================================================== | 179 | #========================================================================== |
180 | 180 | ||
181 | def compressJS_jsmin (self, js, description): | 181 | def compressJS_jsmin (self, js, description): |
182 | self.log("compressing " + description + " code") | 182 | self.log("compressing " + description + " code") |
183 | original = StringIO.StringIO(js) | 183 | original = StringIO.StringIO(js) |
184 | output = StringIO.StringIO() | 184 | output = StringIO.StringIO() |
185 | 185 | ||
186 | jsMinifier = jsmin.JavascriptMinify() | 186 | jsMinifier = jsmin.JavascriptMinify() |
187 | jsMinifier.minify(original, output) | 187 | jsMinifier.minify(original, output) |
188 | 188 | ||
189 | result = output.getvalue() | 189 | result = output.getvalue() |
190 | 190 | ||
191 | original.close() | 191 | original.close() |
192 | output.close() | 192 | output.close() |
193 | 193 | ||
194 | return result | 194 | return result |
195 | 195 | ||
196 | def compressJS_closureCompiler (self, js, description): | 196 | def compressJS_closureCompiler (self, js, description): |
197 | #Googles Closure compiler | 197 | #Googles Closure compiler |
198 | #java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js | 198 | #java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js |
199 | 199 | ||
200 | result = js | 200 | result = js |
201 | 201 | ||
202 | return result | 202 | return result |
203 | 203 | ||
204 | 204 | ||
205 | def compressJS (self, js, description): | 205 | def compressJS (self, js, description): |
206 | return self.compressJS_jsmin(js, description) | 206 | return self.compressJS_jsmin(js, description) |
207 | #return self.compressJS_closureCompiler(js, description) | 207 | #return self.compressJS_closureCompiler(js, description) |
208 | 208 | ||
209 | 209 | ||
210 | #========================================================================== | 210 | #========================================================================== |
211 | 211 | ||
212 | def packBookmarklet (self, bookmakeletCode, version): | 212 | def packBookmarklet (self, bookmakeletCode, version): |
213 | replacers = [ | 213 | replacers = [ |
214 | ('isLoginForm', 'ilf'), | 214 | ('isLoginForm', 'ilf'), |
215 | ('findLoginForm', 'flf'), | 215 | ('findLoginForm', 'flf'), |
216 | ('findLoginForm', 'flf'), | 216 | ('findLoginForm', 'flf'), |
217 | ('formParameters', 'fp' ), | 217 | ('formParameters', 'fp' ), |
218 | ('pageParameters', 'pp' ), | 218 | ('pageParameters', 'pp' ), |
219 | ('serializeJSON', 'sj' ), | 219 | ('serializeJSON', 'sj' ), |
220 | ('reprString', 'rs' ), | 220 | ('reprString', 'rs' ), |
221 | ('logFormParameters', 'lfp'), | 221 | ('logFormParameters', 'lfp'), |
222 | ('loadClipperzBookmarklet','lcb'), | 222 | ('loadClipperzBookmarklet','lcb'), |
223 | ('loginForm', 'lf' ), | 223 | ('loginForm', 'lf' ), |
224 | ('parameters', 'p' ), | 224 | ('parameters', 'p' ), |
225 | ('inputElementValues', 'iev'), | 225 | ('inputElementValues', 'iev'), |
226 | ] | 226 | ] |
227 | result = self.compressJS(bookmakeletCode, version + " bookmarklet") | 227 | result = self.compressJS(bookmakeletCode, version + " bookmarklet") |
228 | 228 | ||
229 | result = re.sub('\n', ' ', result) #Fit all in a single line | 229 | result = re.sub('\n', ' ', result) #Fit all in a single line |
230 | # result = re.sub('\s+', ' ', result) #Collapse "redundant" spaces. WARNING: this could have some evil side effects on constant strings used inside to code!! | 230 | # result = re.sub('\s+', ' ', result) #Collapse "redundant" spaces. WARNING: this could have some evil side effects on constant strings used inside to code!! |
231 | # result = re.sub('\s?([,\+=\(\)\{\};])\s?', '\\1', result) | 231 | # result = re.sub('\s?([,\+=\(\)\{\};])\s?', '\\1', result) |
232 | 232 | ||
233 | for replacer in replacers: | 233 | for replacer in replacers: |
234 | result = re.sub(replacer[0], replacer[1], result) | 234 | result = re.sub(replacer[0], replacer[1], result) |
235 | 235 | ||
236 | # <!-- escaping required to handle the bookmarklet code within the javascript code --> | 236 | # <!-- escaping required to handle the bookmarklet code within the javascript code --> |
237 | result = re.sub('\://', '%3a%2f%2f',result) | 237 | result = re.sub('\://', '%3a%2f%2f',result) |
238 | result = re.sub('/', '%2f', result) | 238 | result = re.sub('/', '%2f', result) |
239 | # result = re.sub('"', '%22', result) | 239 | # result = re.sub('"', '%22', result) |
240 | result = re.sub('"', '\\"', result) | 240 | result = re.sub('"', '\\"', result) |
241 | result = re.sub('\"', '%22', result) | 241 | result = re.sub('\"', '%22', result) |
242 | result = re.sub('\'', '%22', result) | 242 | result = re.sub('\'', '%22', result) |
243 | result = re.sub('\\\\', '%5c', result) | 243 | result = re.sub('\\\\', '%5c', result) |
244 | result = result.strip() | 244 | result = result.strip() |
245 | result = 'javascript:' + result | 245 | result = 'javascript:' + result |
246 | 246 | ||
247 | # replacers = [ | 247 | # replacers = [ |
248 | # ('aForm', '_1' ), | 248 | # ('aForm', '_1' ), |
249 | # ('inputFields', '_2' ), | 249 | # ('inputFields', '_2' ), |
250 | # ('passwordFieldsFound','_3' ), | 250 | # ('passwordFieldsFound','_3' ), |
251 | # ('aDocument', '_6' ), | 251 | # ('aDocument', '_6' ), |
252 | # ('aLevel', '_7' ), | 252 | # ('aLevel', '_7' ), |
253 | # # ('result', '_8' ), | 253 | # # ('result', '_8' ), |
254 | # ('documentForms', '_9' ), | 254 | # ('documentForms', '_9' ), |
255 | # ('iFrames', '_c' ), | 255 | # ('iFrames', '_c' ), |
256 | # ('anInputElement', '_d' ), | 256 | # ('anInputElement', '_d' ), |
257 | # ('options', '_f' ), | 257 | # ('options', '_f' ), |
258 | # ('option', '_12'), | 258 | # ('option', '_12'), |
259 | # ('aLoginForm', '_13'), | 259 | # ('aLoginForm', '_13'), |
260 | # # ('action', '_17'), | 260 | # # ('action', '_17'), |
261 | # ('radioValues', '_18'), | 261 | # ('radioValues', '_18'), |
262 | # ('radioValueName', '_19'), | 262 | # ('radioValueName', '_19'), |
263 | # ('inputElement', '_1a'), | 263 | # ('inputElement', '_1a'), |
264 | # ('elementValues', '_1b'), | 264 | # ('elementValues', '_1b'), |
265 | # ('radioValue', '_1c'), | 265 | # ('radioValue', '_1c'), |
266 | # ('values', '_1d'), | 266 | # ('values', '_1d'), |
267 | # ('objtype', '_21'), | 267 | # ('objtype', '_21'), |
268 | # ('useKey', '_27'), | 268 | # ('useKey', '_27'), |
269 | # ('bookmarkletDiv', '_28'), | 269 | # ('bookmarkletDiv', '_28'), |
270 | # ('someParameters', '_29'), | 270 | # ('someParameters', '_29'), |
271 | # ('anException', '_2a'), | 271 | # ('anException', '_2a'), |
272 | # ('newDiv', '_2b'), | 272 | # ('newDiv', '_2b'), |
273 | # ('base_url', '_2c'), | 273 | # ('base_url', '_2c'), |
274 | # ('help_url', '_2d'), | 274 | # ('help_url', '_2d'), |
275 | # ('logo_image_url', '_2e'), | 275 | # ('logo_image_url', '_2e'), |
276 | # ('background_image_url','_2f'), | 276 | # ('background_image_url','_2f'), |
277 | # ('close_image_url', '_30'), | 277 | # ('close_image_url', '_30'), |
278 | # #('bookmarklet_textarea','_31'), | 278 | # #('bookmarklet_textarea','_31'), |
279 | # ('innerHTML', '_32'), | 279 | # ('innerHTML', '_32'), |
280 | # ] | 280 | # ] |
281 | # for replacer in replacers: | 281 | # for replacer in replacers: |
282 | # result = re.sub('([^\.])' + replacer[0], '\\1' + replacer[1], result) | 282 | # result = re.sub('([^\.])' + replacer[0], '\\1' + replacer[1], result) |
283 | 283 | ||
284 | # replacers = [ | 284 | # replacers = [ |
285 | # ('headNode', '_1' ), | 285 | # ('headNode', '_1' ), |
286 | # ('clipperzScriptNode','_2' ), | 286 | # ('clipperzScriptNode','_2' ), |
287 | # ] | 287 | # ] |
288 | # for replacer in replacers: | 288 | # for replacer in replacers: |
289 | # result = re.sub('([^\.])' + replacer[0], '\\1' + replacer[1], result) | 289 | # result = re.sub('([^\.])' + replacer[0], '\\1' + replacer[1], result) |
290 | 290 | ||
291 | # result = re.sub(';', ';\n', result) | 291 | # result = re.sub(';', ';\n', result) |
292 | 292 | ||
293 | return result | 293 | return result |
294 | 294 | ||
295 | 295 | ||
296 | 296 | ||
297 | def bookmarklet (self): | 297 | def bookmarklet (self): |
298 | cacheKey = 'bookmarklet' | 298 | cacheKey = 'bookmarklet' |
299 | if not self.processedFiles.has_key(cacheKey): | 299 | if not self.processedFiles.has_key(cacheKey): |
300 | result = 'bookmarklet="' + self.packBookmarklet(self.loadFilesContent('js', ['Bookmarklet.js']), "regular") + '";bookmarklet_ie="' + self.packBookmarklet(self.loadFilesContent('js', ['Bookmarklet_IE.js']), "IE") + '";' | 300 | result = 'bookmarklet="' + self.packBookmarklet(self.loadFilesContent('js', ['Bookmarklet.js']), "regular") + '";bookmarklet_ie="' + self.packBookmarklet(self.loadFilesContent('js', ['Bookmarklet_IE.js']), "IE") + '";' |
301 | self.processedFiles[cacheKey] = result | 301 | self.processedFiles[cacheKey] = result |
302 | else: | 302 | else: |
303 | result = self.processedFiles[cacheKey] | 303 | result = self.processedFiles[cacheKey] |
304 | 304 | ||
305 | return result | 305 | return result |
306 | 306 | ||
307 | 307 | ||
308 | def replaceTemplatePlaceholders (self, pageTitle, copyright, css, code, jsLoadMode, version, versionType): | 308 | def replaceTemplatePlaceholders (self, pageTitle, copyright, css, code, jsLoadMode, version, versionType): |
309 | result = self.template() | 309 | result = self.template() |
310 | 310 | ||
311 | result = result.replace('@page.title@', pageTitle, 1) | 311 | result = result.replace('@page.title@', pageTitle) |
312 | result = result.replace('@copyright@', copyright, 1) | 312 | result = result.replace('@copyright@', copyright) |
313 | result = result.replace('@css@', css, 1) | 313 | result = result.replace('@css@', css) |
314 | #result = result.replace('@bookmarklet@', bookmarklet,1) | 314 | #result = result.replace('@bookmarklet@', bookmarklet) |
315 | result = result.replace('@application.version@', version, 1) | 315 | result = result.replace('@application.version@', version) |
316 | result = result.replace('@application.version.type@', versionType,1) | 316 | result = result.replace('@application.version.type@',versionType) |
317 | result = result.replace('@js_' + jsLoadMode + '@', code, 1) | 317 | result = result.replace('@js_' + jsLoadMode + '@', code) |
318 | 318 | ||
319 | result = re.sub('@js_[^@]+@', '', result) | 319 | result = re.sub('@js_[^@]+@', '', result) |
320 | 320 | ||
321 | return result | 321 | return result |
322 | 322 | ||
323 | 323 | ||
324 | def assembleCopyrightHeader (self): | 324 | def assembleCopyrightHeader (self): |
325 | processedFile = 'copyright' | 325 | processedFile = 'copyright' |
326 | if not self.processedFiles.has_key(processedFile): | 326 | if not self.processedFiles.has_key(processedFile): |
327 | #self.log("assembling copyright header") | 327 | #self.log("assembling copyright header") |
328 | copyrightValues = self.settings['copyright.values'] | 328 | copyrightValues = self.settings['copyright.values'] |
329 | license = self.loadFilesContent('../../properties', ['license.txt']) | 329 | license = self.loadFilesContent('../../properties', ['license.txt']) |
330 | result = self.loadFilesContent('properties', ['creditsAndCopyrights.txt']) | 330 | result = self.loadFilesContent('properties', ['creditsAndCopyrights.txt']) |
331 | 331 | ||
332 | result = re.sub('@clipperz.license@', license, result) | 332 | result = re.sub('@clipperz.license@', license, result) |
333 | for key in copyrightValues: | 333 | for key in copyrightValues: |
334 | result = re.sub('@'+key+'@', copyrightValues[key], result) | 334 | result = re.sub('@'+key+'@', copyrightValues[key], result) |
335 | 335 | ||
336 | self.processedFiles[processedFile] = result | 336 | self.processedFiles[processedFile] = result |
337 | 337 | ||
338 | return self.processedFiles[processedFile] | 338 | return self.processedFiles[processedFile] |
339 | 339 | ||
340 | 340 | ||
341 | def cssTagsForFiles (self, basePath, files): | 341 | def cssTagsForFiles (self, basePath, files): |
342 | #<link rel="stylesheet" type="text/css" href="./css/reset-min.css" /> | 342 | #<link rel="stylesheet" type="text/css" href="./css/reset-min.css" /> |
343 | return '\n'.join(map(lambda file: '<link rel="stylesheet" type="text/css" href="' + basePath + '/' + file + '" />', files)) | 343 | return '\n'.join(map(lambda file: '<link rel="stylesheet" type="text/css" href="' + basePath + '/' + file + '" />', files)) |
344 | 344 | ||
345 | 345 | ||
346 | def cssTagForContent (self, content): | 346 | def cssTagForContent (self, content): |
347 | return '<style type="text/css">' + content + '</style>' | 347 | return '<style type="text/css">' + content + '</style>' |
348 | 348 | ||
349 | 349 | ||
350 | def scriptTagsForFiles (self, basePath, files): | 350 | def scriptTagsForFiles (self, basePath, files): |
351 | #<script type='text/javascript' src='./js/src/bookmarklet.js'></script> | 351 | #<script type='text/javascript' src='./js/src/bookmarklet.js'></script> |
352 | return '\n'.join(map(lambda file: '<script type="text/javascript" src="' + basePath + '/' + file + '" charset="utf-8"></script>', files)) | 352 | return '\n'.join(map(lambda file: '<script type="text/javascript" src="' + basePath + '/' + file + '" charset="utf-8"></script>', files)) |
353 | 353 | ||
354 | 354 | ||
355 | def scriptTagForContent (self, content): | 355 | def scriptTagForContent (self, content): |
356 | return '<script>' + content + '</script>' | 356 | return '<script>' + content + '</script>' |
357 | 357 | ||
358 | 358 | ||
359 | def assembleVersion (self, pageTitle, copyright, css, js, jsLoadMode, version, versionType): | 359 | def assembleVersion (self, pageTitle, copyright, css, js, jsLoadMode, version, versionType): |
360 | cacheKey = version + "-" + versionType | 360 | cacheKey = version + "-" + versionType |
361 | if not self.processedFiles.has_key(cacheKey): | 361 | if not self.processedFiles.has_key(cacheKey): |
362 | result = self.replaceTemplatePlaceholders(pageTitle, copyright, css, js, jsLoadMode, version, versionType) | 362 | result = self.replaceTemplatePlaceholders(pageTitle, copyright, css, js, jsLoadMode, version, versionType) |
363 | self.processedFiles[cacheKey] = result | 363 | self.processedFiles[cacheKey] = result |
364 | else: | 364 | else: |
365 | result = self.processedFiles[cacheKey] | 365 | result = self.processedFiles[cacheKey] |
366 | 366 | ||
367 | #self.log("# cacheKey:\n" + result) | 367 | #self.log("# cacheKey:\n" + result) |
368 | return result | 368 | return result |
369 | 369 | ||
370 | 370 | ||
371 | def assemble (self, assemblyMode='INSTALL', versionType='LIVE'): | 371 | def assemble (self, assemblyMode='INSTALL', versionType='LIVE'): |
372 | 372 | ||
373 | if versionType == 'LIVE': | 373 | if versionType == 'LIVE': |
374 | pageTitle = "Clipperz - " + self.module | 374 | pageTitle = "Clipperz - " + self.module |
375 | else: | 375 | else: |
376 | pageTitle = "Clipperz - " + self.module + " [" + versionType + " - " + assemblyMode +"]" | 376 | pageTitle = "Clipperz - " + self.module + " [" + versionType + " - " + assemblyMode +"]" |
377 | 377 | ||
378 | if assemblyMode == 'INSTALL': | 378 | if assemblyMode == 'INSTALL': |
379 | copyright = self.assembleCopyrightHeader() | 379 | copyright = self.assembleCopyrightHeader() |
380 | css =self.cssTagForContent(self.compressCSS(self.loadFilesContent('css', self.settings['css']))) | 380 | css =self.cssTagForContent(self.compressCSS(self.loadFilesContent('css', self.settings['css']))) |
381 | js =self.scriptTagForContent( | 381 | js =self.scriptTagForContent( |
382 | self.bookmarklet() + | 382 | self.bookmarklet() + |
383 | '\n' + | 383 | '\n' + |
384 | self.compressJS(self.loadFilesContent('js', self.settings['js']), "application") | 384 | self.compressJS(self.loadFilesContent('js', self.settings['js']), "application") |
385 | ) | 385 | ) |
386 | jsLoadMode = 'EMBEDDED' | 386 | jsLoadMode = 'EMBEDDED' |
387 | 387 | ||
388 | elif assemblyMode == 'DEBUG': | 388 | elif assemblyMode == 'DEBUG': |
389 | copyright = self.assembleCopyrightHeader() | 389 | copyright = self.assembleCopyrightHeader() |
390 | css =self.cssTagsForFiles('./css', self.filterFiles(self.settings['css'])) | 390 | css =self.cssTagsForFiles('./css', self.filterFiles(self.settings['css'])) |
391 | js =self.scriptTagForContent(self.bookmarklet()) + \ | 391 | js =self.scriptTagForContent(self.bookmarklet()) + \ |
392 | '\n' + \ | 392 | '\n' + \ |
393 | self.scriptTagsForFiles('./js', self.filterFiles(self.settings['js'])) | 393 | self.scriptTagsForFiles('./js', self.filterFiles(self.settings['js'])) |
394 | jsLoadMode = 'LINKED' | 394 | jsLoadMode = 'LINKED' |
395 | 395 | ||
396 | elif assemblyMode == 'DEVELOPMENT': | 396 | elif assemblyMode == 'DEVELOPMENT': |
397 | copyright = "" | 397 | copyright = "" |
398 | css =self.cssTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'css')), self.filterFiles(self.settings['css'])) | 398 | css =self.cssTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'css')), self.filterFiles(self.settings['css'])) |
399 | js =self.scriptTagForContent(self.bookmarklet()) + \ | 399 | js =self.scriptTagForContent(self.bookmarklet()) + \ |
400 | '\n' + \ | 400 | '\n' + \ |
401 | self.scriptTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'js')), self.filterFiles(self.settings['js'])) | 401 | self.scriptTagsForFiles('file://' + str(os.path.join(self.absolutePathForSources(), 'js')), self.filterFiles(self.settings['js'])) |
402 | jsLoadMode = 'LINKED' | 402 | jsLoadMode = 'LINKED' |
403 | versionType = 'development' | 403 | versionType = 'development' |
404 | 404 | ||
405 | else: | 405 | else: |
406 | raise NotImplementedError() | 406 | raise NotImplementedError() |
407 | 407 | ||
408 | return self.assembleVersion( | 408 | return self.assembleVersion( |
409 | pageTitle = pageTitle, | 409 | pageTitle = pageTitle, |
410 | copyright = copyright, | 410 | copyright = copyright, |
411 | css = css, | 411 | css = css, |
412 | js = js, | 412 | js = js, |
413 | jsLoadMode = jsLoadMode, | 413 | jsLoadMode = jsLoadMode, |
414 | version = self.repositoryVersion, | 414 | version = self.repositoryVersion, |
415 | versionType = versionType | 415 | versionType = versionType |
416 | ) | 416 | ) |
417 | 417 | ||
418 | 418 | ||
419 | 419 | ||
420 | 420 | ||