1
0
mirror of http://git.whoc.org.uk/git/password-manager.git synced 2024-11-14 18:09:03 +01:00

Updated to python 3 compatible code

This commit is contained in:
Graham Eades 2020-03-02 18:01:27 +00:00
parent fcd6e4863a
commit 6f22b5eb6e
5 changed files with 31 additions and 27 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
@ -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']])
@ -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 'bookmarklet' 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 'copyright' 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)