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