From 74024c584a63d80f3da96ae3c2a00ee4e4d91044 Mon Sep 17 00:00:00 2001 From: Karl-Philipp Richter Date: Fri, 6 Mar 2020 22:32:57 +0100 Subject: [PATCH] Fix print syntax for Python 3.x compatibility --- rapid/ui/qt/gui.py | 14 +++++++------- rapid/ui/text/interaction.py | 24 ++++++++++++------------ rapid/ui/text/main.py | 20 ++++++++++---------- rapid/ui/text/progressbar.py | 2 +- rapid/unitsync/api.py | 10 +++++----- rapid/unitsync/generate.py | 6 +++--- run.py | 4 ++-- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/rapid/ui/qt/gui.py b/rapid/ui/qt/gui.py index aa150f2..9dab018 100644 --- a/rapid/ui/qt/gui.py +++ b/rapid/ui/qt/gui.py @@ -35,8 +35,8 @@ def run(self): elif os.name == 'posix': main.init(os.path.expanduser('~/.spring'), ui) else: - print 'No data directory specified. Specify one using either --datadir or --unitsync.' - print + print('No data directory specified. Specify one using either --datadir or --unitsync.') + print() installed,available = split_on_condition( main.rapid.packages, lambda p: p.installed ) self.mainWidget.reload( installed,available ) #progress.destroy() @@ -70,11 +70,11 @@ def install_single(self, p, dep = False): for d in p.dependencies: self.install_single(d, True) if not p.installed: - print ['Installing: ', 'Installing dependency: '][int(dep)] + p.name + print(['Installing: ', 'Installing dependency: '][int(dep)] + p.name) p.install(self) - print + print() elif not dep: - print 'Already installed: ' + p.name + print('Already installed: ' + p.name) def __call__(self, value ): self.emit( QtCore.SIGNAL("incrementValue"), value ) @@ -154,7 +154,7 @@ def doubleClicked(self,modelIndex): QtGui.QMessageBox.information( self.parent, "Done","%s was removed"%p.name ) self.sourceModel.reload() except Exception, e: - print e + print(e) QtGui.QMessageBox.critical( self.parent, "Error", "Removing %s failed\n%s"%(p.name,str(e)) ) @@ -168,7 +168,7 @@ def __init__(self,parent): def doubleClicked(self,modelIndex): item = self.sourceModel.itemFromIndex( self.proxyModel.mapToSource( modelIndex ) ) tag = str(item.text()) - print 'downloading ',tag + print('downloading ',tag) self.dl = DownloadDialog(self.parent,tag) self.dl.show() self.connect( self.dl.dt, QtCore.SIGNAL("downloadComplete"), self.parent.reload, QtCore.Qt.QueuedConnection ) diff --git a/rapid/ui/text/interaction.py b/rapid/ui/text/interaction.py index 21cac5e..3ceee79 100644 --- a/rapid/ui/text/interaction.py +++ b/rapid/ui/text/interaction.py @@ -19,9 +19,9 @@ def _to_i_bounds_check(self, text, lower, upper): def choose_many(self, header, options, question): """ Let the user choose multiple options from a list.""" - print header + print(header) for i in range(len(options)): - print '%2i. %s' % (i + 1, options[i]) + print('%2i. %s' % (i + 1, options[i])) which = raw_input(question + ' [enter number(s) or "all"]: ') if which.lower().strip() == 'all': return options @@ -30,7 +30,7 @@ def choose_many(self, header, options, question): n = len(options) which = [self._to_i_bounds_check(x, 1, n) - 1 for x in which] except (ValueError, IndexError) as e: - print type(e).__name__ + ':', str(e) + print(type(e).__name__ + ':', str(e)) return [] return [options[x] for x in which] @@ -46,11 +46,11 @@ def select(self, noun, needle, haystack): selected = self._select_core(needle, haystack) if len(selected) == 0: - print 'No %ss matching "%s" found.' % (noun, needle) + print('No %ss matching "%s" found.' % (noun, needle)) return selected if len(selected) >= 100: - print '100 or more %ss matching "%s" found, please narrow your search.' % (noun, needle) + print('100 or more %ss matching "%s" found, please narrow your search.' % (noun, needle)) return [] if len(selected) > 1: @@ -60,18 +60,18 @@ def select(self, noun, needle, haystack): def output_header(self, text): """ Output the header of a list/table.""" - print text + print(text) def output_detail(self, text): """ Output a detail row of a list/table. TODO: Interface should be improved.""" - print text + print(text) def important_warning(self, *lines): """ Display an important warning to the user.""" - print - print '#' * 79 + print() + print('#' * 79) for line in lines: - print '# %-75s #' % line.center(75) - print '#' * 79 - print + print('# %-75s #' % line.center(75)) + print('#' * 79) + print() diff --git a/rapid/ui/text/main.py b/rapid/ui/text/main.py index 25dc9f1..9f283d1 100644 --- a/rapid/ui/text/main.py +++ b/rapid/ui/text/main.py @@ -78,8 +78,8 @@ def req_arg(): """ Returns the next positional argument or displays an error and exits if there are no arguments left.""" if len(args) < 1: - print 'Not enough arguments to operation.' - print + print('Not enough arguments to operation.') + print() usage() return args.pop(0) @@ -94,10 +94,10 @@ def opt_arg(): # Only the left side is expanded by git-archive, so when the left side # and the right side differ we are running a real release. if '$Format:%h%d$'[1:-1] == 'Format:%h%d': - print 'No version information available.', - print 'Are you using a development version?' + print('No version information available.') + print('Are you using a development version?') else: - print 'Exported from git commit: $Format:%h%d$' + print('Exported from git commit: $Format:%h%d$') sys.exit(0) if len(args) < 1: @@ -118,8 +118,8 @@ def opt_arg(): elif os.name == 'posix': init(os.path.expanduser('~/.spring'), ui) else: - print 'No data directory specified. Specify one using either --datadir or --unitsync.' - print + print('No data directory specified. Specify one using either --datadir or --unitsync.') + print() usage() # Loop conditions are at the end. @@ -144,7 +144,7 @@ def opt_arg(): if len(args) == 0: break else: - print '---' + print('---') # Commands which have a fixed number of arguments. if verb == 'list-packages': @@ -166,6 +166,6 @@ def opt_arg(): elif verb == 'make-sdd': make_sdd(req_arg(), req_arg()) elif not handled: - print 'Unknown operation: ' + verb - print + print('Unknown operation: ' + verb) + print() usage() diff --git a/rapid/ui/text/progressbar.py b/rapid/ui/text/progressbar.py index dde32d0..b80a837 100644 --- a/rapid/ui/text/progressbar.py +++ b/rapid/ui/text/progressbar.py @@ -73,7 +73,7 @@ def __call__(self, value): carriage return first, so it will overwrite the current line in stdout.""" if self.amount < self.max: - print '\r', + print('\r') self.update_amount(self.amount + value) sys.stdout.write(str(self)) sys.stdout.write(self.amount < self.max and "\r" or "\n") diff --git a/rapid/unitsync/api.py b/rapid/unitsync/api.py index 68da8c6..4f1e33f 100644 --- a/rapid/unitsync/api.py +++ b/rapid/unitsync/api.py @@ -49,9 +49,9 @@ def generate_locations(): if type == _winreg.REG_SZ: yield value else: - print 'key of unknown type' + print('key of unknown type') except WindowsError as e: - print "Registry key not found: " + str(e) + print("Registry key not found: " + str(e)) program_files = os.getenv('ProgramFiles') if program_files: for filename in filenames: @@ -86,13 +86,13 @@ def get_writable_data_directory(): def test(): # Quick test. for location in generate_locations(): - print location + print(location) unitsync = locate_unitsync() # This is not available in older versions of unitsync. - print 'Has GetMapDescription?', unitsync.has('GetMapDescription') + print('Has GetMapDescription?', unitsync.has('GetMapDescription')) # Test main interface. data_directory = get_writable_data_directory() - print '===>', data_directory, '<===' + print('===>', data_directory, '<===') if __name__ == '__main__': diff --git a/rapid/unitsync/generate.py b/rapid/unitsync/generate.py index a4f21f7..6c21c8d 100644 --- a/rapid/unitsync/generate.py +++ b/rapid/unitsync/generate.py @@ -75,14 +75,14 @@ def __init__(self, location): if os.path.isfile('./unitsync_api.h'): argv.append('./unitsync_api.h') else: - print 'must be passed unitsync_api.h to generate bindings' - print 'if on windows, you can simply drag the file onto this one' + print('must be passed unitsync_api.h to generate bindings') + print('if on windows, you can simply drag the file onto this one') time.sleep(30) sys.exit(1) name = argv[1] if not os.path.isfile(name): - print '%s is not a valid file' % name + print('%s is not a valid file' % name) time.sleep(30) sys.exit(1) diff --git a/run.py b/run.py index 00e4385..c29a2d1 100755 --- a/run.py +++ b/run.py @@ -7,9 +7,9 @@ def main(): sys.path = [os.path.normpath(os.path.dirname(os.path.realpath(__file__)))] + sys.path if len(sys.argv) < 2: - print """Usage: %s foo.py [arguments...]' + print("""Usage: %s foo.py [arguments...]' Runs foo.py as if it was run directly, except that sys.path is modified so that -development copies of modules (relative to this script) are picked up first.""" % sys.argv[0] +development copies of modules (relative to this script) are picked up first.""" % sys.argv[0]) sys.exit(1) # Cloak =)