X-Git-Url: http://git.tremily.us/?p=hooke.git;a=blobdiff_plain;f=hooke%2Fui%2Fcommandline.py;h=d6801f93d35227287b9fc0b68a10860d4d55b695;hp=be0f14a8b02184dc4ecf1551587a152d09a0605a;hb=HEAD;hpb=be1cce68dfffc3f65de215c1e6fe010b84eab14b diff --git a/hooke/ui/commandline.py b/hooke/ui/commandline.py index be0f14a..d6801f9 100644 --- a/hooke/ui/commandline.py +++ b/hooke/ui/commandline.py @@ -1,20 +1,19 @@ -# Copyright (C) 2010 W. Trevor King +# Copyright (C) 2010-2012 W. Trevor King # # This file is part of Hooke. # -# Hooke is free software: you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# Hooke is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. # -# Hooke is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General -# Public License for more details. +# Hooke is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. # -# You should have received a copy of the GNU Lesser General Public -# License along with Hooke. If not, see -# . +# You should have received a copy of the GNU Lesser General Public License +# along with Hooke. If not, see . """Defines :class:`CommandLine` for driving Hooke from the command line. @@ -24,6 +23,7 @@ import codecs import cmd import logging import optparse +import pprint try: import readline # including readline makes cmd.Cmd.cmdloop() smarter except ImportError, e: @@ -152,7 +152,7 @@ class DoCommand (CommandMethod): try: args = self._parse_args(args) except optparse.OptParseError, e: - self.cmd.stdout.write(str(e).lstrip()+'\n') + self.cmd.stdout.write(unicode(e).lstrip()+'\n') self.cmd.stdout.write('Failure\n') return cm = CommandMessage(self.command.name, args) @@ -163,7 +163,7 @@ class DoCommand (CommandMethod): return True elif isinstance(msg, CommandExit): self.cmd.stdout.write(msg.__class__.__name__+'\n') - self.cmd.stdout.write(str(msg).rstrip()+'\n') + self.cmd.stdout.write(unicode(msg).rstrip()+'\n') break elif isinstance(msg, ReloadUserInterfaceConfig): self.cmd.ui.reload_config(msg.config) @@ -174,7 +174,11 @@ class DoCommand (CommandMethod): except EOF: return True continue - self.cmd.stdout.write(unicode(msg).rstrip()+'\n') + if isinstance(msg, dict): + text = pprint.pformat(msg) + else: + text = unicode(msg) + self.cmd.stdout.write(text.rstrip()+'\n') def _parse_args(self, args): options,args = self.parser.parse_args(args) @@ -242,7 +246,7 @@ class DoCommand (CommandMethod): while True: if error != None: self.cmd.stdout.write(''.join([ - error.__class__.__name__, ': ', str(error), '\n'])) + error.__class__.__name__, ': ', unicode(error), '\n'])) self.cmd.stdout.write(prompt_string) stdin = sys.stdin try: