X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=roundup%2Fadmin.py;h=88cbace2c8e6e3bb253a4d1ec896c38eadd70d07;hb=acd718eb6d28335be2c805236b238c27d5d8d7e2;hp=a73c086cbd82ed76392efe0fe6c482b431e127d5;hpb=b5c486ed75085168302bfb5eabcaa839a7e692ae;p=roundup.git diff --git a/roundup/admin.py b/roundup/admin.py index a73c086..88cbace 100644 --- a/roundup/admin.py +++ b/roundup/admin.py @@ -16,7 +16,10 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: admin.py,v 1.31 2002-09-18 05:07:47 richard Exp $ +# $Id: admin.py,v 1.35 2002-10-03 06:56:28 richard Exp $ + +'''Administration commands for maintaining Roundup trackers. +''' import sys, os, getpass, getopt, re, UserDict, shlex, shutil try: @@ -51,7 +54,17 @@ class UsageError(ValueError): pass class AdminTool: + ''' A collection of methods used in maintaining Roundup trackers. + + Typically these methods are accessed through the roundup-admin + script. The main() method provided on this class gives the main + loop for the roundup-admin script. + + Actions are defined by do_*() methods, with help for the action + given in the method docstring. + Additional help may be supplied by help_*() methods. + ''' def __init__(self): self.commands = CommandDict() for k in AdminTool.__dict__.keys(): @@ -73,14 +86,20 @@ class AdminTool: raise UsageError, _('no such class "%(classname)s"')%locals() def props_from_args(self, args): + ''' Produce a dictionary of prop: value from the args list. + + The args list is specified as ``prop=value prop=value ...``. + ''' props = {} for arg in args: if arg.find('=') == -1: - raise UsageError, _('argument "%(arg)s" not propname=value')%locals() + raise UsageError, _('argument "%(arg)s" not propname=value' + )%locals() try: key, value = arg.split('=') except ValueError: - raise UsageError, _('argument "%(arg)s" not propname=value')%locals() + raise UsageError, _('argument "%(arg)s" not propname=value' + )%locals() if value: props[key] = value else: @@ -88,6 +107,8 @@ class AdminTool: return props def usage(self, message=''): + ''' Display a simple usage message. + ''' if message: message = _('Problem: %(message)s)\n\n')%locals() print _('''%(message)sUsage: roundup-admin [options] @@ -106,6 +127,8 @@ Help: self.help_commands() def help_commands(self): + ''' List the commands available with their precis help. + ''' print _('Commands:'), commands = [''] for command in self.commands.values(): @@ -118,11 +141,13 @@ Help: print def help_commands_html(self, indent_re=re.compile(r'^(\s+)\S+')): - commands = self.commands.values() + ''' Produce an HTML command list. + ''' + commands = self.commands.values() def sortfun(a, b): return cmp(a.__name__, b.__name__) commands.sort(sortfun) - for command in commands: + for command in commands: h = command.__doc__.split('\n') name = command.__name__[3:] usage = h[0] @@ -308,7 +333,8 @@ Command help: print _(''' You should now edit the tracker configuration file: %(config_file)s - ... at a minimum, you must set MAILHOST, MAIL_DOMAIN and ADMIN_EMAIL. + ... at a minimum, you must set MAILHOST, TRACKER_WEB, MAIL_DOMAIN and + ADMIN_EMAIL. If you wish to modify the default schema, you should also edit the database initialisation file: @@ -397,7 +423,7 @@ Command help: return 0 - def do_set(self, args): + def do_set(self, args, pwre = re.compile(r'{(\w+)}(.+)')): '''Usage: set [items] property=value property=value ... Set the given properties of one or more items(s). @@ -447,7 +473,15 @@ Command help: elif isinstance(proptype, hyperdb.String): continue elif isinstance(proptype, hyperdb.Password): - props[key] = password.Password(value) + m = pwre.match(value) + if m: + # password is being given to us encrypted + p = password.Password() + p.scheme = m.group(1) + p.password = m.group(2) + props[key] = p + else: + props[key] = password.Password(value) elif isinstance(proptype, hyperdb.Date): try: props[key] = date.Date(value) @@ -469,6 +503,7 @@ Command help: try: apply(cl.set, (itemid, ), props) except (TypeError, IndexError, ValueError), message: + import traceback; traceback.print_exc() raise UsageError, message return 0 @@ -570,7 +605,7 @@ Command help: value = cl.get(nodeid, key) print _('%(key)s: %(value)s')%locals() - def do_create(self, args): + def do_create(self, args, pwre = re.compile(r'{(\w+)}(.+)')): '''Usage: create classname property=value ... Create a new entry of a given class. @@ -633,7 +668,15 @@ Command help: except ValueError, message: raise UsageError, _('"%(value)s": %(message)s')%locals() elif isinstance(proptype, hyperdb.Password): - props[propname] = password.Password(value) + m = pwre.match(value) + if m: + # password is being given to us encrypted + p = password.Password() + p.scheme = m.group(1) + p.password = m.group(2) + props[propname] = p + else: + props[propname] = password.Password(value) elif isinstance(proptype, hyperdb.Multilink): props[propname] = value.split(',') elif isinstance(proptype, hyperdb.Boolean): @@ -931,8 +974,8 @@ Command help: # do the import and figure the current highest nodeid maxid = max(maxid, int(cl.import_list(propnames, l))) - print 'setting', classname, maxid - self.db.setid(classname, str(maxid)) + print 'setting', classname, maxid+1 + self.db.setid(classname, str(maxid+1)) return 0 def do_pack(self, args):