Update files in windows directory so it compiles under python3 (print

statements and except and raise).
This commit is contained in:
kulath 2016-08-22 15:48:17 +01:00
parent 5e459e4541
commit 6204bbb8b1
5 changed files with 208 additions and 208 deletions

View File

@ -229,7 +229,7 @@ class buildbase(GObject.GObject):
# GetText Win 32 obtained from http://gnuwin32.sourceforge.net/packages/gettext.htm
# ....\gettext\bin\msgfmt.exe needs to be on the path
msgfmtCmd = 'msgfmt.exe'
#print 'msgfmtCmd = %s' % msgfmtCmd
#print('msgfmtCmd = %s' % msgfmtCmd)
elif sys.platform == 'linux2':
po_files = glob.glob(po_dir + "/*.po")
msgfmtCmd = "%s/bin/msgfmt" % sys.prefix
@ -304,7 +304,7 @@ class buildbase(GObject.GObject):
try:
log.info('removing directory: %s' % self.build_root )
shutil.rmtree(self.build_root)
except MY_EXCEPTION, e:
except MY_EXCEPTION as e:
log.error( e )
for file in ['gramps-%s.exe'%self.gramps_version ]: #, 'build.log']:
@ -313,7 +313,7 @@ class buildbase(GObject.GObject):
try:
log.info('removing file: %s' % fname )
os.remove(fname)
except MY_EXCEPTION, e:
except MY_EXCEPTION as e:
log.error( e )
def getNSISVersionNumber(self):
@ -339,7 +339,7 @@ class buildbase(GObject.GObject):
major = int(ver[0])
try:
minor = int(ver[1])
except ValueError, e:
except ValueError as e:
m = ver[1]
minor = int(m[:2])
return (major, minor)
@ -356,7 +356,7 @@ class buildbase(GObject.GObject):
makensisexe = path.join( nsispath, 'makensis.exe')
if path.isfile( makensisexe ):
MAKENSIS_exe = makensisexe
except WindowsError, e:
except WindowsError as e:
log.warning('NSIS not found, in registory')
log.warning('..Testing if makensis is on the path')
MAKENSIS_exe = 'makensis'
@ -394,7 +394,7 @@ class buildbase(GObject.GObject):
svnpath = winreg.QueryValue(key, '')
if path.isfile(svnpath):
SVN_exe = svnpath
except WindowsError, e:
except WindowsError as e:
log.warning('SVN not found, in registory')
log.warning('... Hoping svn is on the path')
SVN_exe = 'svn'
@ -429,9 +429,9 @@ class buildbase(GObject.GObject):
extractDir = os.path.join(self.out_dir, self.tarbase3 )
try:
os.rename( extractDir, self.build_root)
except WindowsError, e:
except WindowsError as e:
log.error("FAILED: \n\t extractDir=%s \n\t build_root=%s" % (extractDir, self.build_root))
raise WindowsError, e
raise WindowsError(e)
else:
log.error( "Sorry %s is not a tar file" % self.repository_path )
@ -449,7 +449,7 @@ class buildbase(GObject.GObject):
vers = self.getVersionFromLines(lines)
if 'TODO' in member: #need to get path this will extract too, grab it of one of the files
self.tarbase3, rest = member.split('/', 1)
print '==ExtractPath', self.tarbase3
print('==ExtractPath', self.tarbase3)
tar.close()
log.debug( 'Version (%s)' % (vers) )
return vers
@ -474,11 +474,11 @@ class buildbase(GObject.GObject):
self.copyPatchTreeToDest(srcname, dstname)
else:
log.error('UNDEFINED: %s -> %s' % (srcname, dstname))
except (IOError, os.error), why:
except (IOError, os.error) as why:
errors.append((srcname, dstname, str(why)))
# catch the Error from the recursive copytree so that we can
# continue with other files
except Error, err:
except Error as err:
errors.extend(err.args[0])
if errors:
raise Error(errors)
@ -568,7 +568,7 @@ Options:
for o, a in opts:
if o in ("-h", "--help"):
print usage
print(usage)
sys.exit(0)
if o in ("-o", "--out"):
@ -576,19 +576,19 @@ Options:
if o in ("--nsis_only"):
bBuildAll = False
if o in ('-t', "--tarball"):
print 'This is a tarball build'
print('This is a tarball build')
bTarball = True
if o in ("-m", "--msgdir"):
if os.path.isdir( a ):
msg_dir = a
else:
raise getopt.GetoptError, '\nERROR: msgfmt dir does not exist'
raise getopt.GetoptError('\nERROR: msgfmt dir does not exist')
if o in ("-p", "--patch"):
if os.path.isdir( a ):
patch_dir = a
bPatchBuild = True
else:
raise getopt.GetoptError, '\nERROR: Patch directory does not exist'
raise getopt.GetoptError('\nERROR: Patch directory does not exist')
if args: #got args use first one as base dir
repository_path = path.normpath(args[0])
@ -601,21 +601,21 @@ Options:
# raise getopt.GetoptError, '\nERROR: No base directory specified'
if len(args) > 1:
raise getopt.GetoptError, '\nERROR: Too many arguments'
raise getopt.GetoptError('\nERROR: Too many arguments')
except getopt.GetoptError, msg:
print msg
print '\n %s' % usage
except getopt.GetoptError as msg:
print(msg)
print('\n %s' % usage)
sys.exit(2)
if bTarball:
if not tarfile.is_tarfile(repository_path):
print "Tarball %s not a valid Tarball" % repository_path
print("Tarball %s not a valid Tarball" % repository_path)
sys.exit(1)
else:
if not os.path.isdir(repository_path):
print "WC root directory not found; %s " % repository_path
print("WC root directory not found; %s " % repository_path)
sys.exit(1)
if out_dir == None:
@ -630,7 +630,7 @@ Options:
for value in sys.argv[1:]:
s_args = s_args + ' %s'%value
print "======= build_GrampsWin32.py %s ========" % s_args
print("======= build_GrampsWin32.py %s ========" % s_args)
log.debug('Using %s to find python tools' % sys.prefix)
log.info('Platform: %s' % sys.platform)
#==========================

