Skip to content

Commit 3e63caf

Browse files
Daniel NunesInfernio
authored andcommitted
Prepare print functions for py3
Changed them everywhere except in the records. One does not simply modify the records.
1 parent f6f7ce4 commit 3e63caf

17 files changed

Lines changed: 108 additions & 98 deletions

Mopy/bash/bash.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
loop."""
2828

2929
# Imports ---------------------------------------------------------------------
30+
from __future__ import print_function
3031
import atexit
3132
import codecs
3233
import lz4
@@ -149,10 +150,10 @@ def exit_cleanup():
149150
subprocess.Popen(cmd_line, # a list, no need to escape spaces
150151
close_fds=True)
151152
except Exception as error:
152-
print error
153-
print u'Error Attempting to Restart Wrye Bash!'
154-
print u'cmd line: %s' % (cmd_line, )
155-
print
153+
print(error)
154+
print(u'Error Attempting to Restart Wrye Bash!')
155+
print(u'cmd line: %s' % (cmd_line, ))
156+
print()
156157
raise
157158

158159
def dump_environment():
@@ -244,12 +245,12 @@ def _main(opts, wx_locale):
244245
if opts.genHtml is not None:
245246
msg1 = _(u"generating HTML file from: '%s'") % opts.genHtml
246247
msg2 = _(u'done')
247-
try: print msg1
248-
except UnicodeError: print msg1.encode(bolt.Path.sys_fs_enc)
248+
try: print(msg1)
249+
except UnicodeError: print(msg1.encode(bolt.Path.sys_fs_enc))
249250
from . import belt # this imports bosh which imports wx (DUH)
250251
bolt.WryeText.genHtml(opts.genHtml)
251-
try: print msg2
252-
except UnicodeError: print msg2.encode(bolt.Path.sys_fs_enc)
252+
try: print(msg2)
253+
except UnicodeError: print(msg2.encode(bolt.Path.sys_fs_enc))
253254
return
254255

255256
# We need the Mopy dirs to initialize restore settings instance
@@ -466,13 +467,13 @@ def __init__(self, msg):
466467
_tkinter_error_dial(msg, but_kwargs)
467468

468469
except Exception as e:
469-
print u'Wrye Bash encountered an error but could not display it.'
470-
print u'The following is the error that occurred when displaying the '\
471-
u'first error:'
470+
print(u'Wrye Bash encountered an error but could not display it.')
471+
print(u'The following is the error that occurred when displaying the '\
472+
u'first error:')
472473
try:
473-
print traceback.format_exc(e)
474+
print(traceback.format_exc(e))
474475
except Exception:
475-
print u' An error occurred while displaying the second error.'
476+
print(u' An error occurred while displaying the second error.')
476477

477478
def _tkinter_error_dial(msg, but_kwargs):
478479
import Tkinter as tkinter # PY3

Mopy/bash/basher/app_buttons.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# https://github.com/wrye-bash
2222
#
2323
# =============================================================================
24-
from __future__ import division
24+
from __future__ import division, print_function
2525
import subprocess
2626
import webbrowser
2727
from . import BashStatusBar, BashFrame
@@ -710,15 +710,15 @@ def _update_pkl(fileName=None):
710710
maxId = 0
711711
maxId = max(maxId, 0xf12345)
712712
maxOld = maxId
713-
print 'maxId', hex(maxId)
713+
print('maxId', hex(maxId))
714714
#--Eid list? - if the GMST has a 00000000 eid when looking at it in
715715
# the CS with nothing but oblivion.esm loaded you need to add the
716716
# gmst to this list, rebuild the pickle and overwrite the old one.
717717
for eid in bush.game.gmstEids:
718718
if eid not in fids:
719719
maxId += 1
720720
fids[eid] = maxId
721-
print '%08X %08X %s' % (0, maxId, eid)
721+
print('%08X %08X %s' % (0, maxId, eid))
722722
#--Source file
723723
if fileName:
724724
sorter = lambda a: a.eid
@@ -727,19 +727,19 @@ def _update_pkl(fileName=None):
727727
modFile = parsers.ModFile(modInfo, loadFactory)
728728
modFile.load(True)
729729
for gmst in sorted(modFile.GMST.records, key=sorter):
730-
print gmst.eid, gmst.value
730+
print(gmst.eid, gmst.value)
731731
if gmst.eid not in fids:
732732
maxId += 1
733733
fids[gmst.eid] = maxId
734-
print '%08X %08X %s' % (gmst.fid, maxId, gmst.eid)
734+
print('%08X %08X %s' % (gmst.fid, maxId, gmst.eid))
735735
#--Changes?
736736
if maxId > maxOld:
737737
outData = {'GMST': fids}
738738
pickle.dump(outData, GPath(bush.game.pklfile).open('w'))
739-
print _(u"%d new gmst ids written to " + bush.game.pklfile) % (
740-
(maxId - maxOld),)
739+
print(_(u"%d new gmst ids written to " + bush.game.pklfile) % (
740+
(maxId - maxOld),))
741741
else:
742-
print _(u'No changes necessary. PKL data unchanged.')
742+
print(_(u'No changes necessary. PKL data unchanged.'))
743743

744744
#------------------------------------------------------------------------------
745745
class App_ModChecker(StatusBar_Button):

Mopy/bash/basher/mod_links.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"""Menu items for the _item_ menu of the mods tab - their window attribute
2626
points to BashFrame.modList singleton."""
2727

28+
from __future__ import print_function
2829
import StringIO
2930
import collections
3031
import copy
@@ -80,9 +81,9 @@ class Mod_FullLoad(OneItemLink):
8081
def Execute(self):
8182
with balt.Progress(_(u'Loading:') + u'\n%s'
8283
% self._selected_item.stail) as progress:
83-
print bosh.MreRecord.type_class
84+
print(bosh.MreRecord.type_class)
8485
readClasses = bosh.MreRecord.type_class
85-
print readClasses.values()
86+
print(readClasses.values())
8687
loadFactory = parsers.LoadFactory(False, *readClasses.values())
8788
modFile = parsers.ModFile(self._selected_info, loadFactory)
8889
try:
@@ -2494,7 +2495,7 @@ def _log(self, changed, fileName):
24942495
try:
24952496
buff.write(format_ % (eid, full, newFull))
24962497
except:
2497-
print u'unicode error:', (format_, eid, full, newFull)
2498+
print(u'unicode error:', (format_, eid, full, newFull))
24982499
self._showLog(buff.getvalue(), title=_(u'Objects Renamed'))
24992500

25002501
# CBash only Import/Export ----------------------------------------------------

Mopy/bash/basher/settings_links.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#
2323
# =============================================================================
2424

25+
from __future__ import print_function
2526
import sys
2627

2728
from . import BashFrame, BashStatusBar
@@ -214,7 +215,7 @@ def Execute(self):
214215
ver = line.split(u':',1)[1]
215216
ver = eval(ver)
216217
current[dll].append(ver)
217-
print dll,':',ver
218+
print(dll,':',ver)
218219
if not replace:
219220
bass.settings['bash.installers.goodDlls'].update(Dlls['goodDlls'])
220221
bass.settings['bash.installers.badDlls'].update(Dlls['badDlls'])

Mopy/bash/bolt.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
# Imports ---------------------------------------------------------------------
2626
#--Standard
27-
from __future__ import division
27+
from __future__ import division, print_function
2828
import StringIO
2929
import cPickle as pickle # PY3
3030
import chardet
@@ -591,20 +591,20 @@ def tempDir(prefix=u'WryeBash_'):
591591
except UnicodeDecodeError:
592592
try:
593593
traceback.print_exc()
594-
print 'Trying to pass temp dir in...'
594+
print('Trying to pass temp dir in...')
595595
tempdir = unicode(tempfile.gettempdir(), Path.sys_fs_enc)
596596
return GPath(tempfile.mkdtemp(prefix=prefix, dir=tempdir))
597597
except UnicodeDecodeError:
598598
try:
599599
traceback.print_exc()
600-
print 'Trying to encode temp dir prefix...'
600+
print('Trying to encode temp dir prefix...')
601601
return GPath(tempfile.mkdtemp(
602602
prefix=prefix.encode(Path.sys_fs_enc)).decode(
603603
Path.sys_fs_enc))
604604
except:
605605
traceback.print_exc()
606-
print 'Failed to create tmp dir, Bash will not function ' \
607-
'correctly.'
606+
print('Failed to create tmp dir, Bash will not function ' \
607+
'correctly.')
608608

609609
@staticmethod
610610
def baseTempDir():
@@ -1287,8 +1287,8 @@ def main(self):
12871287
func = self.funcs.get(key)
12881288
if not func:
12891289
msg = _(u"Unknown function/object: %s") % key
1290-
try: print msg
1291-
except UnicodeError: print msg.encode('mbcs')
1290+
try: print(msg)
1291+
except UnicodeError: print(msg.encode('mbcs'))
12921292
return
12931293
for attr in attrs:
12941294
func = getattr(func,attr)
@@ -1740,10 +1740,10 @@ def deprint(*args,**keyargs):
17401740
o.close()
17411741
try:
17421742
# Should work if stdout/stderr is going to wxPython output
1743-
print msg
1743+
print(msg)
17441744
except UnicodeError:
17451745
# Nope, it's going somewhere else
1746-
print msg.encode(Path.sys_fs_enc)
1746+
print(msg.encode(Path.sys_fs_enc))
17471747

17481748
def getMatch(reMatch,group=0):
17491749
"""Returns the match or an empty string."""

Mopy/bash/bosh/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
# Imports ---------------------------------------------------------------------
3030
#--Python
31+
from __future__ import print_function
3132
import cPickle as pickle # PY3
3233
import collections
3334
import errno
@@ -786,8 +787,8 @@ def isMissingStrings(self, __debug=0):
786787
if bsa_info.has_assets({assetPath}):
787788
break # found
788789
except (BSAError, OverflowError):
789-
print u'Failed to parse %s:\n%s' % (
790-
bsa_info.name, traceback.format_exc())
790+
print(u'Failed to parse %s:\n%s' % (
791+
bsa_info.name, traceback.format_exc()))
791792
continue
792793
if __debug == 2:
793794
deprint(u'Asset %s not in %s' % (assetPath, bsa_info.name))

Mopy/bash/bosh/_saves.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
Oblivion only . We need this split into cosaves and proper saves module and
2626
coded for rest of the games."""
2727
# TODO: Oblivion only - we need to support rest of games - help needed
28-
from __future__ import division
28+
from __future__ import division, print_function
2929
from collections import Counter
3030
from itertools import starmap, repeat
3131
from operator import attrgetter
@@ -562,10 +562,10 @@ def getMaster(modIndex):
562562
#--Unknown type?
563563
if doUnknownTypes and type not in knownTypes:
564564
if mod < 255:
565-
print type,hex(fid),getMaster(mod)
565+
print(type,hex(fid),getMaster(mod))
566566
knownTypes.add(type)
567567
elif fid in id_created:
568-
print type,hex(fid),id_created[fid].recType
568+
print(type,hex(fid),id_created[fid].recType)
569569
knownTypes.add(type)
570570
#--Obj ref parents
571571
if type == 49 and mod == 255 and (rec_flgs & 2):

