Updated 'print' statements throughout Appy code, in order to be Python3x as well as Python2x-compliant.

This commit is contained in:
Gaetan Delannay 2013-05-30 00:46:11 +02:00
parent e8c63f225f
commit 0c50fe188a
24 changed files with 92 additions and 92 deletions

View file

@ -41,7 +41,7 @@ class AskSap:
def manageArgs(self, parser, options, args):
# Check number of args
if len(args) != 5:
print WRONG_NG_OF_ARGS
print(WRONG_NG_OF_ARGS)
parser.print_help()
sys.exit(ERROR_CODE)
@ -59,10 +59,10 @@ class AskSap:
if not password:
password = getpass.getpass('Password for the SAP user: ')
connectionParams = args[:4] + [password]
print 'Connecting to SAP...'
print('Connecting to SAP...')
sap = Sap(*connectionParams)
sap.connect()
print 'Connected.'
print('Connected.')
sapElement = args[4]
if options.isGroup:
# Returns info about the functions available in this group of
@ -73,8 +73,8 @@ class AskSap:
# Return info about a given function.
info = sap.getFunctionInfo(sapElement)
prefix = 'Function'
print '%s: %s' % (prefix, sapElement)
print info
print('%s: %s' % (prefix, sapElement))
print(info)
sap.disconnect()
except SapError, se:
sys.stderr.write(str(se))

View file

@ -217,7 +217,7 @@ class ZodbBackuper:
if self.emails:
self.sendEmails()
self.logFile.close()
print self.logMem.getvalue()
print(self.logMem.getvalue())
self.logMem.close()
# ------------------------------------------------------------------------------

View file

@ -16,7 +16,7 @@ class LdapTester:
def __init__(self):
# Get params from shell args.
if len(sys.argv) != 7:
print LdapTester.__doc__
print(LdapTester.__doc__)
sys.exit(0)
s = self
s.uri, s.login, s.password, s.base, s.attrs, s.filter = sys.argv[1:]
@ -28,25 +28,25 @@ class LdapTester:
def test(self):
# Connect the the LDAP
print 'Creating server object for server %s...' % self.uri
print('Creating server object for server %s...' % self.uri)
server = ldap.initialize(self.uri)
print 'Done. Login with %s...' % self.login
print('Done. Login with %s...' % self.login)
server.simple_bind(self.login, self.password)
if self.ssl:
server.start_tls_s()
try:
for i in range(self.tentatives):
try:
print 'Done. Performing a simple query on %s...' % self.base
print('Done. Performing a simple query on %s...'% self.base)
res = server.search_st(
self.base, ldap.SCOPE_ONELEVEL, filterstr=self.filter,
attrlist=self.attrs, timeout=5)
print 'Got %d entries' % len(res)
print('Got %d entries' % len(res))
break
except ldap.TIMEOUT:
print 'Got timeout.'
print('Got timeout.')
except ldap.LDAPError, le:
print le.__class__.__name__, le
print('%s %s' % (le.__class__.__name__, str(le)))
# ------------------------------------------------------------------------------
if __name__ == '__main__':

View file

@ -20,21 +20,21 @@ class LoChecker:
# Call LO in server mode to convert self.odtFile to PDF
converter = os.path.join(self.appyFolder, 'pod', 'converter.py')
cmd = 'python %s %s pdf -p %d' % (converter, self.odtFile, self.port)
print cmd
print(cmd)
os.system(cmd)
# Check if the PDF was generated
pdfFile = '%s.pdf' % os.path.splitext(self.odtFile)[0]
if not os.path.exists(pdfFile):
print 'PDF was not generated.'
print('PDF was not generated.')
else:
os.remove(pdfFile)
print 'Check successfull.'
print('Check successfull.')
# ------------------------------------------------------------------------------
if __name__ == '__main__':
nbOfArgs = len(sys.argv)
if nbOfArgs not in (1, 2):
print usage
print(usage)
sys.exit()
# Get the nb of args
port = (nbOfArgs == 2) and int(sys.argv[1]) or 2002

View file

@ -32,5 +32,4 @@ if not os.path.exists(scriptName):
f.close()
os.system('chmod -R 755 %s' % repoFolder)
os.chdir(curdir)
print 'Repository created.'
print('Repository created.')

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

View file

@ -53,12 +53,12 @@ class GeneratorScript:
def manageArgs(self, parser, options, args):
# Check number of args
if len(args) != 1:
print WRONG_NG_OF_ARGS
print(WRONG_NG_OF_ARGS)
parser.print_help()
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])
@ -76,8 +76,8 @@ class GeneratorScript:
(options, args) = optParser.parse_args()
try:
self.manageArgs(optParser, options, args)
print 'Appy version:', 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()