View File

@ -48,13 +48,13 @@ explain_safe = ''' **********************************************************
def RunExeCommand( app, args ):
cmd = app + ' ' + args
#print "Running: ", cmd
#print("Running: ", cmd)
stdin, stdout, stderr = os.popen3( cmd )
output = string.strip(stdout.read())
#print output
#print(output)
err = stderr.read()
if err:
print err
print(err)
return output
def CheckGtkInReg():
@ -69,7 +69,7 @@ def CheckGtkInReg():
log.info( ' Path : %s'% gtkPathInRegistry )
log.info( ' DllPath : %s'% dllPathInRegistry )
except WindowsError, e:
except WindowsError as e:
log.info( '\n GTK registry key not found in registry' )
log.info( ''' ********************************************************************
* This might not be an error, but means I don't know the directory to
@ -99,7 +99,7 @@ def FindLibsWithCtypes():
dllpathvalid = False
cpath = find_library(dll)
if cpath:
#print cpath
#print(cpath)
if cpath == os.path.join(dllPathInRegistry, dll) \
or cpath == os.path.join(dllPathShort, dll):
dllpathvalid = True
@ -180,7 +180,7 @@ def CheckWithDependencyWalker():
#delete the output file before running command
try:
os.remove(fout)
except WindowsError, e:
except WindowsError as e:
pass
log.info( ' Testing file %s' % ftest )
out = RunExeCommand(exe, '/c /f1 /ot "%s" "%s"' % (fout, ftest) )
@ -201,7 +201,7 @@ def CheckPathForOtherGtkInstalls():
other_paths = []
explain_level = 0
for i, d in enumerate(dirs):
#print '==%s==' %d
#print('==%s==' %d)
if d == gtkPathInRegistry or d == dllPathInRegistry\
or d == dllPathShort:
gtkpth_idx = i
@ -209,7 +209,7 @@ def CheckPathForOtherGtkInstalls():
for fname in testdlls:
f = os.path.join(d, fname)
if os.path.isfile( f ):
#print ' Found Erronous gtk DLL %s' % f
#print(' Found Erronous gtk DLL %s' % f)
if d not in other_paths:
other_paths.append(d)
if i < gtkpth_idx: # path appears BEFORE runtime path
@ -301,7 +301,7 @@ def Import_pyGtkIntoPython():
try:
import Gtk.glade
log.info( ' Glade tesing import of libglade .......\tOK\n' )
except ImportError, e:
except ImportError as e:
log.info( ' Glade importError: %s\n' % e )
if __name__ == '__main__':
@ -332,14 +332,14 @@ Options:
sys.exit(0)
if len(args) > 1:
raise getopt.GetoptError, '\nERROR: Too many arguments'
raise getopt.GetoptError('\nERROR: Too many arguments')
for arg in args:
if os.path.isdir(arg):
gtkPath = arg
else:
raise getopt.GetoptError, '\nERROR: Not a valid GTK path %s' % arg
raise getopt.GetoptError('\nERROR: Not a valid GTK path %s' % arg)
except getopt.GetoptError, msg:
except getopt.GetoptError as msg:
log.info( msg )
log.info( '\n %s' % usage )
sys.exit(2)

