add python3 suppport based on 2to3 script

This commit is contained in:
Stefan Klug 2015-10-27 21:10:24 +01:00
parent caef0e85d0
commit 4f91a30fec
68 changed files with 597 additions and 576 deletions

View file

@ -73,10 +73,10 @@ class AskSap:
# Return info about a given function.
info = sap.getFunctionInfo(sapElement)
prefix = 'Function'
print('%s: %s' % (prefix, sapElement))
print(('%s: %s' % (prefix, sapElement)))
print(info)
sap.disconnect()
except SapError, se:
except SapError as se:
sys.stderr.write(str(se))
sys.stderr.write('\n')
sys.exit(ERROR_CODE)

View file

@ -4,7 +4,7 @@ from optparse import OptionParser
import ZODB.FileStorage
import ZODB.serialize
from DateTime import DateTime
from StringIO import StringIO
from io import StringIO
folderName = os.path.dirname(__file__)
# ------------------------------------------------------------------------------
@ -87,9 +87,9 @@ class ZodbBackuper:
w('Try to create backup folder for logs "%s"...' % \
self.logsBackupFolder)
os.mkdir(self.logsBackupFolder)
except IOError, ioe:
except IOError as ioe:
w(folderCreateError % str(ioe))
except OSError, oe:
except OSError as oe:
w(folderCreateError % str(oe))
if os.path.exists(self.logsBackupFolder):
# Ok, we can make the backup of the log files.
@ -175,7 +175,7 @@ class ZodbBackuper:
except smtplib.SMTPException, sme:
w('Error while contacting SMTP server %s (%s).' % \
(self.options.smtpServer, str(se)))
except socket.error, se:
except socket.error as se:
w('Could not connect to SMTP server %s (%s).' % \
(self.options.smtpServer, str(se)))
@ -191,12 +191,12 @@ class ZodbBackuper:
for fileName in os.listdir(self.tempFolder):
ext = os.path.splitext(fileName)[1]
if ext in self.toRemoveExts:
exec '%sCount += 1' % ext[1:]
exec('%sCount += 1' % ext[1:])
fullFileName = os.path.join(self.tempFolder, fileName)
#w('Removing "%s"...' % fullFileName)
try:
os.remove(fullFileName)
except OSError, oe:
except OSError as oe:
w('Could not remove "%s" (%s).' % (fullFileName, str(oe)))
w('%d .pdf, %d .doc, %d .rtf and %d .odt file(s) removed.' % \
(pdfCount, docCount, rtfCount, odtCount))
@ -268,7 +268,7 @@ class ZodbBackuper:
if self.emails:
self.sendEmails()
self.logFile.close()
print(self.logMem.getvalue())
print((self.logMem.getvalue()))
self.logMem.close()
# ------------------------------------------------------------------------------
@ -302,7 +302,7 @@ class ZodbBackupScript:
f.write('Hello.')
f.close()
os.remove(fileName)
except OSError, oe:
except OSError as oe:
raise BackupError('I do not have the right to write in ' \
'folder "%s".' % args[1])
# Check temp folder
@ -401,7 +401,7 @@ class ZodbBackupScript:
self.checkArgs(options, args)
backuper = ZodbBackuper(args[0], args[1], options)
backuper.run()
except BackupError, be:
except BackupError as be:
sys.stderr.write(str(be) + '\nRun the script without any ' \
'argument for getting help.\n')
sys.exit(ERROR_CODE)

View file

@ -21,7 +21,7 @@ class LdapTester:
def __init__(self):
# Get params from shell args.
if len(sys.argv) != 8:
print(LdapTester.__doc__)
print((LdapTester.__doc__))
sys.exit(0)
s = self
s.uri,s.login,s.password,s.base,s.attrs,s.filter,s.scope = sys.argv[1:]
@ -33,15 +33,15 @@ class LdapTester:
def test(self):
# Connect the the LDAP
print('Connecting to... %s' % self.uri)
print(('Connecting to... %s' % self.uri))
connector = LdapConnector(self.uri)
success, msg = connector.connect(self.login, self.password)
if not success: return
# Perform the query.
print ('Querying %s...' % self.base)
print(('Querying %s...' % self.base))
res = connector.search(self.base, self.scope, self.filter,
self.attributes)
print('Got %d results' % len(res))
print(('Got %d results' % len(res)))
# ------------------------------------------------------------------------------
if __name__ == '__main__': LdapTester().test()

