Compare commits

...

5 Commits

Author SHA1 Message Date
Graham Eades ad13fffb07 Tidy up key test 2020-03-03 11:43:50 +00:00
Graham Eades 1f38736b37 Fixed print in repository check 2020-03-02 18:03:03 +00:00
Graham Eades 6f22b5eb6e Updated to python 3 compatible code 2020-03-02 18:01:27 +00:00
Graham Eades fcd6e4863a Updated print function in file 2020-03-02 17:42:47 +00:00
Graham Eades 81a8565710 Updated scripts for python3 2020-03-02 17:40:55 +00:00
7 changed files with 56 additions and 50 deletions

View File

@ -7,7 +7,7 @@ import hashlib
from functools import reduce
from operator import add
from itertools import izip
#from itertools import izip
import main
@ -63,7 +63,7 @@ class BackendBuilder(object):
# --------------------------------------------------------------------------
def writeToFolder (self, folder, filename, content):
file = open(os.path.join(folder, filename), 'w')
file = open(os.path.join(folder, filename), 'wb')
file.write(content.encode('utf-8'))
file.close()
@ -81,19 +81,19 @@ class BackendBuilder(object):
def formatMAC (self, value):
x = iter(value)
return ' '.join([reduce(add, tup) for tup in izip(x, x, x, x)])
return ' '.join([reduce(add, tup) for tup in zip(x, x, x, x)])
def logChecksums (self, content, message):
md5Digest = self.formatMAC(hashlib.md5(content.encode('utf-8')).hexdigest())
shaDigest = self.formatMAC(hashlib.sha1(content.encode('utf-8')).hexdigest())
sha256Digest = self.formatMAC(hashlib.sha256(content.encode('utf-8')).hexdigest())
print "-----"
print message + ": " + md5Digest + " (md5)"
print message + ": " + shaDigest + " (sha1)"
print message + ": " + sha256Digest + " (sha256)"
print "file size: " + "{:,}".format(len(content))
print "====="
print ( "-----" )
print ( message + ": " + md5Digest + " (md5)" )
print ( message + ": " + shaDigest + " (sha1)" )
print ( message + ": " + sha256Digest + " (sha256)" )
print ( "file size: " + "{:,}".format(len(content)) )
print ( "=====" )
def shouldCompileCode (self):
@ -101,7 +101,7 @@ class BackendBuilder(object):
def run (self):
print self.name() + " - RUN"
print ( self.name() + " - RUN" )
if self.shouldCompileCode():
self.compileCode()

View File

@ -4,7 +4,7 @@
"""`cssmin` - A Python port of the YUI CSS compressor."""
from StringIO import StringIO # The pure-Python StringIO supports unicode.
from io import StringIO # The pure-Python StringIO supports unicode.
import re

View File

@ -6,7 +6,7 @@ import cssmin
import jsmin
import codecs
import shutil
import StringIO
from io import StringIO
import urllib
import main
@ -53,7 +53,7 @@ class FrontendBuilder(object):
module = self.module
if (self.module != self.submodule):
module = module + "." + self.submodule
print "frontend [" + module + "]: " + message
print ( "frontend [" + module + "]: " + message )
def absolutePathForSources (self):
@ -117,7 +117,7 @@ class FrontendBuilder(object):
try:
fileHandler = codecs.open(self.absolutePathForSourceFile(basePath, file), 'r', 'utf-8')
except:
print "FILE: " + file
print ( "FILE: " + file )
result[file] = fileHandler.read()
fileHandler.close()
@ -146,7 +146,7 @@ class FrontendBuilder(object):
def template (self):
processedFile = 'html_template'
if not self.processedFiles.has_key(processedFile):
if processedFile not in self.processedFiles:
# self.processedFiles[processedFile] = self.loadFilesContent('html', ['index_template.html'])
self.processedFiles[processedFile] = self.loadFilesContent('html', [self.settings['html.template']])
@ -197,7 +197,7 @@ class FrontendBuilder(object):
# output rule if it contains any declarations
if properties:
print "%s{%s}" % ( ','.join( selectors ), ''.join(['%s:%s;' % (key, properties[key]) for key in porder])[:-1] )
print ( "%s{%s}" % ( ','.join( selectors ), ''.join(['%s:%s;' % (key, properties[key]) for key in porder])[:-1] ) )
return css
@ -218,8 +218,8 @@ class FrontendBuilder(object):
def compressJS_jsmin (self, js, description):
self.log("compressing " + description + " code")
original = StringIO.StringIO(js)
output = StringIO.StringIO()
original = StringIO(js)
output = StringIO()
jsMinifier = jsmin.JavascriptMinify()
jsMinifier.minify(original, output)
@ -287,7 +287,8 @@ class FrontendBuilder(object):
def bookmarklet (self):
cacheKey = 'bookmarklet'
if not self.processedFiles.has_key(cacheKey):
# if not self.processedFiles.has_key(cacheKey):
if cacheKey not in self.processedFiles:
result = 'bookmarklet="' + self.packBookmarklet(self.loadFilesContent('js', ['Bookmarklet.js']), "regular") + '";bookmarklet_ie="' + self.packBookmarklet(self.loadFilesContent('js', ['Bookmarklet_IE.js']), "IE") + '";'
self.processedFiles[cacheKey] = result
else:
@ -316,7 +317,8 @@ class FrontendBuilder(object):
def assembleCopyrightHeader (self):
processedFile = 'copyright'
if not self.processedFiles.has_key(processedFile):
# if not self.processedFiles.has_key(processedFile):
if processedFile not in self.processedFiles:
#self.log("assembling copyright header")
copyrightValues = self.settings['copyright.values']
license = self.loadFilesContent('../../properties', ['license.txt'])
@ -351,7 +353,8 @@ class FrontendBuilder(object):
def assembleVersion (self, pageTitle, copyright, css, js, jsLoadMode, version, versionType):
cacheKey = version + "-" + versionType
if not self.processedFiles.has_key(cacheKey):
# if not self.processedFiles.has_key(cacheKey):
if cacheKey not in self.processedFiles:
result = self.replaceTemplatePlaceholders(pageTitle, copyright, css, js, jsLoadMode, version, versionType)
self.processedFiles[cacheKey] = result
else:

