annotate roundup/admin.py @ 602:c242455d9b46 config-0-4-0-branch

Brought the config branch up to date with HEAD
author Richard Jones <richard@users.sourceforge.net>
date Wed, 06 Feb 2002 04:05:55 +0000
parents 912029653c1c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
601
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1 #! /usr/bin/env python
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
2 #
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
3 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
4 # This module is free software, and you may redistribute it and/or modify
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
5 # under the same terms as Python, so long as this copyright message and
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
6 # disclaimer are retained in their original form.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
7 #
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
8 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
9 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
10 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
11 # POSSIBILITY OF SUCH DAMAGE.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
12 #
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
13 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
18 #
602
c242455d9b46 Brought the config branch up to date with HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 601
diff changeset
19 # $Id: admin.py,v 1.6.2.1 2002-02-06 04:05:53 richard Exp $
601
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
20
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
21 import sys, os, getpass, getopt, re, UserDict, shlex
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
22 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
23 import csv
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
24 except ImportError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
25 csv = None
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
26 from roundup import date, hyperdb, roundupdb, init, password, token
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
27 import roundup.instance
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
28 from roundup.i18n import _
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
29
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
30 class CommandDict(UserDict.UserDict):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
31 '''Simple dictionary that lets us do lookups using partial keys.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
32
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
33 Original code submitted by Engelbert Gruber.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
34 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
35 _marker = []
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
36 def get(self, key, default=_marker):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
37 if self.data.has_key(key):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
38 return [(key, self.data[key])]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
39 keylist = self.data.keys()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
40 keylist.sort()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
41 l = []
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
42 for ki in keylist:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
43 if ki.startswith(key):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
44 l.append((ki, self.data[ki]))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
45 if not l and default is self._marker:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
46 raise KeyError, key
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
47 return l
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
48
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
49 class UsageError(ValueError):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
50 pass
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
51
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
52 class AdminTool:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
53
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
54 def __init__(self):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
55 self.commands = CommandDict()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
56 for k in AdminTool.__dict__.keys():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
57 if k[:3] == 'do_':
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
58 self.commands[k[3:]] = getattr(self, k)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
59 self.help = {}
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
60 for k in AdminTool.__dict__.keys():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
61 if k[:5] == 'help_':
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
62 self.help[k[5:]] = getattr(self, k)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
63 self.instance_home = ''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
64 self.db = None
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
65
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
66 def get_class(self, classname):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
67 '''Get the class - raise an exception if it doesn't exist.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
68 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
69 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
70 return self.db.getclass(classname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
71 except KeyError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
72 raise UsageError, _('no such class "%(classname)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
73
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
74 def props_from_args(self, args, klass=None):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
75 props = {}
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
76 for arg in args:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
77 if arg.find('=') == -1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
78 raise UsageError, _('argument "%(arg)s" not propname=value')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
79 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
80 key, value = arg.split('=')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
81 except ValueError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
82 raise UsageError, _('argument "%(arg)s" not propname=value')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
83 props[key] = value
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
84 return props
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
85
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
86 def usage(self, message=''):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
87 if message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
88 message = _('Problem: %(message)s)\n\n')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
89 print _('''%(message)sUsage: roundup-admin [-i instance home] [-u login] [-c] <command> <arguments>
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
90
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
91 Help:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
92 roundup-admin -h
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
93 roundup-admin help -- this help
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
94 roundup-admin help <command> -- command-specific help
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
95 roundup-admin help all -- all available help
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
96 Options:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
97 -i instance home -- specify the issue tracker "home directory" to administer
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
98 -u -- the user[:password] to use for commands
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
99 -c -- when outputting lists of data, just comma-separate them''')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
100 self.help_commands()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
101
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
102 def help_commands(self):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
103 print _('Commands:'),
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
104 commands = ['']
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
105 for command in self.commands.values():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
106 h = command.__doc__.split('\n')[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
107 commands.append(' '+h[7:])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
108 commands.sort()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
109 commands.append(_('Commands may be abbreviated as long as the abbreviation matches only one'))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
110 commands.append(_('command, e.g. l == li == lis == list.'))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
111 print '\n'.join(commands)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
112 print
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
113
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
114 def help_commands_html(self, indent_re=re.compile(r'^(\s+)\S+')):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
115 commands = self.commands.values()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
116 def sortfun(a, b):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
117 return cmp(a.__name__, b.__name__)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
118 commands.sort(sortfun)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
119 for command in commands:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
120 h = command.__doc__.split('\n')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
121 name = command.__name__[3:]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
122 usage = h[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
123 print _('''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
124 <tr><td valign=top><strong>%(name)s</strong></td>
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
125 <td><tt>%(usage)s</tt><p>
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
126 <pre>''')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
127 indent = indent_re.match(h[3])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
128 if indent: indent = len(indent.group(1))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
129 for line in h[3:]:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
130 if indent:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
131 print line[indent:]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
132 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
133 print line
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
134 print _('</pre></td></tr>\n')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
135
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
136 def help_all(self):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
137 print _('''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
138 All commands (except help) require an instance specifier. This is just the path
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
139 to the roundup instance you're working with. A roundup instance is where
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
140 roundup keeps the database and configuration file that defines an issue
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
141 tracker. It may be thought of as the issue tracker's "home directory". It may
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
142 be specified in the environment variable ROUNDUP_INSTANCE or on the command
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
143 line as "-i instance".
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
144
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
145 A designator is a classname and a nodeid concatenated, eg. bug1, user10, ...
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
146
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
147 Property values are represented as strings in command arguments and in the
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
148 printed results:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
149 . Strings are, well, strings.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
150 . Date values are printed in the full date format in the local time zone, and
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
151 accepted in the full format or any of the partial formats explained below.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
152 . Link values are printed as node designators. When given as an argument,
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
153 node designators and key strings are both accepted.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
154 . Multilink values are printed as lists of node designators joined by commas.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
155 When given as an argument, node designators and key strings are both
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
156 accepted; an empty string, a single node, or a list of nodes joined by
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
157 commas is accepted.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
158
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
159 When property values must contain spaces, just surround the value with
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
160 quotes, either ' or ". A single space may also be backslash-quoted. If a
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
161 valuu must contain a quote character, it must be backslash-quoted or inside
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
162 quotes. Examples:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
163 hello world (2 tokens: hello, world)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
164 "hello world" (1 token: hello world)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
165 "Roch'e" Compaan (2 tokens: Roch'e Compaan)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
166 Roch\'e Compaan (2 tokens: Roch'e Compaan)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
167 address="1 2 3" (1 token: address=1 2 3)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
168 \\ (1 token: \)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
169 \n\r\t (1 token: a newline, carriage-return and tab)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
170
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
171 When multiple nodes are specified to the roundup get or roundup set
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
172 commands, the specified properties are retrieved or set on all the listed
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
173 nodes.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
174
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
175 When multiple results are returned by the roundup get or roundup find
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
176 commands, they are printed one per line (default) or joined by commas (with
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
177 the -c) option.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
178
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
179 Where the command changes data, a login name/password is required. The
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
180 login may be specified as either "name" or "name:password".
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
181 . ROUNDUP_LOGIN environment variable
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
182 . the -u command-line option
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
183 If either the name or password is not supplied, they are obtained from the
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
184 command-line.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
185
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
186 Date format examples:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
187 "2000-04-17.03:45" means <Date 2000-04-17.08:45:00>
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
188 "2000-04-17" means <Date 2000-04-17.00:00:00>
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
189 "01-25" means <Date yyyy-01-25.00:00:00>
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
190 "08-13.22:13" means <Date yyyy-08-14.03:13:00>
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
191 "11-07.09:32:43" means <Date yyyy-11-07.14:32:43>
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
192 "14:25" means <Date yyyy-mm-dd.19:25:00>
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
193 "8:47:11" means <Date yyyy-mm-dd.13:47:11>
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
194 "." means "right now"
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
195
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
196 Command help:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
197 ''')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
198 for name, command in self.commands.items():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
199 print _('%s:')%name
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
200 print _(' '), command.__doc__
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
201
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
202 def do_help(self, args, nl_re=re.compile('[\r\n]'),
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
203 indent_re=re.compile(r'^(\s+)\S+')):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
204 '''Usage: help topic
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
205 Give help about topic.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
206
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
207 commands -- list commands
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
208 <command> -- help specific to a command
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
209 initopts -- init command options
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
210 all -- all available help
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
211 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
212 if len(args)>0:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
213 topic = args[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
214 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
215 topic = 'help'
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
216
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
217
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
218 # try help_ methods
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
219 if self.help.has_key(topic):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
220 self.help[topic]()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
221 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
222
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
223 # try command docstrings
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
224 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
225 l = self.commands.get(topic)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
226 except KeyError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
227 print _('Sorry, no help for "%(topic)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
228 return 1
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
229
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
230 # display the help for each match, removing the docsring indent
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
231 for name, help in l:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
232 lines = nl_re.split(help.__doc__)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
233 print lines[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
234 indent = indent_re.match(lines[1])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
235 if indent: indent = len(indent.group(1))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
236 for line in lines[1:]:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
237 if indent:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
238 print line[indent:]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
239 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
240 print line
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
241 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
242
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
243 def help_initopts(self):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
244 import roundup.templates
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
245 templates = roundup.templates.listTemplates()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
246 print _('Templates:'), ', '.join(templates)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
247 import roundup.backends
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
248 backends = roundup.backends.__all__
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
249 print _('Back ends:'), ', '.join(backends)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
250
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
251
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
252 def do_initialise(self, instance_home, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
253 '''Usage: initialise [template [backend [admin password]]]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
254 Initialise a new Roundup instance.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
255
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
256 The command will prompt for the instance home directory (if not supplied
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
257 through INSTANCE_HOME or the -i option). The template, backend and admin
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
258 password may be specified on the command-line as arguments, in that
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
259 order.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
260
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
261 See also initopts help.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
262 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
263 if len(args) < 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
264 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
265 # select template
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
266 import roundup.templates
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
267 templates = roundup.templates.listTemplates()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
268 template = len(args) > 1 and args[1] or ''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
269 if template not in templates:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
270 print _('Templates:'), ', '.join(templates)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
271 while template not in templates:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
272 template = raw_input(_('Select template [classic]: ')).strip()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
273 if not template:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
274 template = 'classic'
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
275
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
276 import roundup.backends
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
277 backends = roundup.backends.__all__
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
278 backend = len(args) > 2 and args[2] or ''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
279 if backend not in backends:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
280 print _('Back ends:'), ', '.join(backends)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
281 while backend not in backends:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
282 backend = raw_input(_('Select backend [anydbm]: ')).strip()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
283 if not backend:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
284 backend = 'anydbm'
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
285 if len(args) > 3:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
286 adminpw = confirm = args[3]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
287 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
288 adminpw = ''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
289 confirm = 'x'
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
290 while adminpw != confirm:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
291 adminpw = getpass.getpass(_('Admin Password: '))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
292 confirm = getpass.getpass(_(' Confirm: '))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
293 init.init(instance_home, template, backend, adminpw)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
294 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
295
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
296
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
297 def do_get(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
298 '''Usage: get property designator[,designator]*
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
299 Get the given property of one or more designator(s).
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
300
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
301 Retrieves the property value of the nodes specified by the designators.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
302 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
303 if len(args) < 2:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
304 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
305 propname = args[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
306 designators = args[1].split(',')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
307 l = []
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
308 for designator in designators:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
309 # decode the node designator
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
310 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
311 classname, nodeid = roundupdb.splitDesignator(designator)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
312 except roundupdb.DesignatorError, message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
313 raise UsageError, message
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
314
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
315 # get the class
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
316 cl = self.get_class(classname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
317 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
318 if self.comma_sep:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
319 l.append(cl.get(nodeid, propname))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
320 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
321 print cl.get(nodeid, propname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
322 except IndexError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
323 raise UsageError, _('no such %(classname)s node "%(nodeid)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
324 except KeyError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
325 raise UsageError, _('no such %(classname)s property '
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
326 '"%(propname)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
327 if self.comma_sep:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
328 print ','.join(l)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
329 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
330
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
331
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
332 def do_set(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
333 '''Usage: set designator[,designator]* propname=value ...
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
334 Set the given property of one or more designator(s).
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
335
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
336 Sets the property to the value for all designators given.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
337 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
338 if len(args) < 2:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
339 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
340 from roundup import hyperdb
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
341
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
342 designators = args[0].split(',')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
343
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
344 # get the props from the args
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
345 props = self.props_from_args(args[1:])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
346
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
347 # now do the set for all the nodes
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
348 for designator in designators:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
349 # decode the node designator
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
350 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
351 classname, nodeid = roundupdb.splitDesignator(designator)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
352 except roundupdb.DesignatorError, message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
353 raise UsageError, message
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
354
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
355 # get the class
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
356 cl = self.get_class(classname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
357
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
358 properties = cl.getprops()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
359 for key, value in props.items():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
360 proptype = properties[key]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
361 if isinstance(proptype, hyperdb.String):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
362 continue
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
363 elif isinstance(proptype, hyperdb.Password):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
364 props[key] = password.Password(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
365 elif isinstance(proptype, hyperdb.Date):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
366 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
367 props[key] = date.Date(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
368 except ValueError, message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
369 raise UsageError, '"%s": %s'%(value, message)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
370 elif isinstance(proptype, hyperdb.Interval):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
371 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
372 props[key] = date.Interval(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
373 except ValueError, message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
374 raise UsageError, '"%s": %s'%(value, message)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
375 elif isinstance(proptype, hyperdb.Link):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
376 props[key] = value
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
377 elif isinstance(proptype, hyperdb.Multilink):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
378 props[key] = value.split(',')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
379
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
380 # try the set
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
381 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
382 apply(cl.set, (nodeid, ), props)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
383 except (TypeError, IndexError, ValueError), message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
384 raise UsageError, message
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
385 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
386
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
387 def do_find(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
388 '''Usage: find classname propname=value ...
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
389 Find the nodes of the given class with a given link property value.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
390
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
391 Find the nodes of the given class with a given link property value. The
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
392 value may be either the nodeid of the linked node, or its key value.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
393 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
394 if len(args) < 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
395 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
396 classname = args[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
397 # get the class
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
398 cl = self.get_class(classname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
399
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
400 # handle the propname=value argument
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
401 props = self.props_from_args(args[1:])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
402
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
403 # if the value isn't a number, look up the linked class to get the
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
404 # number
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
405 for propname, value in props.items():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
406 num_re = re.compile('^\d+$')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
407 if not num_re.match(value):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
408 # get the property
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
409 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
410 property = cl.properties[propname]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
411 except KeyError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
412 raise UsageError, _('%(classname)s has no property '
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
413 '"%(propname)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
414
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
415 # make sure it's a link
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
416 if (not isinstance(property, hyperdb.Link) and not
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
417 isinstance(property, hyperdb.Multilink)):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
418 raise UsageError, _('You may only "find" link properties')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
419
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
420 # get the linked-to class and look up the key property
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
421 link_class = self.db.getclass(property.classname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
422 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
423 props[propname] = link_class.lookup(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
424 except TypeError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
425 raise UsageError, _('%(classname)s has no key property"')%{
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
426 'classname': link_class.classname}
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
427 except KeyError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
428 raise UsageError, _('%(classname)s has no entry "%(propname)s"')%{
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
429 'classname': link_class.classname, 'propname': propname}
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
430
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
431 # now do the find
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
432 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
433 if self.comma_sep:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
434 print ','.join(apply(cl.find, (), props))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
435 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
436 print apply(cl.find, (), props)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
437 except KeyError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
438 raise UsageError, _('%(classname)s has no property '
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
439 '"%(propname)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
440 except (ValueError, TypeError), message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
441 raise UsageError, message
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
442 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
443
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
444 def do_specification(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
445 '''Usage: specification classname
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
446 Show the properties for a classname.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
447
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
448 This lists the properties for a given class.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
449 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
450 if len(args) < 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
451 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
452 classname = args[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
453 # get the class
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
454 cl = self.get_class(classname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
455
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
456 # get the key property
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
457 keyprop = cl.getkey()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
458 for key, value in cl.properties.items():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
459 if keyprop == key:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
460 print _('%(key)s: %(value)s (key property)')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
461 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
462 print _('%(key)s: %(value)s')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
463
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
464 def do_display(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
465 '''Usage: display designator
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
466 Show the property values for the given node.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
467
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
468 This lists the properties and their associated values for the given
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
469 node.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
470 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
471 if len(args) < 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
472 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
473
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
474 # decode the node designator
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
475 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
476 classname, nodeid = roundupdb.splitDesignator(args[0])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
477 except roundupdb.DesignatorError, message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
478 raise UsageError, message
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
479
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
480 # get the class
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
481 cl = self.get_class(classname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
482
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
483 # display the values
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
484 for key in cl.properties.keys():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
485 value = cl.get(nodeid, key)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
486 print _('%(key)s: %(value)s')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
487
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
488 def do_create(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
489 '''Usage: create classname property=value ...
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
490 Create a new entry of a given class.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
491
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
492 This creates a new entry of the given class using the property
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
493 name=value arguments provided on the command line after the "create"
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
494 command.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
495 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
496 if len(args) < 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
497 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
498 from roundup import hyperdb
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
499
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
500 classname = args[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
501
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
502 # get the class
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
503 cl = self.get_class(classname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
504
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
505 # now do a create
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
506 props = {}
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
507 properties = cl.getprops(protected = 0)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
508 if len(args) == 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
509 # ask for the properties
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
510 for key, value in properties.items():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
511 if key == 'id': continue
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
512 name = value.__class__.__name__
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
513 if isinstance(value , hyperdb.Password):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
514 again = None
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
515 while value != again:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
516 value = getpass.getpass(_('%(propname)s (Password): ')%{
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
517 'propname': key.capitalize()})
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
518 again = getpass.getpass(_(' %(propname)s (Again): ')%{
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
519 'propname': key.capitalize()})
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
520 if value != again: print _('Sorry, try again...')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
521 if value:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
522 props[key] = value
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
523 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
524 value = raw_input(_('%(propname)s (%(proptype)s): ')%{
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
525 'propname': key.capitalize(), 'proptype': name})
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
526 if value:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
527 props[key] = value
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
528 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
529 props = self.props_from_args(args[1:])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
530
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
531 # convert types
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
532 for propname in props.keys():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
533 # get the property
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
534 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
535 proptype = properties[propname]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
536 except KeyError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
537 raise UsageError, _('%(classname)s has no property '
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
538 '"%(propname)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
539
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
540 if isinstance(proptype, hyperdb.Date):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
541 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
542 props[propname] = date.Date(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
543 except ValueError, message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
544 raise UsageError, _('"%(value)s": %(message)s')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
545 elif isinstance(proptype, hyperdb.Interval):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
546 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
547 props[propname] = date.Interval(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
548 except ValueError, message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
549 raise UsageError, _('"%(value)s": %(message)s')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
550 elif isinstance(proptype, hyperdb.Password):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
551 props[propname] = password.Password(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
552 elif isinstance(proptype, hyperdb.Multilink):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
553 props[propname] = value.split(',')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
554
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
555 # check for the key property
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
556 propname = cl.getkey()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
557 if propname and not props.has_key(propname):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
558 raise UsageError, _('you must provide the "%(propname)s" '
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
559 'property.')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
560
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
561 # do the actual create
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
562 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
563 print apply(cl.create, (), props)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
564 except (TypeError, IndexError, ValueError), message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
565 raise UsageError, message
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
566 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
567
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
568 def do_list(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
569 '''Usage: list classname [property]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
570 List the instances of a class.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
571
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
572 Lists all instances of the given class. If the property is not
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
573 specified, the "label" property is used. The label property is tried
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
574 in order: the key, "name", "title" and then the first property,
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
575 alphabetically.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
576 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
577 if len(args) < 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
578 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
579 classname = args[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
580
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
581 # get the class
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
582 cl = self.get_class(classname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
583
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
584 # figure the property
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
585 if len(args) > 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
586 propname = args[1]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
587 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
588 propname = cl.labelprop()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
589
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
590 if self.comma_sep:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
591 print ','.join(cl.list())
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
592 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
593 for nodeid in cl.list():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
594 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
595 value = cl.get(nodeid, propname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
596 except KeyError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
597 raise UsageError, _('%(classname)s has no property '
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
598 '"%(propname)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
599 print _('%(nodeid)4s: %(value)s')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
600 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
601
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
602 def do_table(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
603 '''Usage: table classname [property[,property]*]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
604 List the instances of a class in tabular form.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
605
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
606 Lists all instances of the given class. If the properties are not
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
607 specified, all properties are displayed. By default, the column widths
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
608 are the width of the property names. The width may be explicitly defined
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
609 by defining the property as "name:width". For example::
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
610 roundup> table priority id,name:10
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
611 Id Name
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
612 1 fatal-bug
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
613 2 bug
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
614 3 usability
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
615 4 feature
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
616 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
617 if len(args) < 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
618 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
619 classname = args[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
620
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
621 # get the class
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
622 cl = self.get_class(classname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
623
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
624 # figure the property names to display
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
625 if len(args) > 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
626 prop_names = args[1].split(',')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
627 all_props = cl.getprops()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
628 for spec in prop_names:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
629 if ':' in spec:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
630 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
631 propname, width = spec.split(':')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
632 except (ValueError, TypeError):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
633 raise UsageError, _('"%(spec)s" not name:width')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
634 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
635 propname = spec
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
636 if not all_props.has_key(propname):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
637 raise UsageError, _('%(classname)s has no property '
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
638 '"%(propname)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
639 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
640 prop_names = cl.getprops().keys()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
641
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
642 # now figure column widths
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
643 props = []
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
644 for spec in prop_names:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
645 if ':' in spec:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
646 name, width = spec.split(':')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
647 props.append((name, int(width)))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
648 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
649 props.append((spec, len(spec)))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
650
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
651 # now display the heading
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
652 print ' '.join([name.capitalize().ljust(width) for name,width in props])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
653
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
654 # and the table data
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
655 for nodeid in cl.list():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
656 l = []
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
657 for name, width in props:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
658 if name != 'id':
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
659 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
660 value = str(cl.get(nodeid, name))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
661 except KeyError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
662 # we already checked if the property is valid - a
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
663 # KeyError here means the node just doesn't have a
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
664 # value for it
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
665 value = ''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
666 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
667 value = str(nodeid)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
668 f = '%%-%ds'%width
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
669 l.append(f%value[:width])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
670 print ' '.join(l)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
671 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
672
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
673 def do_history(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
674 '''Usage: history designator
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
675 Show the history entries of a designator.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
676
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
677 Lists the journal entries for the node identified by the designator.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
678 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
679 if len(args) < 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
680 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
681 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
682 classname, nodeid = roundupdb.splitDesignator(args[0])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
683 except roundupdb.DesignatorError, message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
684 raise UsageError, message
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
685
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
686 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
687 print self.db.getclass(classname).history(nodeid)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
688 except KeyError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
689 raise UsageError, _('no such class "%(classname)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
690 except IndexError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
691 raise UsageError, _('no such %(classname)s node "%(nodeid)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
692 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
693
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
694 def do_commit(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
695 '''Usage: commit
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
696 Commit all changes made to the database.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
697
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
698 The changes made during an interactive session are not
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
699 automatically written to the database - they must be committed
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
700 using this command.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
701
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
702 One-off commands on the command-line are automatically committed if
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
703 they are successful.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
704 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
705 self.db.commit()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
706 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
707
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
708 def do_rollback(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
709 '''Usage: rollback
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
710 Undo all changes that are pending commit to the database.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
711
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
712 The changes made during an interactive session are not
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
713 automatically written to the database - they must be committed
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
714 manually. This command undoes all those changes, so a commit
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
715 immediately after would make no changes to the database.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
716 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
717 self.db.rollback()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
718 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
719
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
720 def do_retire(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
721 '''Usage: retire designator[,designator]*
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
722 Retire the node specified by designator.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
723
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
724 This action indicates that a particular node is not to be retrieved by
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
725 the list or find commands, and its key value may be re-used.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
726 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
727 if len(args) < 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
728 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
729 designators = args[0].split(',')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
730 for designator in designators:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
731 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
732 classname, nodeid = roundupdb.splitDesignator(designator)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
733 except roundupdb.DesignatorError, message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
734 raise UsageError, message
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
735 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
736 self.db.getclass(classname).retire(nodeid)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
737 except KeyError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
738 raise UsageError, _('no such class "%(classname)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
739 except IndexError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
740 raise UsageError, _('no such %(classname)s node "%(nodeid)s"')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
741 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
742
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
743 def do_export(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
744 '''Usage: export class[,class] destination_dir
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
745 Export the database to tab-separated-value files.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
746
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
747 This action exports the current data from the database into
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
748 tab-separated-value files that are placed in the nominated destination
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
749 directory. The journals are not exported.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
750 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
751 if len(args) < 2:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
752 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
753 classes = args[0].split(',')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
754 dir = args[1]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
755
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
756 # use the csv parser if we can - it's faster
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
757 if csv is not None:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
758 p = csv.parser(field_sep=':')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
759
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
760 # do all the classes specified
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
761 for classname in classes:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
762 cl = self.get_class(classname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
763 f = open(os.path.join(dir, classname+'.csv'), 'w')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
764 f.write(':'.join(cl.properties.keys()) + '\n')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
765
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
766 # all nodes for this class
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
767 properties = cl.properties.items()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
768 for nodeid in cl.list():
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
769 l = []
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
770 for prop, proptype in properties:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
771 value = cl.get(nodeid, prop)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
772 # convert data where needed
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
773 if isinstance(proptype, hyperdb.Date):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
774 value = value.get_tuple()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
775 elif isinstance(proptype, hyperdb.Interval):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
776 value = value.get_tuple()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
777 elif isinstance(proptype, hyperdb.Password):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
778 value = str(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
779 l.append(repr(value))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
780
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
781 # now write
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
782 if csv is not None:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
783 f.write(p.join(l) + '\n')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
784 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
785 # escape the individual entries to they're valid CSV
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
786 m = []
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
787 for entry in l:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
788 if '"' in entry:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
789 entry = '""'.join(entry.split('"'))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
790 if ':' in entry:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
791 entry = '"%s"'%entry
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
792 m.append(entry)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
793 f.write(':'.join(m) + '\n')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
794 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
795
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
796 def do_import(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
797 '''Usage: import class file
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
798 Import the contents of the tab-separated-value file.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
799
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
800 The file must define the same properties as the class (including having
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
801 a "header" line with those property names.) The new nodes are added to
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
802 the existing database - if you want to create a new database using the
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
803 imported data, then create a new database (or, tediously, retire all
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
804 the old data.)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
805 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
806 if len(args) < 2:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
807 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
808 if csv is None:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
809 raise UsageError, \
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
810 _('Sorry, you need the csv module to use this function.\n'
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
811 'Get it from: http://www.object-craft.com.au/projects/csv/')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
812
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
813 from roundup import hyperdb
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
814
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
815 # ensure that the properties and the CSV file headings match
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
816 classname = args[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
817 cl = self.get_class(classname)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
818 f = open(args[1])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
819 p = csv.parser(field_sep=':')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
820 file_props = p.parse(f.readline())
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
821 props = cl.properties.keys()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
822 m = file_props[:]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
823 m.sort()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
824 props.sort()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
825 if m != props:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
826 raise UsageError, _('Import file doesn\'t define the same '
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
827 'properties as "%(arg0)s".')%{'arg0': args[0]}
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
828
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
829 # loop through the file and create a node for each entry
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
830 n = range(len(props))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
831 while 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
832 line = f.readline()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
833 if not line: break
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
834
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
835 # parse lines until we get a complete entry
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
836 while 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
837 l = p.parse(line)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
838 if l: break
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
839
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
840 # make the new node's property map
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
841 d = {}
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
842 for i in n:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
843 # Use eval to reverse the repr() used to output the CSV
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
844 value = eval(l[i])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
845 # Figure the property for this column
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
846 key = file_props[i]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
847 proptype = cl.properties[key]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
848 # Convert for property type
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
849 if isinstance(proptype, hyperdb.Date):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
850 value = date.Date(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
851 elif isinstance(proptype, hyperdb.Interval):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
852 value = date.Interval(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
853 elif isinstance(proptype, hyperdb.Password):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
854 pwd = password.Password()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
855 pwd.unpack(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
856 value = pwd
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
857 if value is not None:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
858 d[key] = value
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
859
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
860 # and create the new node
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
861 apply(cl.create, (), d)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
862 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
863
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
864 def do_pack(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
865 '''Usage: pack period | date
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
866
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
867 Remove journal entries older than a period of time specified or
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
868 before a certain date.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
869
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
870 A period is specified using the suffixes "y", "m", and "d". The
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
871 suffix "w" (for "week") means 7 days.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
872
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
873 "3y" means three years
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
874 "2y 1m" means two years and one month
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
875 "1m 25d" means one month and 25 days
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
876 "2w 3d" means two weeks and three days
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
877
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
878 Date format is "YYYY-MM-DD" eg:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
879 2001-01-01
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
880
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
881 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
882 if len(args) <> 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
883 raise UsageError, _('Not enough arguments supplied')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
884
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
885 # are we dealing with a period or a date
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
886 value = args[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
887 date_re = re.compile(r'''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
888 (?P<date>\d\d\d\d-\d\d?-\d\d?)? # yyyy-mm-dd
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
889 (?P<period>(\d+y\s*)?(\d+m\s*)?(\d+d\s*)?)?
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
890 ''', re.VERBOSE)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
891 m = date_re.match(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
892 if not m:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
893 raise ValueError, _('Invalid format')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
894 m = m.groupdict()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
895 if m['period']:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
896 # TODO: need to fix date module. one should be able to say
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
897 # pack_before = date.Date(". - %s"%value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
898 pack_before = date.Date(".") + date.Interval("- %s"%value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
899 elif m['date']:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
900 pack_before = date.Date(value)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
901 self.db.pack(pack_before)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
902 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
903
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
904 def run_command(self, args):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
905 '''Run a single command
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
906 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
907 command = args[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
908
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
909 # handle help now
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
910 if command == 'help':
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
911 if len(args)>1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
912 self.do_help(args[1:])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
913 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
914 self.do_help(['help'])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
915 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
916 if command == 'morehelp':
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
917 self.do_help(['help'])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
918 self.help_commands()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
919 self.help_all()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
920 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
921
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
922 # figure what the command is
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
923 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
924 functions = self.commands.get(command)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
925 except KeyError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
926 # not a valid command
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
927 print _('Unknown command "%(command)s" ("help commands" for a '
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
928 'list)')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
929 return 1
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
930
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
931 # check for multiple matches
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
932 if len(functions) > 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
933 print _('Multiple commands match "%(command)s": %(list)s')%{'command':
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
934 command, 'list': ', '.join([i[0] for i in functions])}
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
935 return 1
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
936 command, function = functions[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
937
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
938 # make sure we have an instance_home
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
939 while not self.instance_home:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
940 self.instance_home = raw_input(_('Enter instance home: ')).strip()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
941
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
942 # before we open the db, we may be doing an init
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
943 if command == 'initialise':
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
944 return self.do_initialise(self.instance_home, args)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
945
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
946 # get the instance
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
947 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
948 instance = roundup.instance.open(self.instance_home)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
949 except ValueError, message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
950 self.instance_home = ''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
951 print _("Couldn't open instance: %(message)s")%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
952 return 1
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
953
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
954 # only open the database once!
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
955 if not self.db:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
956 self.db = instance.open('admin')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
957
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
958 # do the command
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
959 ret = 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
960 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
961 ret = function(args[1:])
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
962 except UsageError, message:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
963 print _('Error: %(message)s')%locals()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
964 print function.__doc__
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
965 ret = 1
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
966 except:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
967 import traceback
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
968 traceback.print_exc()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
969 ret = 1
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
970 return ret
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
971
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
972 def interactive(self):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
973 '''Run in an interactive mode
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
974 '''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
975 print _('Roundup {version} ready for input.')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
976 print _('Type "help" for help.')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
977 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
978 import readline
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
979 except ImportError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
980 print _('Note: command history and editing not available')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
981
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
982 while 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
983 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
984 command = raw_input(_('roundup> '))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
985 except EOFError:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
986 print _('exit...')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
987 break
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
988 if not command: continue
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
989 args = token.token_split(command)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
990 if not args: continue
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
991 if args[0] in ('quit', 'exit'): break
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
992 self.run_command(args)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
993
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
994 # exit.. check for transactions
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
995 if self.db and self.db.transactions:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
996 commit = raw_input(_('There are unsaved changes. Commit them (y/N)? '))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
997 if commit and commit[0].lower() == 'y':
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
998 self.db.commit()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
999 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1000
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1001 def main(self):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1002 try:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1003 opts, args = getopt.getopt(sys.argv[1:], 'i:u:hc')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1004 except getopt.GetoptError, e:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1005 self.usage(str(e))
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1006 return 1
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1007
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1008 # handle command-line args
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1009 self.instance_home = os.environ.get('ROUNDUP_INSTANCE', '')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1010 name = password = ''
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1011 if os.environ.has_key('ROUNDUP_LOGIN'):
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1012 l = os.environ['ROUNDUP_LOGIN'].split(':')
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1013 name = l[0]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1014 if len(l) > 1:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1015 password = l[1]
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1016 self.comma_sep = 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1017 for opt, arg in opts:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1018 if opt == '-h':
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1019 self.usage()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1020 return 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1021 if opt == '-i':
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1022 self.instance_home = arg
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1023 if opt == '-c':
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1024 self.comma_sep = 1
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1025
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1026 # if no command - go interactive
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1027 ret = 0
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1028 if not args:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1029 self.interactive()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1030 else:
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1031 ret = self.run_command(args)
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1032 if self.db: self.db.commit()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1033 return ret
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1034
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1035
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1036 if __name__ == '__main__':
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1037 tool = AdminTool()
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1038 sys.exit(tool.main())
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1039
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1040 #
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1041 # $Log: not supported by cvs2svn $
602
c242455d9b46 Brought the config branch up to date with HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 601
diff changeset
1042 # Revision 1.6 2002/01/23 07:27:19 grubert
c242455d9b46 Brought the config branch up to date with HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 601
diff changeset
1043 # . allow abbreviation of "help" in admin tool too.
c242455d9b46 Brought the config branch up to date with HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 601
diff changeset
1044 #
601
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1045 # Revision 1.5 2002/01/21 16:33:19 rochecompaan
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1046 # You can now use the roundup-admin tool to pack the database
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1047 #
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1048 # Revision 1.4 2002/01/14 06:51:09 richard
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1049 # . #503164 ] create and passwords
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1050 #
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1051 # Revision 1.3 2002/01/08 05:26:32 rochecompaan
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1052 # Missing "self" in props_from_args
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1053 #
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1054 # Revision 1.2 2002/01/07 10:41:44 richard
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1055 # #500140 ] AdminTool.get_class() returns nothing
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1056 #
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1057 # Revision 1.1 2002/01/05 02:11:22 richard
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1058 # I18N'ed roundup admin - and split the code off into a module so it can be used
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1059 # elsewhere.
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1060 # Big issue with this is the doc strings - that's the help. We're probably going to
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1061 # have to switch to not use docstrings, which will suck a little :(
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1062 #
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1063 #
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1064 #
912029653c1c [[Metadata associated with this commit was garbled during conversion from CVS
No Author <no-author@users.sourceforge.net>
parents:
diff changeset
1065 # vim: set filetype=python ts=4 sw=4 et si

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