From: richard Date: Thu, 8 Nov 2001 04:29:59 +0000 (+0000) Subject: roundup-admin now accepts abbreviated commands (eg. l = li = lis = list) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=554024f7ac6c5cc9f639c98bf824b41733d30b99;p=roundup.git roundup-admin now accepts abbreviated commands (eg. l = li = lis = list) [thanks Engelbert Gruber for the inspiration] git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@382 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index 2095b52..6ed0501 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,7 @@ Feature: . Added Structured Text rendering to htmltemplate, thanks Brad Clements. . Added CGI configuration via env vars (see roundup.cgi for details) . "roundup.cgi" is now installed to "/share/roundup/cgi-bin" + . roundup-admin now accepts abbreviated commands (eg. l = li = lis = list) Fixed: . Fixed a bug in HTMLTemplate changes. diff --git a/roundup-admin b/roundup-admin index 8ea9173..7250e91 100755 --- a/roundup-admin +++ b/roundup-admin @@ -16,14 +16,14 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: roundup-admin,v 1.38 2001-11-05 23:45:40 richard Exp $ +# $Id: roundup-admin,v 1.39 2001-11-08 04:29:59 richard Exp $ import sys if int(sys.version[0]) < 2: print 'Roundup requires python 2.0 or later.' sys.exit(1) -import string, os, getpass, getopt, re +import string, os, getpass, getopt, re, UserDict try: import csv except ImportError: @@ -31,10 +31,29 @@ except ImportError: from roundup import date, hyperdb, roundupdb, init, password import roundup.instance +class CommandDict(UserDict.UserDict): + '''Simple dictionary that lets us do lookups using partial keys. + + Original code submitted by Engelbert Gruber. + ''' + _marker = [] + def get(self, key, default=_marker): + d = self.data.get(key, default) + if d is not default: return [(key, d)] + keylist = self.data.keys() + keylist.sort() + l = [] + for ki in keylist: + if ki.startswith(key): + l.append((ki, self.data[ki])) + if not l and default is self._marker: + raise KeyError, key + return l + class AdminTool: def __init__(self): - self.commands = {} + self.commands = CommandDict() for k in AdminTool.__dict__.keys(): if k[:3] == 'do_': self.commands[k[3:]] = getattr(self, k) @@ -131,13 +150,22 @@ Command help: initopts -- init command options all -- all available help ''' - help = self.help.get(args[0], None) - if help: - help() + topic = args[0] + + # try help_ methods + if self.help.has_key(topic): + self.help[topic]() + return + + # try command docstrings + try: + l = self.commands.get(topic) + except KeyError: + print 'Sorry, no help for "%s"'%topic return - help = self.commands.get(args[0], None) - if help: - # display the help, removing the docsring indent + + # display the help for each match, removing the docsring indent + for name, help in l: lines = nl_re.split(help.__doc__) print lines[0] indent = indent_re.match(lines[1]) @@ -147,8 +175,6 @@ Command help: print line[indent:] else: print line - else: - print 'Sorry, no help for "%s"'%args[0] def help_initopts(self): import roundup.templates @@ -601,6 +627,21 @@ Command help: self.help_all() return 0 + # figure what the command is + try: + functions = self.commands.get(command) + except KeyError: + # not a valid command + print 'Unknown command "%s" ("help commands" for a list)'%command + return 1 + + # check for multiple matches + if len(functions) > 1: + print 'Multiple commands match "%s": %s'%(command, + ', '.join([i[0] for i in functions])) + return 1 + command, function = functions[0] + # make sure we have an instance_home while not self.instance_home: self.instance_home = raw_input('Enter instance home: ').strip() @@ -609,13 +650,6 @@ Command help: if command == 'init': return self.do_init(self.instance_home, args) - function = self.commands.get(command, None) - - # not a valid command - if function is None: - print 'Unknown command "%s" ("help commands" for a list)'%command - return 1 - # get the instance instance = roundup.instance.open(self.instance_home) self.db = instance.open('admin') @@ -687,6 +721,10 @@ if __name__ == '__main__': # # $Log: not supported by cvs2svn $ +# Revision 1.38 2001/11/05 23:45:40 richard +# Fixed newuser_action so it sets the cookie with the unencrypted password. +# Also made it present nicer error messages (not tracebacks). +# # Revision 1.37 2001/10/23 01:00:18 richard # Re-enabled login and registration access after lopping them off via # disabling access for anonymous users.