diff options
author | W. Trevor King <wking@drexel.edu> | 2009-12-14 07:37:51 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-12-14 07:37:51 -0500 |
commit | 19fe0817ba7c2cd04caea3adfa82d4490288a548 (patch) | |
tree | 6291cac9b9861f1009d63a419c3e79879f356bc8 /libbe/ui | |
parent | 2f0ceedba5b6619faf476cd1aa67e826e91d5c7c (diff) | |
download | bugseverywhere-19fe0817ba7c2cd04caea3adfa82d4490288a548.tar.gz |
Transitioned comment to Command format
Diffstat (limited to 'libbe/ui')
-rwxr-xr-x | libbe/ui/command_line.py | 38 | ||||
-rw-r--r-- | libbe/ui/util/editor.py | 11 |
2 files changed, 31 insertions, 18 deletions
diff --git a/libbe/ui/command_line.py b/libbe/ui/command_line.py index c59a302..4042123 100755 --- a/libbe/ui/command_line.py +++ b/libbe/ui/command_line.py @@ -43,8 +43,8 @@ class CmdOptionParser(optparse.OptionParser): def __init__(self, command): self.command = command optparse.OptionParser.__init__(self) - self.disable_interspersed_args() self.remove_option('-h') + self.disable_interspersed_args() self._option_by_name = {} for option in self.command.options: self._add_option(option) @@ -62,12 +62,13 @@ class CmdOptionParser(optparse.OptionParser): if option.arg == None: # a callback option kwargs['action'] = 'callback' kwargs['callback'] = self.callback + elif option.arg.type == 'bool': + kwargs['action'] = 'store_true' + kwargs['metavar'] = None + kwargs['default'] = False else: - if option.arg.type == 'bool': - kwargs['action'] = 'store_true' - else: - kwargs['type'] = option.arg.type - kwargs['action'] = 'store' + kwargs['type'] = option.arg.type + kwargs['action'] = 'store' kwargs['metavar'] = option.arg.metavar kwargs['default'] = option.arg.default if option.short_name != None: @@ -143,7 +144,6 @@ class CmdOptionParser(optparse.OptionParser): raise CallbackExit def complete(self, argument=None, fragment=None): - print argument, fragment comps = self.command.complete(argument, fragment) if fragment != None: comps = [c for c in comps if c.startswith(fragment)] @@ -166,13 +166,24 @@ class BE (libbe.command.Command): usage: be [options] [COMMAND [command-options] [COMMAND-ARGS ...]] <BLANKLINE> Options: - -h HELP, --help=HELP Print a help message. + -h, --help Print a help message. <BLANKLINE> - --complete=STRING Print a list of possible completions. + --complete Print a list of possible completions. <BLANKLINE> - --version=VERSION Print version string. + --version Print version string. + ... + >>> try: + ... options,args = p.parse_args(['--complete']) # doctest: +ELLIPSIS + ... except CallbackExit: + ... print ' got callback' + --help + --complete + --version ... - >>> options,args = p.parse_args(['--complete']) # doctest: +ELLIPSIS + subscribe + tag + target + got callback """ name = 'be' @@ -262,8 +273,11 @@ def main(): storage = libbe.storage.get_storage(options['repo']) storage.connect() bugdir = libbe.bugdir.BugDir(storage, from_storage=True) - elif: command.requires_unconnected_storage == True: + elif command.requires_storage == True \ + or command.requires_unconnected_storage == True: storage = libbe.storage.get_storage(options['repo']) + if command.requires_unconnected_storage == False: + storage.connect() try: options,args = parser.parse_args(args[1:]) command.run(storage, bugdir, options, args) diff --git a/libbe/ui/util/editor.py b/libbe/ui/util/editor.py index 859cedc..83262e7 100644 --- a/libbe/ui/util/editor.py +++ b/libbe/ui/util/editor.py @@ -28,12 +28,12 @@ import sys import tempfile import libbe +import libbe.util.encoding + if libbe.TESTING == True: import doctest -default_encoding = sys.getfilesystemencoding() or locale.getpreferredencoding() - comment_marker = u"== Anything below this line will be ignored\n" class CantFindEditor(Exception): @@ -60,7 +60,7 @@ def editor_string(comment=None, encoding=None): >>> del os.environ["VISUAL"] """ if encoding == None: - encoding = default_encoding + encoding = libbe.util.encoding.get_filesystem_encoding() for name in ('VISUAL', 'EDITOR'): try: editor = os.environ[name] @@ -77,9 +77,8 @@ def editor_string(comment=None, encoding=None): os.close(fhandle) oldmtime = os.path.getmtime(fname) os.system("%s %s" % (editor, fname)) - f = codecs.open(fname, "r", encoding) - output = trimmed_string(f.read()) - f.close() + output = libbe.util.encoding.get_file_contents( + fname, encoding=encoding, decode=True) if output.rstrip('\n') == "": output = None finally: |