View file

@ -110,12 +110,12 @@ class EggifyScript:
eggFullName = j(self.eggFolder, self.eggName)
if os.path.exists(eggFullName):
os.remove(eggFullName)
print('Existing "%s" was removed.' % eggFullName)
print(('Existing "%s" was removed.' % eggFullName))
# Create a temp folder where to store the egg
eggTempFolder = os.path.splitext(eggFullName)[0]
if os.path.exists(eggTempFolder):
FolderDeleter.delete(eggTempFolder)
print('Removed "%s" that was in my way.' % eggTempFolder)
print(('Removed "%s" that was in my way.' % eggTempFolder))
os.mkdir(eggTempFolder)
# Create the "Products" sub-folder if we must wrap the package in this
# namespace
@ -170,7 +170,7 @@ class EggifyScript:
try:
self.checkArgs(options, args)
self.eggify()
except EggifierError, ee:
except EggifierError as ee:
sys.stderr.write(str(ee) + '\nRun eggify.py -h for getting help.\n')
sys.exit(ERROR_CODE)

View file

@ -41,7 +41,7 @@ class GeneratorScript:
sys.exit(ERROR_CODE)
# Check existence of application
if not os.path.exists(args[0]):
print(APP_NOT_FOUND % args[0])
print((APP_NOT_FOUND % args[0]))
sys.exit(ERROR_CODE)
# Convert app path to an absolute path
args[0] = os.path.abspath(args[0])
@ -55,8 +55,8 @@ class GeneratorScript:
(options, args) = optParser.parse_args()
try:
self.manageArgs(optParser, options, args)
print('Appy version: %s' % appy.version.verbose)
print('Generating Zope product in %s/zope...' % args[0])
print(('Appy version: %s' % appy.version.verbose))
print(('Generating Zope product in %s/zope...' % args[0]))
ZopeGenerator(args[0], options).run()
# Give the user some statistics about its code
LinesCounter(args[0], excludes=['%szope' % os.sep]).run()
@ -71,7 +71,7 @@ class GeneratorScript:
f.close()
version = version[:version.find('build')-1]
Debianizer(app, appDir, appVersion=version).run()
except GeneratorError, ge:
except GeneratorError as ge:
sys.stderr.write(str(ge))
sys.stderr.write('\n')
optParser.print_help()

View file

@ -82,6 +82,6 @@ else:
targetObject = getattr(targetObject, elem)
# Execute the method on the target object
if args: args = args.split('*')
exec 'targetObject.%s(*args)' % toolMethod
exec('targetObject.%s(*args)' % toolMethod)
transaction.commit()
# ------------------------------------------------------------------------------

View file

