diff options
Diffstat (limited to 'libbe/ui/command_line.py')
-rw-r--r-- | libbe/ui/command_line.py | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/libbe/ui/command_line.py b/libbe/ui/command_line.py index 5d4d80a..be6f80a 100644 --- a/libbe/ui/command_line.py +++ b/libbe/ui/command_line.py @@ -89,10 +89,10 @@ class CmdOptionParser(optparse.OptionParser): options,parsed_args = optparse.OptionParser.parse_args( self, args=args, values=values) options = options.__dict__ - for name,value in options.items(): + for name,value in list(options.items()): if '_' in name: # reconstruct original option name options[name.replace('_', '-')] = options.pop(name) - for name,value in options.items(): + for name,value in list(options.items()): argument = None option = self._option_by_name[name] if option.arg != None: @@ -157,8 +157,8 @@ class CmdOptionParser(optparse.OptionParser): fragment = parser.rargs[0] self.complete(argument, fragment) else: - print >> self.command.stdout, command_option.callback( - self.command, command_option, value) + print(command_option.callback( + self.command, command_option, value), file=self.command.stdout) raise CallbackExit def complete(self, argument=None, fragment=None): @@ -166,7 +166,7 @@ class CmdOptionParser(optparse.OptionParser): if fragment != None: comps = [c for c in comps if c.startswith(fragment)] if len(comps) > 0: - print >> self.command.stdout, '\n'.join(comps) + print('\n'.join(comps), file=self.command.stdout) raise CallbackExit def process_raw_argument(self, argument, value): @@ -175,7 +175,7 @@ class CmdOptionParser(optparse.OptionParser): if argument.type == 'string': if not hasattr(self, 'argv_encoding'): self.argv_encoding = libbe.util.encoding.get_argv_encoding() - return unicode(value, self.argv_encoding) + return str(value, self.argv_encoding) return value @@ -305,36 +305,36 @@ def dispatch(ui, command, args): ret = ui.run(command, options, args) except CallbackExit: return 0 - except UnicodeDecodeError, e: - print >> ui.io.stdout, '\n'.join([ + except UnicodeDecodeError as e: + print('\n'.join([ 'ERROR:', str(e), 'You should set a locale that supports unicode, e.g.', ' export LANG=en_US.utf8', 'See http://docs.python.org/library/locale.html for details', - ]) + ]), file=ui.io.stdout) return 1 - except libbe.command.UsageError, e: - print >> ui.io.stdout, 'Usage Error:\n', e + except libbe.command.UsageError as e: + print('Usage Error:\n', e, file=ui.io.stdout) if e.command: - print >> ui.io.stdout, e.command.usage() - print >> ui.io.stdout, 'For usage information, try' - print >> ui.io.stdout, ' be help %s' % e.command_name + print(e.command.usage(), file=ui.io.stdout) + print('For usage information, try', file=ui.io.stdout) + print(' be help %s' % e.command_name, file=ui.io.stdout) return 1 - except libbe.command.UserError, e: - print >> ui.io.stdout, 'ERROR:\n', e + except libbe.command.UserError as e: + print('ERROR:\n', e, file=ui.io.stdout) return 1 - except OSError, e: - print >> ui.io.stdout, 'OSError:\n', e + except OSError as e: + print('OSError:\n', e, file=ui.io.stdout) return 1 - except libbe.storage.ConnectionError, e: - print >> ui.io.stdout, 'Connection Error:\n', e + except libbe.storage.ConnectionError as e: + print('Connection Error:\n', e, file=ui.io.stdout) return 1 - except libbe.util.http.HTTPError, e: - print >> ui.io.stdout, 'HTTP Error:\n', e + except libbe.util.http.HTTPError as e: + print('HTTP Error:\n', e, file=ui.io.stdout) return 1 except (libbe.util.id.MultipleIDMatches, libbe.util.id.NoIDMatches, - libbe.util.id.InvalidIDStructure), e: - print >> ui.io.stdout, 'Invalid id:\n', e + libbe.util.id.InvalidIDStructure) as e: + print('Invalid id:\n', e, file=ui.io.stdout) return 1 finally: command.cleanup() @@ -352,26 +352,26 @@ def main(): options,args = parser.parse_args() except CallbackExit: return 0 - except libbe.command.UsageError, e: + except libbe.command.UsageError as e: if isinstance(e.command, BE): # no command given, print usage string - print >> ui.io.stdout, 'Usage Error:\n', e - print >> ui.io.stdout, be.usage() - print >> ui.io.stdout, 'For example, try' - print >> ui.io.stdout, ' be help' + print('Usage Error:\n', e, file=ui.io.stdout) + print(be.usage(), file=ui.io.stdout) + print('For example, try', file=ui.io.stdout) + print(' be help', file=ui.io.stdout) else: - print >> ui.io.stdout, 'Usage Error:\n', e + print('Usage Error:\n', e, file=ui.io.stdout) if e.command: - print >> ui.io.stdout, e.command.usage() - print >> ui.io.stdout, 'For usage information, try' - print >> ui.io.stdout, ' be help %s' % e.command_name + print(e.command.usage(), file=ui.io.stdout) + print('For usage information, try', file=ui.io.stdout) + print(' be help %s' % e.command_name, file=ui.io.stdout) return 1 command_name = args.pop(0) try: Class = libbe.command.get_command_class(command_name=command_name) - except libbe.command.UnknownCommand, e: - print >> ui.io.stdout, e + except libbe.command.UnknownCommand as e: + print(e, file=ui.io.stdout) return 1 ui.storage_callbacks = libbe.command.StorageCallbacks(options['repo']) @@ -392,8 +392,8 @@ def main(): ret = dispatch(ui, command, args) try: ui.cleanup() - except IOError, e: - print >> ui.io.stdout, 'IOError:\n', e + except IOError as e: + print('IOError:\n', e, file=ui.io.stdout) return 1 return ret |