Mopy/bash/bosh/bain.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# =============================================================================
2424
"""BAIN backbone classes."""
2525

26+
from __future__ import print_function
2627
import collections
2728
import copy
2829
import errno
@@ -300,7 +301,7 @@ def __setstate__(self,values):
300301
try:
301302
self.__setstate(values)
302303
except Exception as e:
303-
print ('Failed loading %s' % values[0]) + ' due to %s' % e
304+
print(('Failed loading %s' % values[0]) + ' due to %s' % e)
304305
deprint('Failed loading %s' % values[0], traceback=True)
305306
# init to default values and let it be picked for refresh in
306307
# InstallersData#scan_installers_dir

Mopy/bash/brec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
"""This module contains all of the basic types used to read ESP/ESM mod files.
2626
"""
27-
from __future__ import division
27+
from __future__ import division, print_function
2828
import cPickle as pickle # PY3
2929
import copy
3030
import os

Mopy/bash/cint.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#
3838
####### END LICENSE BLOCK ######
3939

40-
from __future__ import division
40+
from __future__ import division, print_function
4141
from ctypes import byref, cast, c_bool, c_byte, c_char, c_char_p, c_float, \
4242
CFUNCTYPE, c_long, c_short, c_ubyte, c_uint32, c_ushort, c_ulong, CDLL, \
4343
POINTER, string_at, Structure, c_int, c_void_p
@@ -74,7 +74,7 @@ class Path(object):
7474
def GPath(obj):
7575
return obj
7676
def deprint(obj):
77-
print obj
77+
print(obj)
7878
def _(obj):
7979
return obj
8080