@ -106,17 +106,17 @@ class ZopeInstanceCreator:
f = file('bin/zopectl', 'w')
f.write(zopeCtl % self.instancePath)
f.close()
os.chmod('bin/zopectl', 0744) # Make it executable by owner.
os.chmod('bin/zopectl', 0o744) # Make it executable by owner.
# Create bin/runzope
f = file('bin/runzope', 'w')
f.write(runZope % self.instancePath)
f.close()
os.chmod('bin/runzope', 0744) # Make it executable by owner.
os.chmod('bin/runzope', 0o744) # Make it executable by owner.
# Create bin/startoo
f = file('bin/startoo', 'w')
f.write(ooStart)
f.close()
os.chmod('bin/startoo', 0744) # Make it executable by owner.
os.chmod('bin/startoo', 0o744) # Make it executable by owner.
# Create etc/zope.conf
os.mkdir('etc')
f = file('etc/zope.conf', 'w')
@ -138,10 +138,10 @@ class ZopeInstanceCreator:
password = binascii.b2a_base64(sha('admin').digest())[:-1]
f.write('admin:{SHA}%s\n' % password)
f.close()
os.chmod('inituser', 0644)
os.chmod('inituser', 0o644)
# User "zope" must own this instance
os.system('chown -R zope %s' % self.instancePath)
print('Zope instance created in %s.' % self.instancePath)
print(('Zope instance created in %s.' % self.instancePath))
os.chdir(curdir)
# ------------------------------------------------------------------------------
@ -229,7 +229,7 @@ class NewScript:
j = os.path.join
# As eggs have been deleted, versions of components are lost. Reify
# them from p_versions.
dVersions = ['"%s":"%s"' % (n, v) for n, v in versions.iteritems()]
dVersions = ['"%s":"%s"' % (n, v) for n, v in versions.items()]
sVersions = 'appyVersions = {' + ','.join(dVersions) + '}'
codeFile = "%s/pkg_resources.py" % self.libFolder
f = file(codeFile)
@ -326,7 +326,7 @@ class NewScript:
action = 'Copying'
if linksForProducts:
action = 'Symlinking'
print('%s Plone stuff in the Zope instance...' % action)
print(('%s Plone stuff in the Zope instance...' % action))
if self.ploneVersion in ('plone25', 'plone30'):
self.installPlone25or30Stuff(linksForProducts)
elif self.ploneVersion in ('plone3x', 'plone4'):
@ -379,11 +379,11 @@ class NewScript:
try:
self.manageArgs(args)
if self.ploneVersion != 'zope':
print('Creating new %s instance...' % self.ploneVersion)
print(('Creating new %s instance...' % self.ploneVersion))
self.createInstance(linksForProducts)
else:
ZopeInstanceCreator(self.instancePath).run()
except NewError, ne:
except NewError as ne:
optParser.print_help()
sys.stderr.write(str(ne))
sys.stderr.write('\n')

View file

@ -52,7 +52,7 @@ class OdfGrep:
# Run "grep" in this folder
match = self.callGrep(tempFolder)
if match:
print('Found in %s' % fileName)
print(('Found in %s' % fileName))
FolderDeleter.delete(tempFolder)
def run(self):
@ -65,7 +65,7 @@ class OdfGrep:
if os.path.splitext(name)[1] in self.toUnzip:
self.grepFile(os.path.join(dir, name))
else:
print('%s does not exist.' % self.fileOrFolder)
print(('%s does not exist.' % self.fileOrFolder))
# ------------------------------------------------------------------------------
if __name__ == '__main__':

View file

@ -85,8 +85,8 @@ class FtpFolder:
def clean(self, site):
'''Cleans this folder'''
# First, clean subFolders if they exist
print('Cleaning %s %d subFolders' % \
(self.getFullName(), len(self.subFolders)))
print(('Cleaning %s %d subFolders' % \
(self.getFullName(), len(self.subFolders))))
for subFolder in self.subFolders:
subFolder.clean(site)
# Remove the subFolder
@ -95,7 +95,7 @@ class FtpFolder:
for f in self.files:
fileName = '%s/%s' % (self.getFullName(), f)
site.delete(fileName)
print('%s removed.' % fileName)
print(('%s removed.' % fileName))
# ------------------------------------------------------------------------------
class AppySite:
@ -148,11 +148,11 @@ class AppySite:
fileExt = os.path.splitext(fileName)[1]
if fileExt in self.textExtensions:
# Make a transfer in text mode
print('Transfer file %s (text mode)' % fileName)
print(('Transfer file %s (text mode)' % fileName))
self.site.storlines(cmd, localFile)
else:
# Make a transfer in binary mode
print('Transfer file %s (binary mode)' % fileName)
print(('Transfer file %s (binary mode)' % fileName))
self.site.storbinary(cmd, localFile)
def publish(self):
@ -257,7 +257,7 @@ class Publisher:
yesNo = '[Y/n]'
else:
yesNo = '[y/N]'
print(question + ' ' + yesNo + ' ')
print((question + ' ' + yesNo + ' '))
response = sys.stdin.readline().strip().lower()
res = False
if response in ('y', 'yes'):
@ -274,7 +274,7 @@ class Publisher:
def executeCommand(self, cmd):
'''Executes the system command p_cmd.'''
print('Executing %s...' % cmd)
print(('Executing %s...' % cmd))
os.system(cmd)
distExcluded = ('appy/doc', 'appy/temp', 'appy/versions', 'appy/gen/test')
@ -340,7 +340,7 @@ class Publisher:
newZipRelease, default='yes'):
print('Publication canceled.')
sys.exit(1)
print('Removing obsolete %s...' % newZipRelease)
print(('Removing obsolete %s...' % newZipRelease))
os.remove(newZipRelease)
zipFile = zipfile.ZipFile(newZipRelease, 'w', zipfile.ZIP_DEFLATED)
curdir = os.getcwd()
@ -474,7 +474,7 @@ class Publisher:
if minimalist:
FolderDeleter.delete('%s/pod/test' % genSrcFolder)
# Write the appy version into the code itself (in appy/version.py)'''
print('Publishing version %s...' % self.versionShort)
print(('Publishing version %s...' % self.versionShort))
# Dump version info in appy/version.py
f = file('%s/version.py' % genSrcFolder, 'w')
f.write('short = "%s"\n' % self.versionShort)
@ -495,7 +495,7 @@ class Publisher:
Cleaner().run(verbose=False)
# Perform a small analysis on the Appy code
LinesCounter(appy).run()
print('Generating site in %s...' % self.genFolder)
print(('Generating site in %s...' % self.genFolder))
minimalist = self.askQuestion('Minimalist (shipped without tests)?',
default='no')
self.prepareGenFolder(minimalist)

