summaryrefslogtreecommitdiff
authorGiulio Cesare Solaroli <giulio.cesare@solaroli.it>2012-03-17 14:43:30 (UTC)
committer Giulio Cesare Solaroli <giulio.cesare@solaroli.it>2012-03-17 14:43:30 (UTC)
commit58ec03cc3dba43ccd9826148b99bf3d7b8e97d8a (patch) (unidiff)
treec12d695420bb6281708b367d52970eac5615ef1c
parente7e021141d7906b537b3622ed706017f31222dfd (diff)
parente61e994abb9738d98447b203b9908793da6f560a (diff)
downloadclipperz-58ec03cc3dba43ccd9826148b99bf3d7b8e97d8a.zip
clipperz-58ec03cc3dba43ccd9826148b99bf3d7b8e97d8a.tar.gz
clipperz-58ec03cc3dba43ccd9826148b99bf3d7b8e97d8a.tar.bz2
Merge pull request #31 from gcsolaroli/master
Updated build scripts
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--backend/php/properties/php.properties.json4
-rw-r--r--scripts/builder/backendBuilder.py21
-rw-r--r--scripts/builder/frontendBuilder.py5
-rw-r--r--scripts/builder/repository.py12
4 files changed, 29 insertions, 13 deletions
diff --git a/backend/php/properties/php.properties.json b/backend/php/properties/php.properties.json
index 8ce703a..dd25b09 100644
--- a/backend/php/properties/php.properties.json
+++ b/backend/php/properties/php.properties.json
@@ -1,9 +1,9 @@
1{ 1{
2 "request.path": "index.php", 2 "request.path": "index.php",
3 "should.pay.toll": "false" 3 "should.pay.toll": "false",
4 4
5 "development.settings": { 5 "development.settings": {
6 "url": "http://localhost/php/clipperz" 6 "url": "http://localhost/php/clipperz"
7 } 7 }
8 8
9} \ No newline at end of file 9}
diff --git a/scripts/builder/backendBuilder.py b/scripts/builder/backendBuilder.py
index 3e61955..5b91678 100644
--- a/scripts/builder/backendBuilder.py
+++ b/scripts/builder/backendBuilder.py
@@ -62,57 +62,70 @@ class BackendBuilder(object):
62 file.write(content.encode('utf-8')) 62 file.write(content.encode('utf-8'))
63 file.close() 63 file.close()
64 64
65 65
66 def configureIndexContent (self, indexContent, requestPathPrefix = ".."): 66 def configureIndexContent (self, indexContent, requestPathPrefix = ".."):
67 result = indexContent 67 result = indexContent
68 result = result.replace( '@request.path@', requestPathPrefix + '/' + self.settings['request.path'] ) 68 result = result.replace( '@request.path@', requestPathPrefix + '/' + self.settings['request.path'] )
69 result = result.replace( '@should.pay.toll@', self.settings['should.pay.toll'] ) 69 result = result.replace( '@should.pay.toll@', self.settings['should.pay.toll'] )
70 70
71 return result 71 return result
72 72
73 73
74 def logChecksums (self, content, message): 74 def logChecksums (self, content, message):
75 md5Digest = hashlib.md5(content.encode('utf-8')).hexdigest() 75 md5Digest = hashlib.md5(content.encode('utf-8')).hexdigest()
76 shaDigest = hashlib.sha1(content.encode('utf-8')).hexdigest() 76 shaDigest = hashlib.sha1(content.encode('utf-8')).hexdigest()
77 sha256Digest= hashlib.sha256(content.encode('utf-8')).hexdigest() 77 sha256Digest= hashlib.sha256(content.encode('utf-8')).hexdigest()
78 print message + ": " + md5Digest + " (md5)" 78 print message + ": " + md5Digest + " (md5)"
79 print message + ": " + shaDigest + " (sha1)" 79 print message + ": " + shaDigest + " (sha1)"
80 print message + ": " + sha256Digest + " (sha256)" 80 print message + ": " + sha256Digest + " (sha256)"
81 81
82 82
83 def shouldCompileCode (self): 83 def shouldCompileCode (self):
84 return ('debug' in self.versions) or ('install' in self.versions) 84 return ('debug' in self.versions) or ('install' in self.versions)
85 85
86 86
87 def run (self): 87 def run (self):
88 print self.name() + " - RUN" 88 print self.name() + " - RUN"
89 89
90 if self.shouldCompileCode(): 90 if self.shouldCompileCode():
91 self.compileCode() 91 self.compileCode()
92 92
93 for frontend in self.frontends: 93 for frontend in self.frontends:
94 if (frontend.module == frontend.submodule):
95 submoduleExtension = ''
96 else:
97 submoduleExtension = '.' + frontend.submodule
98
94 main.createFolder(os.path.join(self.frontEndTempFolder(), frontend.module)) 99 main.createFolder(os.path.join(self.frontEndTempFolder(), frontend.module))
95 100
96 if 'debug' in self.versions: 101 if 'debug' in self.versions:
97 frontend.copyResourcesToFolder(self.frontEndTempFolder()) 102 frontend.copyResourcesToFolder(self.frontEndTempFolder())
98 103
99 index = self.configureIndexContent(frontend.assemble(assemblyMode='DEBUG', versionType='DEBUG')) 104 index = self.configureIndexContent(frontend.assemble(assemblyMode='DEBUG', versionType='DEBUG'))
100 self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index_debug.html'), index) 105 self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index_debug' + submoduleExtension + '.html'), index)
101 106
102 if 'install' in self.versions: 107 if 'install' in self.versions:
103 index = self.configureIndexContent(frontend.assemble()) 108 index = self.configureIndexContent(frontend.assemble())
104 self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index.html'), index) 109 self.writeToFolder(self.frontEndTempFolder(), os.path.join(frontend.module, 'index' + submoduleExtension + '.html'), index)
105 110
106 self.logChecksums(index, "[" + self.name() + " - " + frontend.module + "] index.html checksum") 111 self.logChecksums(index, "[" + self.name() + " - " + frontend.module + "] index" + submoduleExtension + ".html checksum")
107 112
108 self.createPackage() 113 self.createPackage()
109 114
110 if 'development' in self.versions: 115 if 'development' in self.versions:
111 for frontend in self.frontends: 116 for frontend in self.frontends:
117 if (frontend.module == frontend.submodule):
118 submoduleExtension = ''
119 else:
120 submoduleExtension = '.' + frontend.submodule
121
122 print "FRONTEND module: " + frontend.module
123 print "FRONTEND submodule: " + frontend.submodule
124
112 main.createFolder(os.path.join(self.developmentTargetFolder(), frontend.module)) 125 main.createFolder(os.path.join(self.developmentTargetFolder(), frontend.module))
113 126
114 index = self.configureIndexContent(frontend.assemble(assemblyMode='DEVELOPMENT', versionType='DEBUG'), self.settings['development.settings']['url']) 127 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.html'), index) 128 self.writeToFolder(self.developmentTargetFolder(), os.path.join(frontend.module, 'index' + submoduleExtension + '.html'), index)
116 129
117 130
118#=================================================================== 131#===================================================================
diff --git a/scripts/builder/frontendBuilder.py b/scripts/builder/frontendBuilder.py
index dae837b..1f0f92f 100644
--- a/scripts/builder/frontendBuilder.py
+++ b/scripts/builder/frontendBuilder.py
@@ -59,65 +59,66 @@ class FrontendBuilder(object):
59 59
60 def copyResources (self, sourceFolder, destinationFolder, fileType): 60 def copyResources (self, sourceFolder, destinationFolder, fileType):
61 for file in self.filterFiles(self.settings[fileType]): 61 for file in self.filterFiles(self.settings[fileType]):
62 src = self.absolutePathForSourceFile(fileType, file) 62 src = self.absolutePathForSourceFile(fileType, file)
63 dst = self.absolutePathForTargetFile(destinationFolder, fileType, file) 63 dst = self.absolutePathForTargetFile(destinationFolder, fileType, file)
64 main.createFolder(os.path.dirname(dst)) 64 main.createFolder(os.path.dirname(dst))
65 shutil.copy2(src, dst) 65 shutil.copy2(src, dst)
66 66
67 67
68 def copyResourcesToFolder (self, targetFolder): 68 def copyResourcesToFolder (self, targetFolder):
69 self.copyResources(self.projectDir, targetFolder, 'css') 69 self.copyResources(self.projectDir, targetFolder, 'css')
70 self.copyResources(self.projectDir, targetFolder, 'js') 70 self.copyResources(self.projectDir, targetFolder, 'js')
71 71
72 72
73 def loadFilesContent (self, basePath, files): 73 def loadFilesContent (self, basePath, files):
74 result = "" 74 result = ""
75 75
76 for file in self.filterFiles(files): 76 for file in self.filterFiles(files):
77 try: 77 try:
78 fileHandler = codecs.open(self.absolutePathForSourceFile(basePath, file), 'r', 'utf-8') 78 fileHandler = codecs.open(self.absolutePathForSourceFile(basePath, file), 'r', 'utf-8')
79 except: 79 except:
80 print "FILE: " + file 80 print "FILE: " + file
81 81
82 result += fileHandler.read() + '\n' 82 result += fileHandler.read() + '\n'
83 fileHandler.close() 83 fileHandler.close()
84 84
85 return result 85 return result
86 86
87 87
88 def template (self): 88 def template (self):
89 processedFile = 'html_template' 89 processedFile = 'html_template'
90 if not self.processedFiles.has_key(processedFile): 90 if not self.processedFiles.has_key(processedFile):
91 self.processedFiles[processedFile] = self.loadFilesContent('html', ['index_template.html']) 91 #self.processedFiles[processedFile] = self.loadFilesContent('html', ['index_template.html'])
92 self.processedFiles[processedFile] = self.loadFilesContent('html', [self.settings['html.template']])
92 93
93 return self.processedFiles[processedFile] 94 return self.processedFiles[processedFile]
94 95
95 96
96 def cssminCompressor (self, css): 97 def cssminCompressor (self, css):
97 # package found here: 98 # package found here:
98 # - http://stackoverflow.com/questions/222581/python-script-for-minifying-css/2396777#2396777 99 # - http://stackoverflow.com/questions/222581/python-script-for-minifying-css/2396777#2396777
99 # actual downloaded version: http://pypi.python.org/pypi/cssmin/0.1.4 100 # actual downloaded version: http://pypi.python.org/pypi/cssmin/0.1.4
100 return cssmin.cssmin(css) 101 return cssmin.cssmin(css)
101 102
102 103
103 def regexCssCompressor (self, css): 104 def regexCssCompressor (self, css):
104 # http://stackoverflow.com/questions/222581/python-script-for-minifying-css/223689#223689 105 # http://stackoverflow.com/questions/222581/python-script-for-minifying-css/223689#223689
105 106
106 # remove comments - this will break a lot of hacks :-P 107 # remove comments - this will break a lot of hacks :-P
107 css = re.sub( r'\s*/\*\s*\*/', "$$HACK1$$", css ) # preserve IE<6 comment hack 108 css = re.sub( r'\s*/\*\s*\*/', "$$HACK1$$", css ) # preserve IE<6 comment hack
108 css = re.sub( r'/\*[\s\S]*?\*/', "", css ) 109 css = re.sub( r'/\*[\s\S]*?\*/', "", css )
109 css = css.replace( "$$HACK1$$", '/**/' ) # preserve IE<6 comment hack 110 css = css.replace( "$$HACK1$$", '/**/' ) # preserve IE<6 comment hack
110 111
111 # url() doesn't need quotes 112 # url() doesn't need quotes
112 css = re.sub( r'url\((["\'])([^)]*)\1\)', r'url(\2)', css ) 113 css = re.sub( r'url\((["\'])([^)]*)\1\)', r'url(\2)', css )
113 114
114 # spaces may be safely collapsed as generated content will collapse them anyway 115 # spaces may be safely collapsed as generated content will collapse them anyway
115 css = re.sub( r'\s+', ' ', css ) 116 css = re.sub( r'\s+', ' ', css )
116 117
117 # shorten collapsable colors: #aabbcc to #abc 118 # shorten collapsable colors: #aabbcc to #abc
118 css = re.sub( r'#([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3(\s|;)', r'#\1\2\3\4', css ) 119 css = re.sub( r'#([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3(\s|;)', r'#\1\2\3\4', css )
119 120
120 # fragment values can loose zeros 121 # fragment values can loose zeros
121 css = re.sub( r':\s*0(\.\d+([cm]m|e[mx]|in|p[ctx]))\s*;', r':\1;', css ) 122 css = re.sub( r':\s*0(\.\d+([cm]m|e[mx]|in|p[ctx]))\s*;', r':\1;', css )
122 123
123 for rule in re.findall( r'([^{]+){([^}]*)}', css ): 124 for rule in re.findall( r'([^{]+){([^}]*)}', css ):
@@ -290,65 +291,65 @@ class FrontendBuilder(object):
290 291
291 return result 292 return result
292 293
293 294
294 def assembleCopyrightHeader (self): 295 def assembleCopyrightHeader (self):
295 processedFile = 'copyright' 296 processedFile = 'copyright'
296 if not self.processedFiles.has_key(processedFile): 297 if not self.processedFiles.has_key(processedFile):
297 #self.log("assembling copyright header") 298 #self.log("assembling copyright header")
298 copyrightValues = self.settings['copyright.values'] 299 copyrightValues = self.settings['copyright.values']
299 license = self.loadFilesContent('../../properties', ['license.txt']) 300 license = self.loadFilesContent('../../properties', ['license.txt'])
300 result = self.loadFilesContent('properties', ['creditsAndCopyrights.txt']) 301 result = self.loadFilesContent('properties', ['creditsAndCopyrights.txt'])
301 302
302 result = re.sub('@clipperz.license@', license, result) 303 result = re.sub('@clipperz.license@', license, result)
303 for key in copyrightValues: 304 for key in copyrightValues:
304 result = re.sub('@'+key+'@', copyrightValues[key], result) 305 result = re.sub('@'+key+'@', copyrightValues[key], result)
305 306
306 self.processedFiles[processedFile] = result 307 self.processedFiles[processedFile] = result
307 308
308 return self.processedFiles[processedFile] 309 return self.processedFiles[processedFile]
309 310
310 311
311 def cssTagsForFiles (self, basePath, files): 312 def cssTagsForFiles (self, basePath, files):
312 #<link rel="stylesheet" type="text/css" href="./css/reset-min.css" /> 313 #<link rel="stylesheet" type="text/css" href="./css/reset-min.css" />
313 return '\n'.join(map(lambda file: '<link rel="stylesheet" type="text/css" href="' + basePath + '/' + file + '" />', files)) 314 return '\n'.join(map(lambda file: '<link rel="stylesheet" type="text/css" href="' + basePath + '/' + file + '" />', files))
314 315
315 316
316 def cssTagForContent (self, content): 317 def cssTagForContent (self, content):
317 return '<style type="text/css">' + content + '</style>' 318 return '<style type="text/css">' + content + '</style>'
318 319
319 320
320 def scriptTagsForFiles (self, basePath, files): 321 def scriptTagsForFiles (self, basePath, files):
321 #<script type='text/javascript' src='./js/src/bookmarklet.js'></script> 322 #<script type='text/javascript' src='./js/src/bookmarklet.js'></script>
322 return '\n'.join(map(lambda file: '<script type="text/javascript" src="' + basePath + '/' + file + '"></script>', files)) 323 return '\n'.join(map(lambda file: '<script type="text/javascript" src="' + basePath + '/' + file + '" charset="utf-8"></script>', files))
323 324
324 325
325 def scriptTagForContent (self, content): 326 def scriptTagForContent (self, content):
326 return '<script>' + content + '</script>' 327 return '<script>' + content + '</script>'
327 328
328 329
329 def assembleVersion (self, pageTitle, copyright, css, js, jsLoadMode, version, versionType): 330 def assembleVersion (self, pageTitle, copyright, css, js, jsLoadMode, version, versionType):
330 cacheKey = version + "-" + versionType 331 cacheKey = version + "-" + versionType
331 if not self.processedFiles.has_key(cacheKey): 332 if not self.processedFiles.has_key(cacheKey):
332 result = self.replaceTemplatePlaceholders(pageTitle, copyright, css, js, jsLoadMode, version, versionType) 333 result = self.replaceTemplatePlaceholders(pageTitle, copyright, css, js, jsLoadMode, version, versionType)
333 self.processedFiles[cacheKey] = result 334 self.processedFiles[cacheKey] = result
334 else: 335 else:
335 result = self.processedFiles[cacheKey] 336 result = self.processedFiles[cacheKey]
336 337
337 #self.log("# cacheKey:\n" + result) 338 #self.log("# cacheKey:\n" + result)
338 return result 339 return result
339 340
340 341
341 def assemble (self, assemblyMode='INSTALL', versionType='LIVE'): 342 def assemble (self, assemblyMode='INSTALL', versionType='LIVE'):
342 343
343 if versionType == 'LIVE': 344 if versionType == 'LIVE':
344 pageTitle = "Clipperz - " + self.module 345 pageTitle = "Clipperz - " + self.module
345 else: 346 else:
346 pageTitle = "Clipperz - " + self.module + " [" + versionType + " - " + assemblyMode +"]" 347 pageTitle = "Clipperz - " + self.module + " [" + versionType + " - " + assemblyMode +"]"
347 348
348 if assemblyMode == 'INSTALL': 349 if assemblyMode == 'INSTALL':
349 copyright = self.assembleCopyrightHeader() 350 copyright = self.assembleCopyrightHeader()
350 css =self.cssTagForContent(self.compressCSS(self.loadFilesContent('css', self.settings['css']))) 351 css =self.cssTagForContent(self.compressCSS(self.loadFilesContent('css', self.settings['css'])))
351 js =self.scriptTagForContent( 352 js =self.scriptTagForContent(
352 self.bookmarklet() + 353 self.bookmarklet() +
353 '\n' + 354 '\n' +
354 self.compressJS(self.loadFilesContent('js', self.settings['js']), "application") 355 self.compressJS(self.loadFilesContent('js', self.settings['js']), "application")
diff --git a/scripts/builder/repository.py b/scripts/builder/repository.py
index 89db9a5..f8528c2 100644
--- a/scripts/builder/repository.py
+++ b/scripts/builder/repository.py
@@ -1,75 +1,77 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2# -*- coding: UTF-8 -*- 2# -*- coding: UTF-8 -*-
3 3
4 4
5def repositoryWithPath (path): 5def repositoryWithPath (path):
6 try: 6 try:
7 from dulwich.repo import Repo 7 from git import Repo
8 8
9 repo = Repo(path) 9 repo = Repo(path)
10 result = GitRepository(repo, path) 10 result = GitRepository(repo, path)
11 except: 11 except ImportError:
12 print "Failed to import git, please install http://gitorious.org/git-python"
13 #except:
12 from mercurial import ui, hg 14 from mercurial import ui, hg
13 15
14 repo = hg.repository(ui.ui(), path) 16 repo = hg.repository(ui.ui(), path)
15 result = HgRepository(repo, path) 17 result = HgRepository(repo, path)
16 18
17 return result 19 return result
18 20
19 21
20#=================================================================== 22#===================================================================
21 23
22 24
23class Repository(object): 25class Repository(object):
24 26
25 def __init__ (self, repository, path): 27 def __init__ (self, repository, path):
26 self.repository = repository 28 self.repository = repository
27 self.path = path 29 self.path = path
28 30
29 31
30 def revision (self): 32 def revision (self):
31 raise NotImplementedError() 33 raise NotImplementedError()
32 34
33 35
34 def areTherePendingChanges (self): 36 def areTherePendingChanges (self):
35 raise NotImplementedError() 37 raise NotImplementedError()
36 38
37 39
38 def version (self): 40 def version (self):
39 result = self.revision() 41 result = self.revision()
40 if self.areTherePendingChanges(): 42 if self.areTherePendingChanges():
41 result = '>>> ' + result + ' <<<' 43 result = '>>> ' + result + ' <<<'
42 44
43 # print "VERSION: " + result 45 # print "VERSION: " + result
44 return result 46 return result
45 47
46 48
47#=================================================================== 49#===================================================================
48 50
49 51
50class GitRepository(Repository): 52class GitRepository(Repository):
51 53
52 def revision (self): 54 def revision (self):
53 return repository.refs['HEAD'] 55 return self.repository.head.commit.hexsha
54 56
55 57
56 def areTherePendingChanges (self): 58 def areTherePendingChanges (self):
57 return repository.is_dirty() 59 return self.repository.is_dirty()
58 60
59 61
60#=================================================================== 62#===================================================================
61 63
62 64
63class HgRepository(Repository): 65class HgRepository(Repository):
64 #http://mercurial.selenic.com/wiki/MercurialApi 66 #http://mercurial.selenic.com/wiki/MercurialApi
65 67
66 def revision (self): 68 def revision (self):
67 return 'hg:' + str(self.repository['tip']) 69 return 'hg:' + str(self.repository['tip'])
68 70
69 71
70 def areTherePendingChanges (self): 72 def areTherePendingChanges (self):
71 # TODO: FIXME: repository.status() does not report 'unknown(?)' files. :( 73 # TODO: FIXME: repository.status() does not report 'unknown(?)' files. :(
72 return not all(map(lambda fileList: len(fileList) == 0, self.repository.status())) 74 return not all(map(lambda fileList: len(fileList) == 0, self.repository.status()))
73 75
74 76
75#=================================================================== 77#===================================================================