View file

@ -31,16 +31,16 @@ import sys, transaction
# Check that job.py is called with the right parameters.
if len(sys.argv) != 2:
print 'job.py was called with wrong args.'
print __doc__
print('job.py was called with wrong args.')
print(__doc__)
else:
commands = sys.argv[1].split(';')
# Check that every command has the right number of sub-elelements.
for command in commands:
parts = command.split(':')
if len(parts) not in (4,5):
print 'job.py was called with wrong args.'
print __doc__
print('job.py was called with wrong args.')
print(__doc__)
for command in commands:
parts = command.split(':')

View file

@ -141,7 +141,7 @@ class ZopeInstanceCreator:
os.chmod('inituser', 0644)
# 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)
# ------------------------------------------------------------------------------
@ -320,13 +320,13 @@ class NewScript:
# For Plone4, we will call it later.
cmd = '%s %s -d %s' % (pythonPath, makeInstancePath, self.instancePath)
if self.ploneVersion != 'plone4':
print cmd
print(cmd)
os.system(cmd)
# Now, make the instance Plone-ready
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'):
@ -338,7 +338,7 @@ class NewScript:
os.environ['PYTHONPATH'] = '%s:%s' % \
(j(self.instancePath,'Products'),
j(self.instancePath, 'lib/python'))
print cmd
print(cmd)
os.system(cmd)
self.patchPlone4(versions)
# Remove .bat files under Linux
@ -379,13 +379,12 @@ 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:
optParser.print_help()
print
sys.stderr.write(str(ne))
sys.stderr.write('\n')
sys.exit(ERROR_CODE)

View file

@ -52,7 +52,7 @@ class OdfGrep:
# Run "grep" in this folder
match = self.callGrep(tempFolder)
if match:
print 'Found in', fileName
print('Found in %s' % fileName)
FolderDeleter.delete(tempFolder)
def run(self):
@ -65,12 +65,12 @@ 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__':
if len(sys.argv) != 3:
print usage
print(usage)
sys.exit()
OdfGrep(sys.argv[1], sys.argv[2]).run()
# ------------------------------------------------------------------------------

View file

@ -28,9 +28,9 @@ recursive-include appy/pod *
recursive-include appy/shared *
'''
def askLogin():
print 'Login: ',
print('Login:')
login = sys.stdin.readline().strip()
print 'Password: ',
print('Password:')
passwd = sys.stdin.readline().strip()
return (login, passwd)
@ -84,7 +84,8 @@ class FtpFolder:
def clean(self, site):
'''Cleans this folder'''
# First, clean subFolders if they exist
print 'Cleaning', self.getFullName(), len(self.subFolders), 'subFolders'
print('Cleaning %s %d subFolders' % \
(self.getFullName(), len(self.subFolders)))
for subFolder in self.subFolders:
subFolder.clean(site)
# Remove the subFolder
@ -93,7 +94,7 @@ class FtpFolder:
for f in self.files:
fileName = '%s/%s' % (self.getFullName(), f)
site.delete(fileName)
print fileName, 'removed.'
print('%s removed.' % fileName)
# ------------------------------------------------------------------------------
class AppySite:
@ -146,17 +147,17 @@ 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):
# Delete the existing content of the distant site
self.createFolderProxies()
print 'Removing existing data on site...'
print('Removing existing data on site...')
self.rootFolder.clean(self.site)
curDir = os.getcwd()
os.chdir('%s/temp' % appyPath)
@ -255,7 +256,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'):
@ -272,7 +273,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')
@ -336,9 +337,9 @@ class Publisher:
if os.path.exists(newZipRelease):
if not self.askQuestion('"%s" already exists. Replace it?' % \
newZipRelease, default='yes'):
print 'Publication canceled.'
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()
@ -472,7 +473,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)
@ -493,7 +494,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 minutes.' % ((stopTime-startTime)/60)
print('Done in %d minute(s).' % ((stopTime-startTime)/60))
# ------------------------------------------------------------------------------
class ZodbRestoreScript:

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()

View file

@ -9,7 +9,7 @@ class ZopeRunner:
def run(self):
# Check that an arg has been given (start, stop, fg, run)
if not sys.argv[3].strip():
print 'Argument required.'
print('Argument required.')
sys.exit(-1)
# Identify the name of the application for which Zope must run.
app = os.path.splitext(os.path.basename(sys.argv[2]))[0].lower()