View File

@ -91,7 +91,7 @@ def GetGtkPath():
if not os.path.isfile(os.path.join(dllPathInRegistry, file)):
dllPathInRegistry = None # one of the files not present, so assume path is wrong
break
except WindowsError, e:
except WindowsError as e:
dllPathInRegistry = None
log.debug(' DLLPATH=%s'%dllPathInRegistry)
return dllPathInRegistry
@ -102,7 +102,7 @@ def GetGrampsPath():
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\GRAMPS') as key:
GrampsPathInRegistry = _winreg.QueryValue(key, '')
# check a few key files exist at this location
except WindowsError, e:
except WindowsError as e:
GrampsPathInRegistry = None
log.debug(' GRAMPSPATH=%s'%GrampsPathInRegistry)
@ -166,7 +166,7 @@ def writeLauncher(language, langcode, runtimepath, grampspath):
fout.writelines(lines)
fout.close()
for line in lines:
print line
print(line)
gtkpath = GetGtkPath()
grampspath = GetGrampsPath()
@ -174,10 +174,10 @@ lang = GetLanguageFromLocale()
if lang:
try:
lang_text = langLookup[lang.split('_', 1)[0]]
except KeyError, e:
except KeyError as e:
try:
lang_text = langLookup[lang]
except KeyError, e:
except KeyError as e:
lang_text = "Unknown"
writeLauncher(lang_text, "%s.utf-8"%lang, gtkpath, grampspath)

View File

@ -59,8 +59,8 @@ try:
except ImportError:
cairover_str = 'not found'
print 'python:%s;'%py_str
print 'gtk++:%s;'%gtkver_str
print 'pygtk:%s;'%pygtkver_str
print 'gobject:%s;'%gobjectver_str
print 'cairo:%s;'%cairover_str
print('python:%s;'%py_str)
print('gtk++:%s;'%gtkver_str)
print('pygtk:%s;'%pygtkver_str)
print('gobject:%s;'%gobjectver_str)
print('cairo:%s;'%cairover_str)

View File