@@ -171,7 +171,7 @@ def PositiveIsErrorCheck(result, function, cArguments, *args):
171171

172172
if _CBash:
173173
def LoggingCB(logString):
174-
print logString,
174+
print(logString, end=' ')
175175
return 0
176176

177177
def RaiseCB(raisedString):
@@ -191,7 +191,7 @@ def RaiseCB(raisedString):
191191
#CBash. Dunno.
192192

193193
#This particular callback may disappear, or be morphed into something else
194-
print "CBash encountered an error", raisedString, "Check the log."
194+
print("CBash encountered an error", raisedString, "Check the log.")
195195
## raise CBashError("Check the log.")
196196
return
197197

@@ -1326,7 +1326,7 @@ def fflags(y):
13261326
for x in xrange(32):
13271327
z = 1 << x
13281328
if y & z == z:
1329-
print hex(z)
1329+
print(hex(z))
13301330
global _dump_RecIndent
13311331
global _dump_LastIndent
13321332
if hasattr(record, 'copyattrs'):
@@ -1341,20 +1341,20 @@ def fflags(y):
13411341
attr = attr[:-5]
13421342
wasList = True
13431343
rec = getattr(record, attr)
1344-
if _dump_RecIndent: print " " * (_dump_RecIndent - 1),
1344+
if _dump_RecIndent: print(" " * (_dump_RecIndent - 1), end=' ')
13451345
if wasList:
1346-
print attr
1346+
print(attr)
13471347
else:
1348-
print attr + " " * (msize - len(attr)), ":",
1348+
print(attr + " " * (msize - len(attr)), ":", end=' ')
13491349
if rec is None:
1350-
print rec
1350+
print(rec)
13511351
elif 'flag' in attr.lower() or 'service' in attr.lower():
1352-
print hex(rec)
1352+
print(hex(rec))
13531353
if _dump_ExpandLists == True:
13541354
for x in xrange(32):
13551355
z = pow(2, x)
13561356
if rec & z == z:
1357-
print " " * _dump_RecIndent, " Active" + " " * (msize - len(" Active")), " :", hex(z)
1357+
print(" " * _dump_RecIndent, " Active" + " " * (msize - len(" Active")), " :", hex(z))
13581358

