aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/cmdutil.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2008-11-25 15:47:19 -0500
committerW. Trevor King <wking@drexel.edu>2008-11-25 15:47:19 -0500
commit5699aef2a5741c5ffc24d9cb12d6bc9b085d484a (patch)
tree84ac8783ce2d1f9a28ba0bd0c256ae7179c68507 /libbe/cmdutil.py
parented4d971d1375a692fbd3a394237f56e851bb5d0e (diff)
downloadbugseverywhere-5699aef2a5741c5ffc24d9cb12d6bc9b085d484a.tar.gz
Added libbe/encoding.py to wrap input/output/file access appropriately.
I borrowed most of the code for this. get_encoding() is from Trac http://trac.edgewall.org/browser/trunk/trac/util/datefmt.py format_datetime() Trac has a BSD license http://trac.edgewall.org/wiki/TracLicense I don't know if such a small snippet requires us to "reproduce the above copyright" or where we need to reproduce it if it is needed. The stdout/stdin replacement code follows http://wiki.python.org/moin/ShellRedirectionFails Because of the stdout replacement, the doctests executes now need an optional 'test' argument to turn off replacement during the doctests, otherwise doctest flips out (since it had set up stdout to catch output, and then we clobbered it's setup). References: http://wiki.python.org/moin/Unicode http://www.amk.ca/python/howto/unicode http://www.python.org/dev/peps/pep-0100/ I also split libbe/editor.py off from libbe.utility.py and started explaining the motivation for the BugDir init flags in it's docstring.
Diffstat (limited to 'libbe/cmdutil.py')
-rw-r--r--libbe/cmdutil.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py
index 6d7ab01..1a321e9 100644
--- a/libbe/cmdutil.py
+++ b/libbe/cmdutil.py
@@ -16,14 +16,14 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import optparse
import os
-import locale
from textwrap import TextWrapper
from StringIO import StringIO
import doctest
import bugdir
import plugin
-import utility
+import encoding
+
class UserError(Exception):
def __init__(self, msg):
@@ -34,6 +34,13 @@ class UserErrorWrap(UserError):
UserError.__init__(self, str(exception))
self.exception = exception
+class GetHelp(Exception):
+ pass
+
+class UsageError(Exception):
+ pass
+
+
def iter_commands():
for name, module in plugin.iter_plugins("becommands"):
yield name.replace("_", "-"), module
@@ -52,9 +59,11 @@ def get_command(command_name):
raise UserError("Unknown command %s" % command_name)
return cmd
+
def execute(cmd, args):
- encoding = locale.getpreferredencoding() or 'ascii'
- return get_command(cmd).execute([a.decode(encoding) for a in args])
+ enc = encoding.get_encoding()
+ get_command(cmd).execute([a.decode(enc) for a in args])
+ return 0
def help(cmd=None):
if cmd != None:
@@ -71,17 +80,8 @@ def help(cmd=None):
ret.append("be %s%*s %s" % (name, numExtraSpaces, "", desc))
return "\n".join(ret)
-class GetHelp(Exception):
- pass
-
-
-class UsageError(Exception):
- pass
-
-
def raise_get_help(option, opt, value, parser):
raise GetHelp
-
class CmdOptionParser(optparse.OptionParser):
def __init__(self, usage):