View file

@ -21,10 +21,10 @@ class ZodbRestorer:
datePart = '-D %s' % self.restoreDate
repozoCmd = '%s %s -Rv -r %s %s -o %s' % (self.python,
self.repozo, self.backupFolder, datePart, self.storageLocation)
print('Executing %s...' % repozoCmd)
print(('Executing %s...' % repozoCmd))
os.system(repozoCmd)
stopTime = time.time()
print('Done in %d minute(s).' % ((stopTime-startTime)/60))
print(('Done in %d minute(s).' % ((stopTime-startTime)/60)))
# ------------------------------------------------------------------------------
class ZodbRestoreScript:
@ -56,7 +56,7 @@ class ZodbRestoreScript:
f.write('Hello.')
f.close()
os.remove(args[0])
except OSError, oe:
except OSError as oe:
raise RestoreError('I do not have the right to write file ' \
'"%s".' % args[0])
@ -81,7 +81,7 @@ class ZodbRestoreScript:
self.checkArgs(options, args)
backuper = ZodbRestorer(args[0], args[1], options)
backuper.run()
except RestoreError, be:
except RestoreError as be:
sys.stderr.write(str(be))
sys.stderr.write('\n')
optParser.print_help()

View file

@ -8,29 +8,29 @@ class Zipper:
def __init__(self):
self.zipFileName = '%s/Desktop/appy.zip' % os.environ['HOME']
def createZipFile(self):
print('Creating %s...' % self.zipFileName)
print(('Creating %s...' % self.zipFileName))
zipFile = zipfile.ZipFile(self.zipFileName, 'w', zipfile.ZIP_DEFLATED)
for dir, dirnames, filenames in os.walk(appyPath):
for f in filenames:
fileName = os.path.join(dir, f)
arcName = fileName[fileName.find('appy/'):]
print('Adding %s' % fileName)
print(('Adding %s' % fileName))
zipFile.write(fileName, arcName)
zipFile.close()
def run(self):
# Where to put the zip file ?
print("Where do you want to put appy.zip ? [Default is %s] " % \
os.path.dirname(self.zipFileName))
print(("Where do you want to put appy.zip ? [Default is %s] " % \
os.path.dirname(self.zipFileName)))
response = sys.stdin.readline().strip()
if response:
if os.path.exists(response) and os.path.isdir(response):
self.zipFileName = '%s/appy.zip' % response
else:
print('%s is not a folder.' % response)
print(('%s is not a folder.' % response))
sys.exit(1)
if os.path.exists(self.zipFileName):
print('Removing existing %s...' % self.zipFileName)
print(('Removing existing %s...' % self.zipFileName))
os.remove(self.zipFileName)
Cleaner().run(verbose=False)
self.createZipFile()