comparison roundup/admin.py @ 1244:8dd4f736370b

merge from maintenance branch
author Richard Jones <richard@users.sourceforge.net>
date Thu, 03 Oct 2002 06:56:30 +0000
parents cab21a36286d
children 8dc60d87ab42
comparison
equal deleted inserted replaced
1243:3a028d2f7830 1244:8dd4f736370b
14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
18 # 18 #
19 # $Id: admin.py,v 1.34 2002-09-26 07:41:54 richard Exp $ 19 # $Id: admin.py,v 1.35 2002-10-03 06:56:28 richard Exp $
20
21 '''Administration commands for maintaining Roundup trackers.
22 '''
20 23
21 import sys, os, getpass, getopt, re, UserDict, shlex, shutil 24 import sys, os, getpass, getopt, re, UserDict, shlex, shutil
22 try: 25 try:
23 import csv 26 import csv
24 except ImportError: 27 except ImportError:
49 52
50 class UsageError(ValueError): 53 class UsageError(ValueError):
51 pass 54 pass
52 55
53 class AdminTool: 56 class AdminTool:
54 57 ''' A collection of methods used in maintaining Roundup trackers.
58
59 Typically these methods are accessed through the roundup-admin
60 script. The main() method provided on this class gives the main
61 loop for the roundup-admin script.
62
63 Actions are defined by do_*() methods, with help for the action
64 given in the method docstring.
65
66 Additional help may be supplied by help_*() methods.
67 '''
55 def __init__(self): 68 def __init__(self):
56 self.commands = CommandDict() 69 self.commands = CommandDict()
57 for k in AdminTool.__dict__.keys(): 70 for k in AdminTool.__dict__.keys():
58 if k[:3] == 'do_': 71 if k[:3] == 'do_':
59 self.commands[k[3:]] = getattr(self, k) 72 self.commands[k[3:]] = getattr(self, k)
71 return self.db.getclass(classname) 84 return self.db.getclass(classname)
72 except KeyError: 85 except KeyError:
73 raise UsageError, _('no such class "%(classname)s"')%locals() 86 raise UsageError, _('no such class "%(classname)s"')%locals()
74 87
75 def props_from_args(self, args): 88 def props_from_args(self, args):
89 ''' Produce a dictionary of prop: value from the args list.
90
91 The args list is specified as ``prop=value prop=value ...``.
92 '''
76 props = {} 93 props = {}
77 for arg in args: 94 for arg in args:
78 if arg.find('=') == -1: 95 if arg.find('=') == -1:
79 raise UsageError, _('argument "%(arg)s" not propname=value')%locals() 96 raise UsageError, _('argument "%(arg)s" not propname=value'
97 )%locals()
80 try: 98 try:
81 key, value = arg.split('=') 99 key, value = arg.split('=')
82 except ValueError: 100 except ValueError:
83 raise UsageError, _('argument "%(arg)s" not propname=value')%locals() 101 raise UsageError, _('argument "%(arg)s" not propname=value'
102 )%locals()
84 if value: 103 if value:
85 props[key] = value 104 props[key] = value
86 else: 105 else:
87 props[key] = None 106 props[key] = None
88 return props 107 return props
89 108
90 def usage(self, message=''): 109 def usage(self, message=''):
110 ''' Display a simple usage message.
111 '''
91 if message: 112 if message:
92 message = _('Problem: %(message)s)\n\n')%locals() 113 message = _('Problem: %(message)s)\n\n')%locals()
93 print _('''%(message)sUsage: roundup-admin [options] <command> <arguments> 114 print _('''%(message)sUsage: roundup-admin [options] <command> <arguments>
94 115
95 Options: 116 Options:
104 roundup-admin help all -- all available help 125 roundup-admin help all -- all available help
105 ''')%locals() 126 ''')%locals()
106 self.help_commands() 127 self.help_commands()
107 128
108 def help_commands(self): 129 def help_commands(self):
130 ''' List the commands available with their precis help.
131 '''
109 print _('Commands:'), 132 print _('Commands:'),
110 commands = [''] 133 commands = ['']
111 for command in self.commands.values(): 134 for command in self.commands.values():
112 h = command.__doc__.split('\n')[0] 135 h = command.__doc__.split('\n')[0]
113 commands.append(' '+h[7:]) 136 commands.append(' '+h[7:])
116 commands.append(_('command, e.g. l == li == lis == list.')) 139 commands.append(_('command, e.g. l == li == lis == list.'))
117 print '\n'.join(commands) 140 print '\n'.join(commands)
118 print 141 print
119 142
120 def help_commands_html(self, indent_re=re.compile(r'^(\s+)\S+')): 143 def help_commands_html(self, indent_re=re.compile(r'^(\s+)\S+')):
121 commands = self.commands.values() 144 ''' Produce an HTML command list.
145 '''
146 commands = self.commands.values()
122 def sortfun(a, b): 147 def sortfun(a, b):
123 return cmp(a.__name__, b.__name__) 148 return cmp(a.__name__, b.__name__)
124 commands.sort(sortfun) 149 commands.sort(sortfun)
125 for command in commands: 150 for command in commands:
126 h = command.__doc__.split('\n') 151 h = command.__doc__.split('\n')
127 name = command.__name__[3:] 152 name = command.__name__[3:]
128 usage = h[0] 153 usage = h[0]
129 print _(''' 154 print _('''
130 <tr><td valign=top><strong>%(name)s</strong></td> 155 <tr><td valign=top><strong>%(name)s</strong></td>
306 init.install(tracker_home, template, backend) 331 init.install(tracker_home, template, backend)
307 332
308 print _(''' 333 print _('''
309 You should now edit the tracker configuration file: 334 You should now edit the tracker configuration file:
310 %(config_file)s 335 %(config_file)s
311 ... at a minimum, you must set MAILHOST, MAIL_DOMAIN and ADMIN_EMAIL. 336 ... at a minimum, you must set MAILHOST, TRACKER_WEB, MAIL_DOMAIN and
337 ADMIN_EMAIL.
312 338
313 If you wish to modify the default schema, you should also edit the database 339 If you wish to modify the default schema, you should also edit the database
314 initialisation file: 340 initialisation file:
315 %(database_config_file)s 341 %(database_config_file)s
316 ... see the documentation on customizing for more information. 342 ... see the documentation on customizing for more information.

Roundup Issue Tracker: http://roundup-tracker.org/