View File

@ -30,7 +30,7 @@ class DeltaBuilder(FrontendBuilder):
content = content.replace('@request.path@', backendSettings['request.path'])
dst = self.absolutePathForTargetFile(targetFolder, '', resource['target'])
file = open(dst, 'w')
file = open(dst, 'wb')
file.write(content.encode('utf-8'))
file.close()

View File

@ -33,7 +33,7 @@ import os, os.path, shutil
# SOFTWARE.
# */
from StringIO import StringIO
from io import StringIO
def jsmin(js):
ins = StringIO(js)
@ -224,7 +224,7 @@ def compress(in_files, out_file, in_type='js', verbose=False, temp_file='.temp')
temp.write(data)
print ' + %s' % f
print ( ' + %s' % f )
temp.close()
out = open(out_file, 'w')
@ -237,10 +237,11 @@ def compress(in_files, out_file, in_type='js', verbose=False, temp_file='.temp')
org_size = os.path.getsize(temp_file)
new_size = os.path.getsize(out_file)
print '=> %s' % out_file
print 'Original: %.2f kB' % (org_size / 1024.0)
print 'Compressed: %.2f kB' % (new_size / 1024.0)
print 'Reduction: %.1f%%' % (float(org_size - new_size) / org_size * 100)
print ''
print ( '=> %s' % out_file )
print ( 'Original: %.2f kB' )% (org_size / 1024.0)
print ( 'Compressed: %.2f kB' )% (new_size / 1024.0)
# print ( 'Reduction: %.1f%%' % (f )loat(org_size - new_size) / org_size * 100)
print ( 'Reduction: %.1f%%' % (org_size - new_size) / org_size * 100)
print ( '' )
os.remove(temp_file)
os.remove(temp_file)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import sys
@ -89,10 +89,10 @@ def build (settings, repository):
if repository.areTherePendingChanges():
if 'install' in settings['versions']:
# print "\nWARNING: repository has pending changes\n"
# print ( "\nWARNING: repository has pending changes\n" )
raise Exception("repository has pending changes, can't 'install'")
else:
print "\nWARNING: repository has pending changes\n"
print ( "\nWARNING: repository has pending changes\n" )
for frontend in settings['frontends']:
normalizedFrontendName = frontend.replace(".", "_")
@ -120,17 +120,17 @@ def clean ():
def usage (message):
if message != None:
print "ERROR: " + message
print ( "ERROR: " + message )
print
print ()
# print "build clean"
# print "build clean install"
print "build install --ALL"
print "build install debug --ALL"
print "build install debug development --ALL"
# print "build clean install debug --ALL"
print "build install debug --backends php python --frontends beta gamma"
print "build install debug development --backends php python --frontends beta gamma gamma.mobile"
print ( "build install --ALL" )
print ( "build install debug --ALL" )
print ( "build install debug development --ALL" )
# print ( "build clean install debug --ALL" )
print ( "build install debug --backends php python --frontends beta gamma" )
print ( "build install debug development --backends php python --frontends beta gamma gamma.mobile" )
exit(1)
#--------------------------------------------------------------------
@ -181,11 +181,11 @@ def main ():
settings['backends'] = []
settings['backends'].append('checksum')
if (not settings.has_key('versions')):
if 'versions' not in settings:
usage("missing 'versions'")
if (not settings.has_key('frontends')):
if 'frontends' not in settings:
usage("missing 'frontends'")
if (not settings.has_key('backends')):
if 'backends' not in settings:
usage("missing 'backends'")
build(settings, currentRepository)

View File

@ -14,11 +14,13 @@ def repositoryWithPath (path):
from git import Repo
repo = Repo(path)
result = GitRepository(repo, path)
except ImportError, exception:
print "Failed to import git, please install http://gitorious.org/git-python"
print "Use sudo apt-get install python-git for Ubuntu/Debian"
print "Use sudo yum install GitPython for Fedora/RHEL/CentOS"
print "Or manually running the following command: easy_install gitpython"
except ImportError as exception:
import sys
print ( sys.version )
print ( "Failed to import git, please install http://gitorious.org/git-python" )
print ( "Use sudo apt-get install python-git for Ubuntu/Debian" )
print ( "Use sudo yum install GitPython for Fedora/RHEL/CentOS" )
print ( "Or manually running the following command: easy_install gitpython" )
except:
result = SnapshotRepository('', path)
@ -68,7 +70,7 @@ class GitRepository(Repository):
def areTherePendingChanges (self):
try:
return self.repository.is_dirty()
except TypeError, te:
except TypeError as te:
return self.repository.is_dirty