13591359
elif isinstance(rec, list):
13601360
if len(rec) > 0:
@@ -1364,15 +1364,15 @@ def fflags(y):
13641364
IsFidList = False
13651365
break
13661366
if IsFidList:
1367-
print rec
1367+
print(rec)
13681368
elif not wasList:
1369-
print rec
1369+
print(rec)
13701370
elif not wasList:
1371-
print rec
1371+
print(rec)
13721372
elif isinstance(rec, basestring):
1373-
print repr(rec)
1373+
print(repr(rec))
13741374
elif not wasList:
1375-
print rec
1375+
print(rec)
13761376
_dump_RecIndent += 2
13771377
printRecord(rec)
13781378
_dump_RecIndent -= 2
@@ -1383,12 +1383,12 @@ def fflags(y):
13831383
for rec in record:
13841384
printRecord(rec)
13851385
if _dump_LastIndent == _dump_RecIndent:
1386-
print
1386+
print()
13871387
global _dump_ExpandLists
13881388
_dump_ExpandLists = expand
13891389
try:
13901390
msize = max([len(attr) for attr in record.copyattrs])
1391-
print " fid" + " " * (msize - len("fid")), ":", record.fid
1391+
print(" fid" + " " * (msize - len("fid")), ":", record.fid)
13921392
except AttributeError:
13931393
pass
13941394
printRecord(record)

0 commit comments

Comments
 (0)