@ -43,58 +43,58 @@ explain_safe = ''' **********************************************************
def RunExeCommand( app, args ):
cmd = app + ' ' + args
#print "Running: ", cmd
#print("Running: ", cmd)
stdin, stdout, stderr = os.popen3( cmd )
output = string.strip(stdout.read())
#print output
#print(output)
err = stderr.read()
if err:
print err
print(err)
return output
def CheckGtkInReg():
global gtkPathInRegistry, gtkVersionInRegistry, dllPathInRegistry, dllPathShort
print '\n==== Checking Registry for GTK ====='
print('\n==== Checking Registry for GTK =====')
try:
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\GTK\\2.0') as key:
gtkVersionInRegistry = _winreg.QueryValueEx(key, 'Version')[0]
gtkPathInRegistry = _winreg.QueryValueEx(key, 'Path')[0]
dllPathInRegistry = _winreg.QueryValueEx(key, 'DllPath')[0]
print ' Version :', gtkVersionInRegistry
print ' Path :', gtkPathInRegistry
print ' DllPath :', dllPathInRegistry
print(' Version :', gtkVersionInRegistry)
print(' Path :', gtkPathInRegistry)
print(' DllPath :', dllPathInRegistry)
except WindowsError, e:
print '\n GTK registry key not found in registry'
print ''' ********************************************************************
except WindowsError as e:
print('\n GTK registry key not found in registry')
print(''' ********************************************************************
* This might not be an error, but means I don't know the directory to
* your preferred GTK installation.
* - try passing in your GTK installation path.\n'''
print '-' * 60
print usage
* - try passing in your GTK installation path.\n''')
print('-' * 60)
print(usage)
sys.exit(0)
def WorkOutShortDosPath():
global dllPathShort
print '\n==== Use win32Api to query short path name for GTK ====='
print('\n==== Use win32Api to query short path name for GTK =====')
try:
import win32api
dllPathShort = win32api.GetShortPathName(dllPathInRegistry)
print ' DllPath8.3:', dllPathShort
print(' DllPath8.3:', dllPathShort)
except ImportError:
print ' **Cant query short path name, Win32Api not installed'
print ' install from http://python.net/crew/mhammond/win32/'
print ' if you want this function to work'
print(' **Cant query short path name, Win32Api not installed')
print(' install from http://python.net/crew/mhammond/win32/')
print(' if you want this function to work')
def FindLibsWithCtypes():
# use ctypes to check where windows finds it's DLL's
print '\n==== Use ctypes to find dlls ===='
print('\n==== Use ctypes to find dlls ====')
other_paths = []
for dll in testdlls:
dllpathvalid = False
cpath = find_library(dll)
if cpath:
#print cpath
#print(cpath)
if cpath == os.path.join(dllPathInRegistry, dll) \
or cpath == os.path.join(dllPathShort, dll):
dllpathvalid = True
@ -104,12 +104,12 @@ def FindLibsWithCtypes():
if pp not in other_paths:
other_paths.append(pp)
else:
print " ERROR:... ctypes failed to find %s" % dll
print(" ERROR:... ctypes failed to find %s" % dll)
if other_paths:
for pth in other_paths:
print " ERROR: ctypes loaded some gtk dll's from %s" % pth
print(" ERROR: ctypes loaded some gtk dll's from %s" % pth)
else:
print " OK ... ctypes found dll's in %s" % os.path.dirname(cpath)
print(" OK ... ctypes found dll's in %s" % os.path.dirname(cpath))
def ScanDependencyFileForErrors(fname):
fin = open(fname, 'r')
@ -148,20 +148,20 @@ def ScanDependencyFileForErrors(fname):
if OK == False:
if parts[0] == 'Error':
print " %s \tError dll not found" %( filename)
print(" %s \tError dll not found" %( filename))
else:
print " ERROR: %s \tVersion %s" %( filename, parts[16])
print(" ERROR: %s \tVersion %s" %( filename, parts[16]))
for rtdll in runtimedlls:
if runtimedlls[rtdll].startswith("Error"):
print '\n ERROR: MS runtime %s not found'%rtdll
print('\n ERROR: MS runtime %s not found'%rtdll)
else:
print '\n MS runtime Version %s loaded from' % runtimedlls[rtdll]
print " %s" %rtdll
print
print('\n MS runtime Version %s loaded from' % runtimedlls[rtdll])
print(" %s" %rtdll)
print()
def CheckWithDependencyWalker():
print '\n==== Checking with Dependency Walker ===='
print ' Please be patient takes some time'
print('\n==== Checking with Dependency Walker ====')
print(' Please be patient takes some time')
exe = os.path.join(scriptpath, 'depends.exe')
fout = os.path.join(scriptpath, 'depres.txt')
f2check = [
@ -175,28 +175,28 @@ def CheckWithDependencyWalker():
#delete the output file before running command
try:
os.remove(fout)
except WindowsError, e:
except WindowsError as e:
pass
print ' Testing file %s' % ftest
print(' Testing file %s' % ftest)
out = RunExeCommand(exe, '/c /f1 /ot "%s" "%s"' % (fout, ftest) )
if os.path.isfile(fout):
ScanDependencyFileForErrors(fout)
else:
print " ERROR: file %d does not exist", ftest
print(" ERROR: file %d does not exist", ftest)
else:
print ' Cannot check with dependency walker, not installed in local directory'
print ' get dependency walker from http://www.dependencywalker.com/'
print ' and unzip into this directory for it to work.'
print(' Cannot check with dependency walker, not installed in local directory')
print(' get dependency walker from http://www.dependencywalker.com/')
print(' and unzip into this directory for it to work.')
def CheckPathForOtherGtkInstalls():
print '\n====Checking environment path for other gtk installations===='
print('\n====Checking environment path for other gtk installations====')
ePath = os.environ['path']
dirs = ePath.split(';')
gtkpth_idx = 9999
other_paths = []
explain_level = 0
for i, d in enumerate(dirs):
#print '==%s==' %d
#print('==%s==' %d)
if d == gtkPathInRegistry or d == dllPathInRegistry\
or d == dllPathShort:
gtkpth_idx = i
@ -204,25 +204,25 @@ def CheckPathForOtherGtkInstalls():
for fname in testdlls:
f = os.path.join(d, fname)
if os.path.isfile( f ):
#print ' Found Erronous gtk DLL %s' % f
#print(' Found Erronous gtk DLL %s' % f)
if d not in other_paths:
other_paths.append(d)
if i < gtkpth_idx: # path appears BEFORE runtime path
print ' ERROR: %s should not appear before runtime path' % d
print(' ERROR: %s should not appear before runtime path' % d)
explain_level = 2
else:
print ' FOUND: %s, Probably OK as appears AFTER runtime path' % d
print(' FOUND: %s, Probably OK as appears AFTER runtime path' % d)
if explain_level <= 1:
explain_level = 1
if gtkpth_idx == 9999:
print '\n ERROR: Runtime directory not on enviroment path'
print " ** Runtime needs to be on path to load DLL's from\n"
print('\n ERROR: Runtime directory not on enviroment path')
print(" ** Runtime needs to be on path to load DLL's from\n")
if explain_level == 2:
print explain_exposed
print(explain_exposed)
elif explain_level == 1:
print explain_safe
print(explain_safe)
if len(other_paths) == 0:
print ' No other gtk installatons found\n'
print(' No other gtk installatons found\n')
# ==== report what python thinks it's using =====
MIN_PYTHON_VER = (2,5,1)
@ -241,23 +241,23 @@ MIN_CAIRO_VER = (1,2,6)
UNTESTED_CAIRO_VER = (1,4,13)
def PrintFailedImport(appl, minVersion, result):
print appl,
print 'version %d.%d.%d or above.....\t' % minVersion ,
print result
print(appl,)
print('version %d.%d.%d or above.....\t' % minVersion ,)
print(result)
def PrintVersionResult(appl, minVersion, actualVersion, untestedVersion):
print appl,
print 'version %d.%d.%d or above.....\t' % minVersion ,
print 'found %d.%d.%d' % actualVersion ,
print(appl,)
print('version %d.%d.%d or above.....\t' % minVersion ,)
print('found %d.%d.%d' % actualVersion ,)
if minVersion <= actualVersion < untestedVersion:
print '...OK'
print('...OK')
elif actualVersion >= untestedVersion:
print '...UNTESTED VERSION'
print('...UNTESTED VERSION')
else:
print '...FAILED'
print('...FAILED')
def Import_pyGtkIntoPython():
print '\n==== Test import into python ===='
print('\n==== Test import into python ====')
#py_str = 'found %d.%d.%d' % sys.version_info[:3]
PrintVersionResult(' Python ', MIN_PYTHON_VER, sys.version_info[:3], UNTESTED_PYTHON_VER)
@ -293,13 +293,13 @@ def Import_pyGtkIntoPython():
PrintFailedImport(' cairo ', MIN_CAIRO_VER, NOT_FOUND_STR)
#test for glade
print '\n==== See if libglade installed ===='
print('\n==== See if libglade installed ====')
try:
import Gtk.glade
print ' Glade tesing import of libglade .......\tOK\n'
except ImportError, e:
print ' Glade importError: %s\n' % e
print(' Glade tesing import of libglade .......\tOK\n')
except ImportError as e:
print(' Glade importError: %s\n' % e)
if __name__ == '__main__':
usage = '''Check for common problems in GTK/pyGTK installation.
@ -325,38 +325,38 @@ Options:
for o, a in opts:
if o in ("-h", "--help"):
print usage
print(usage)
sys.exit(0)
if len(args) > 1:
raise getopt.GetoptError, '\nERROR: Too many arguments'
raise getopt.GetoptError('\nERROR: Too many arguments')
for arg in args:
if os.path.isdir(arg):
gtkPath = arg
else:
raise getopt.GetoptError, '\nERROR: Not a valid GTK path %s' % arg
raise getopt.GetoptError('\nERROR: Not a valid GTK path %s' % arg)
except getopt.GetoptError, msg:
print msg
print '\n %s' % usage
except getopt.GetoptError as msg:
print(msg)
print('\n %s' % usage)
sys.exit(2)
import platform
winver = platform.win32_ver()
if len(winver) == 4:
print '''\n==== platform.win32_ver() reports ====
print('''\n==== platform.win32_ver() reports ====
Operating System: %s
Version : %s
Service Pack : %s
OS type : %s''' % winver
OS type : %s''' % winver)
else:
print winver
print(winver)
if gtkPath:
gtkPathInRegistry = gtkPath
dllPathInRegistry = os.path.join(gtkPath, 'bin')
print ' Using %s as GTK install path' % gtkPathInRegistry
print ' Using %s as GTK dll path' % dllPathInRegistry
print(' Using %s as GTK install path' % gtkPathInRegistry)
print(' Using %s as GTK dll path' % dllPathInRegistry)
else:
CheckGtkInReg()