annotate roundup/admin.py @ 7252:9c067ed4568b

add pragma command to roundup-admin Added basic pragma command. Can assign settings, list settings. Most settings are not yet implemented. Only the pragma command respects unhidden pragma settings at this point. Also added tests, doc updates for roundup-admin. CHANGES.txt not updated because currently only pragma references the unhidden settings. Also fixed a couple of long lines.
author John Rouillard <rouilj@ieee.org>
date Wed, 12 Apr 2023 20:49:21 -0400
parents ee972b3073cb
children 393ae88bf7b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1 #! /usr/bin/env python
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2 #
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
3 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
4 # This module is free software, and you may redistribute it and/or modify
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
5 # under the same terms as Python, so long as this copyright message and
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
6 # disclaimer are retained in their original form.
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
7 #
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
8 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
9 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
b35f229dd049 I18N'ed roundup admin...
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
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
11 # POSSIBILITY OF SUCH DAMAGE.
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
12 #
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
13 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
2307
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
18 #
1244
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1230
diff changeset
19
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
20 """Administration commands for maintaining Roundup trackers.
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
21 """
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
22 from __future__ import print_function
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
23
2005
fc52d57c6c3e documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents: 1916
diff changeset
24 __docformat__ = 'restructuredtext'
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
25
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
26 import csv
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
27 import getopt
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
28 import getpass
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
29 import operator
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
30 import os
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
31 import re
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
32 import shutil
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
33 import sys
3197
6d0b5937ee0d fix: module csv is in standard library, not in roundup package;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3179
diff changeset
34
7178
db06d4aeb978 unshadow stdlib token from roundup's token.
John Rouillard <rouilj@ieee.org>
parents: 7093
diff changeset
35 from roundup import date, hyperdb, init, password, token_r
773
6e6c63a57df9 [SF#569415] {version]]
Richard Jones <richard@users.sourceforge.net>
parents: 763
diff changeset
36 from roundup import __version__ as roundup_version
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
37 import roundup.instance
7076
d3d20e145cea bug: cleaner error message on OptionUnsetError in initialize
John Rouillard <rouilj@ieee.org>
parents: 6959
diff changeset
38 from roundup.configuration import (CoreConfig, NoConfigError, OptionUnsetError,
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6527
diff changeset
39 ParsingOptionError, UserConfig)
6658
408fd477761f Add i18n object to roundupdb.Database
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6585
diff changeset
40 from roundup.i18n import _, get_translation
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
41 from roundup.exceptions import UsageError
5401
4cf48ff01e04 Python 3 preparation: replace raw_input uses.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5250
diff changeset
42 from roundup.anypy.my_input import my_input
5525
bb7865241f8a Make CSV import/export compatible across Python versions (also RDBMS journals) (issue 2550976, issue 2550975).
Joseph Myers <jsm@polyomino.org.uk>
parents: 5459
diff changeset
43 from roundup.anypy.strings import repr_export
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
44
5455
118f5ffd194e import UserDict from collections or UserDict
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5414
diff changeset
45 try:
118f5ffd194e import UserDict from collections or UserDict
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5414
diff changeset
46 from UserDict import UserDict
118f5ffd194e import UserDict from collections or UserDict
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5414
diff changeset
47 except ImportError:
118f5ffd194e import UserDict from collections or UserDict
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5414
diff changeset
48 from collections import UserDict
118f5ffd194e import UserDict from collections or UserDict
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5414
diff changeset
49
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
50
5455
118f5ffd194e import UserDict from collections or UserDict
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5414
diff changeset
51 class CommandDict(UserDict):
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
52 """Simple dictionary that lets us do lookups using partial keys.
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
53
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
54 Original code submitted by Engelbert Gruber.
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
55 """
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
56 _marker = []
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
57
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
58 def get(self, key, default=_marker):
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
59 if key in self.data:
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
60 return [(key, self.data[key])]
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
61 keylist = sorted(self.data)
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
62 matching_keys = []
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
63 for ki in keylist:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
64 if ki.startswith(key):
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
65 matching_keys.append((ki, self.data[ki]))
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
66 if not matching_keys and default is self._marker:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
67 raise KeyError(key)
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
68 # FIXME: what happens if default is not self._marker but
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
69 # there are no matching keys? Should (default, self.data[default])
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
70 # be returned???
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
71 return matching_keys
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
72
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
73
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
74 class AdminTool:
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
75 """ A collection of methods used in maintaining Roundup trackers.
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
76
1244
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1230
diff changeset
77 Typically these methods are accessed through the roundup-admin
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1230
diff changeset
78 script. The main() method provided on this class gives the main
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1230
diff changeset
79 loop for the roundup-admin script.
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1230
diff changeset
80
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1230
diff changeset
81 Actions are defined by do_*() methods, with help for the action
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1230
diff changeset
82 given in the method docstring.
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1230
diff changeset
83
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1230
diff changeset
84 Additional help may be supplied by help_*() methods.
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
85 """
7182
0c6617db0b97 Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents: 7178
diff changeset
86
0c6617db0b97 Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents: 7178
diff changeset
87 # Make my_input a property to allow overriding in testing.
0c6617db0b97 Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents: 7178
diff changeset
88 # my_input is imported in other places, so just set it from
0c6617db0b97 Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents: 7178
diff changeset
89 # the imported value rather than moving def here.
0c6617db0b97 Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents: 7178
diff changeset
90 my_input = my_input
0c6617db0b97 Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents: 7178
diff changeset
91
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
92 def __init__(self):
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
93 self.commands = CommandDict()
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
94 for k in AdminTool.__dict__:
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
95 if k[:3] == 'do_':
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
96 self.commands[k[3:]] = getattr(self, k)
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
97 self.help = {}
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
98 for k in AdminTool.__dict__:
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
99 if k[:5] == 'help_':
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
100 self.help[k[5:]] = getattr(self, k)
1098
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
101 self.tracker_home = ''
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
102 self.db = None
3889
f7766d5ba962 fix [SF#297014]: roundup-admin interactive tracks uncommitted state
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3803
diff changeset
103 self.db_uncommitted = False
5163
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
104 self.force = None
7252
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
105 self.settings = {
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
106 'display_protected': False,
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
107 'indexer_backend': "as set in config.ini",
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
108 '_reopen_tracker': False,
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
109 'show_retired': False,
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
110 'verbose': False,
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
111 '_inttest': 3,
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
112 '_floattest': 3.5,
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
113 }
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
114 self.settings_help = {
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
115 'display_protected':
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
116 _("Have 'display designator' show protected fields: creator. NYI"),
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
117
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
118 'indexer_backend':
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
119 _("Set indexer to use when running 'reindex' NYI"),
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
120
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
121 '_reopen_tracker':
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
122 _("Force reopening of tracker when running each command."),
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
123
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
124 'show_retired': _("Show retired items in table, list etc. NYI"),
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
125 'verbose': _("Enable verbose output: tracing, descriptions..."),
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
126
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
127 '_inttest': "Integer valued setting. For testing only.",
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
128 '_floattest': "Float valued setting. For testing only.",
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
129 }
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
130
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
131 def get_class(self, classname):
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
132 """Get the class - raise an exception if it doesn't exist.
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
133 """
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
134 try:
489
5db2dad23f09 [SF#500140] AdminTool.get_class() returns nothing
Richard Jones <richard@users.sourceforge.net>
parents: 484
diff changeset
135 return self.db.getclass(classname)
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
136 except KeyError:
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
137 raise UsageError(_('no such class "%(classname)s"') % locals())
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
138
649
29f7e41ee437 Ran it through pychecker, made fixes
Richard Jones <richard@users.sourceforge.net>
parents: 626
diff changeset
139 def props_from_args(self, args):
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
140 """ Produce a dictionary of prop: value from the args list.
1244
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1230
diff changeset
141
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1230
diff changeset
142 The args list is specified as ``prop=value prop=value ...``.
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
143 """
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
144 props = {}
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
145 for arg in args:
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
146 key_val = arg.split('=', 1)
6187
cc66cf905147 Removed redundant code; fix help text for do_security
John Rouillard <rouilj@ieee.org>
parents: 6180
diff changeset
147 # if = not in string, will return one element
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
148 if len(key_val) < 2:
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
149 raise UsageError(_('argument "%(arg)s" not propname=value') %
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
150 locals())
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
151 key, value = key_val
1108
b0de30171e57 implemented set for all items in a class, and unset
Richard Jones <richard@users.sourceforge.net>
parents: 1103
diff changeset
152 if value:
b0de30171e57 implemented set for all items in a class, and unset
Richard Jones <richard@users.sourceforge.net>
parents: 1103
diff changeset
153 props[key] = value
b0de30171e57 implemented set for all items in a class, and unset
Richard Jones <richard@users.sourceforge.net>
parents: 1103
diff changeset
154 else:
b0de30171e57 implemented set for all items in a class, and unset
Richard Jones <richard@users.sourceforge.net>
parents: 1103
diff changeset
155 props[key] = None
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
156 return props
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
157
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
158 def usage(self, message=''):
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
159 """ Display a simple usage message.
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
160 """
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
161 if message:
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
162 message = _('Problem: %(message)s\n\n') % locals()
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
163 sys.stdout.write(_("""%(message)sUsage: roundup-admin [options] [<command> <arguments>]
1098
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
164
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
165 Options:
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
166 -i instance home -- specify the issue tracker "home directory" to administer
5979
33a7b10618a6 Add support for -u to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 5897
diff changeset
167 -u -- the user[:password] to use for commands (default admin)
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
168 -d -- print full designators not just class id numbers
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
169 -c -- when outputting lists of data, comma-separate them.
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
170 Same as '-S ","'.
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
171 -S <string> -- when outputting lists of data, string-separate them
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
172 -s -- when outputting lists of data, space-separate them.
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
173 Same as '-S " "'.
3602
064515f658e8 verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
174 -V -- be verbose when importing
064515f658e8 verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
175 -v -- report Roundup and Python versions (and quit)
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
176
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
177 Only one of -s, -c or -S can be specified.
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
178
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
179 Help:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
180 roundup-admin -h
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
181 roundup-admin help -- this help
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
182 roundup-admin help <command> -- command-specific help
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
183 roundup-admin help all -- all available help
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
184 """) % locals())
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
185 self.help_commands()
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
186
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
187 def help_commands(self):
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
188 """List the commands available with their help summary.
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
189 """
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
190 sys.stdout.write(_('Commands: '))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
191 commands = ['']
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
192 for command in self.commands.values():
2307
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
193 h = _(command.__doc__).split('\n')[0]
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
194 commands.append(' '+h[7:])
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
195 commands.sort()
2307
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
196 commands.append(_(
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
197 """Commands may be abbreviated as long as the abbreviation
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
198 matches only one command, e.g. l == li == lis == list.""")) # noqa: E122
5110
87b0358790ed Adding some tests for admin.py. Specifically for issue2550572: setting
John Rouillard <rouilj@ieee.org>
parents: 5104
diff changeset
199 sys.stdout.write('\n'.join(commands) + '\n\n')
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
200
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
201 indent_re = re.compile(r'^(\s+)\S+')
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
202
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
203 def help_commands_html(self, indent_re=indent_re):
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
204 """ Produce an HTML command list.
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
205 """
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
206 commands = sorted(iter(self.commands.values()),
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
207 key=operator.attrgetter('__name__'))
1244
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1230
diff changeset
208 for command in commands:
2307
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
209 h = _(command.__doc__).split('\n')
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
210 name = command.__name__[3:]
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
211 usage = h[0]
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
212 print("""
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
213 <tr><td valign=top><strong>%(name)s</strong></td>
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
214 <td><tt>%(usage)s</tt><p>
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
215 <pre>""" % locals())
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
216 indent = indent_re.match(h[3])
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
217 if indent: indent = len(indent.group(1)) # noqa: E701
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
218 for line in h[3:]:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
219 if indent:
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
220 print(line[indent:])
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
221 else:
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
222 print(line)
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
223 print('</pre></td></tr>\n')
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
224
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
225 def help_all(self):
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
226 print(_("""
2329
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
227 All commands (except help) require a tracker specifier. This is just
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
228 the path to the roundup tracker you're working with. A roundup tracker
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
229 is where roundup keeps the database and configuration file that defines
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
230 an issue tracker. It may be thought of as the issue tracker's "home
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
231 directory". It may be specified in the environment variable TRACKER_HOME
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
232 or on the command line as "-i tracker".
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
233
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
234 A designator is a classname and a nodeid concatenated, eg. bug1, user10, ...
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
235
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
236 Property values are represented as strings in command arguments and in the
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
237 printed results:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
238 . Strings are, well, strings.
2329
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
239 . Date values are printed in the full date format in the local time zone,
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
240 and accepted in the full format or any of the partial formats explained
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
241 below.
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
242 . Link values are printed as node designators. When given as an argument,
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
243 node designators and key strings are both accepted.
2329
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
244 . Multilink values are printed as lists of node designators joined
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
245 by commas. When given as an argument, node designators and key
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
246 strings are both accepted; an empty string, a single node, or a list
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
247 of nodes joined by commas is accepted.
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
248
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
249 When property values must contain spaces, just surround the value with
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
250 quotes, either ' or ". A single space may also be backslash-quoted. If a
2329
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
251 value must contain a quote character, it must be backslash-quoted or inside
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
252 quotes. Examples:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
253 hello world (2 tokens: hello, world)
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
254 "hello world" (1 token: hello world)
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
255 "Roch'e" Compaan (2 tokens: Roch'e Compaan)
2329
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
256 Roch\\'e Compaan (2 tokens: Roch'e Compaan)
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
257 address="1 2 3" (1 token: address=1 2 3)
2329
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
258 \\\\ (1 token: \\)
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
259 \\n\\r\\t (1 token: a newline, carriage-return and tab)
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
260
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
261 When multiple nodes are specified to the roundup get or roundup set
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
262 commands, the specified properties are retrieved or set on all the listed
2307
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
263 nodes.
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
264
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
265 When multiple results are returned by the roundup get or roundup find
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
266 commands, they are printed one per line (default) or joined by commas (with
2307
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
267 the -c) option.
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
268
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
269 Where the command changes data, a login name/password is required. The
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
270 login may be specified as either "name" or "name:password".
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
271 . ROUNDUP_LOGIN environment variable
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
272 . the -u command-line option
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
273 If either the name or password is not supplied, they are obtained from the
7093
f72ce883e677 Mitigation for issue2551246 -u opton to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7078
diff changeset
274 command-line. (See admin guide before using -u.)
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
275
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
276 Date format examples:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
277 "2000-04-17.03:45" means <Date 2000-04-17.08:45:00>
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
278 "2000-04-17" means <Date 2000-04-17.00:00:00>
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
279 "01-25" means <Date yyyy-01-25.00:00:00>
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
280 "08-13.22:13" means <Date yyyy-08-14.03:13:00>
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
281 "11-07.09:32:43" means <Date yyyy-11-07.14:32:43>
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
282 "14:25" means <Date yyyy-mm-dd.19:25:00>
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
283 "8:47:11" means <Date yyyy-mm-dd.13:47:11>
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
284 "." means "right now"
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
285
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
286 Command help:
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
287 """))
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
288 for name, command in list(self.commands.items()):
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
289 print(_('%s:') % name)
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
290 print(' ', _(command.__doc__))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
291
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
292 nl_re = re.compile('[\r\n]')
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
293 # indent_re defined above
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
294
6957
f924af12ef50 issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents: 6818
diff changeset
295 def listTemplates(self, trace_search=False):
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
296 """ List all the available templates.
1591
21312a7564fd moving templates around
Richard Jones <richard@users.sourceforge.net>
parents: 1570
diff changeset
297
1863
d2ad3309c415 Clarify listTemplates docstring...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1775
diff changeset
298 Look in the following places, where the later rules take precedence:
d2ad3309c415 Clarify listTemplates docstring...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1775
diff changeset
299
3894
44f2158fe76e Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3889
diff changeset
300 1. <roundup.admin.__file__>/../../share/roundup/templates/*
44f2158fe76e Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3889
diff changeset
301 this is where they will be if we installed an egg via easy_install
6739
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
302 or we are in the source tree.
3894
44f2158fe76e Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3889
diff changeset
303 2. <prefix>/share/roundup/templates/*
1863
d2ad3309c415 Clarify listTemplates docstring...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1775
diff changeset
304 this should be the standard place to find them when Roundup is
6739
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
305 installed using setup.py without a prefix
6527
5ad7fb912227 issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents: 6524
diff changeset
306 3. <roundup.admin.__file__>/../../<sys.prefix>/share/\
5ad7fb912227 issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents: 6524
diff changeset
307 roundup/templates/* which is where they will be found if
5ad7fb912227 issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents: 6524
diff changeset
308 roundup is installed as a wheel using pip install
6739
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
309 4. <current working dir>/*
1863
d2ad3309c415 Clarify listTemplates docstring...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1775
diff changeset
310 this is for when someone unpacks a 3rd-party template
6739
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
311 5. <current working dir>
1863
d2ad3309c415 Clarify listTemplates docstring...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1775
diff changeset
312 this is for someone who "cd"s to the 3rd-party template dir
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
313 """
1591
21312a7564fd moving templates around
Richard Jones <richard@users.sourceforge.net>
parents: 1570
diff changeset
314 # OK, try <prefix>/share/roundup/templates
3894
44f2158fe76e Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3889
diff changeset
315 # and <egg-directory>/share/roundup/templates
1591
21312a7564fd moving templates around
Richard Jones <richard@users.sourceforge.net>
parents: 1570
diff changeset
316 # -- this module (roundup.admin) will be installed in something
1652
7fb3bf18babb attempt to fix the template finding
Richard Jones <richard@users.sourceforge.net>
parents: 1634
diff changeset
317 # like:
3894
44f2158fe76e Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3889
diff changeset
318 # /usr/lib/python2.5/site-packages/roundup/admin.py (5 dirs up)
44f2158fe76e Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3889
diff changeset
319 # c:\python25\lib\site-packages\roundup\admin.py (4 dirs up)
44f2158fe76e Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3889
diff changeset
320 # /usr/lib/python2.5/site-packages/roundup-1.3.3-py2.5-egg/roundup/admin.py
44f2158fe76e Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3889
diff changeset
321 # (2 dirs up)
44f2158fe76e Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3889
diff changeset
322 #
44f2158fe76e Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3889
diff changeset
323 # we're interested in where the directory containing "share" is
6739
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
324 debug = False
1652
7fb3bf18babb attempt to fix the template finding
Richard Jones <richard@users.sourceforge.net>
parents: 1634
diff changeset
325 templates = {}
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
326 if debug: print(__file__) # noqa: E701
4900
349a83aca61f Correctly locate templates in a virtualenv (issue2550841)
John Kristensen <john@jerrykan.com>
parents: 4781
diff changeset
327 for N in 2, 4, 5, 6:
1652
7fb3bf18babb attempt to fix the template finding
Richard Jones <richard@users.sourceforge.net>
parents: 1634
diff changeset
328 path = __file__
7fb3bf18babb attempt to fix the template finding
Richard Jones <richard@users.sourceforge.net>
parents: 1634
diff changeset
329 # move up N elements in the path
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
330 for _i in range(N):
1652
7fb3bf18babb attempt to fix the template finding
Richard Jones <richard@users.sourceforge.net>
parents: 1634
diff changeset
331 path = os.path.dirname(path)
7fb3bf18babb attempt to fix the template finding
Richard Jones <richard@users.sourceforge.net>
parents: 1634
diff changeset
332 tdir = os.path.join(path, 'share', 'roundup', 'templates')
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
333 if debug or trace_search: print(tdir) # noqa: E701
1652
7fb3bf18babb attempt to fix the template finding
Richard Jones <richard@users.sourceforge.net>
parents: 1634
diff changeset
334 if os.path.isdir(tdir):
1916
d157b9b56ebf implemented munging of template name for installed trackers
Richard Jones <richard@users.sourceforge.net>
parents: 1905
diff changeset
335 templates = init.listTemplates(tdir)
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
336 if debug: print(" Found templates breaking loop") # noqa: E701
1652
7fb3bf18babb attempt to fix the template finding
Richard Jones <richard@users.sourceforge.net>
parents: 1634
diff changeset
337 break
1591
21312a7564fd moving templates around
Richard Jones <richard@users.sourceforge.net>
parents: 1570
diff changeset
338
6524
f961dbbc3573 issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents: 6491
diff changeset
339 # search for data files parallel to the roundup
f961dbbc3573 issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents: 6491
diff changeset
340 # install dir. E.G. a wheel install
f961dbbc3573 issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents: 6491
diff changeset
341 # use roundup.__path__ and go up a level then use sys.prefix
f961dbbc3573 issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents: 6491
diff changeset
342 # to create a base path for searching.
f961dbbc3573 issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents: 6491
diff changeset
343
6527
5ad7fb912227 issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents: 6524
diff changeset
344 import sys
5ad7fb912227 issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents: 6524
diff changeset
345 # __file__ should be something like:
5ad7fb912227 issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents: 6524
diff changeset
346 # /usr/local/lib/python3.10/site-packages/roundup/admin.py
6524
f961dbbc3573 issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents: 6491
diff changeset
347 # os.prefix should be /usr, /usr/local or root of virtualenv
f961dbbc3573 issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents: 6491
diff changeset
348 # strip leading / to make os.path.join work right.
6527
5ad7fb912227 issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents: 6524
diff changeset
349 path = __file__
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
350 for _N in 1, 2:
6527
5ad7fb912227 issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents: 6524
diff changeset
351 path = os.path.dirname(path)
5ad7fb912227 issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents: 6524
diff changeset
352 # path is /usr/local/lib/python3.10/site-packages
5ad7fb912227 issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents: 6524
diff changeset
353 tdir = os.path.join(path, sys.prefix[1:], 'share',
5ad7fb912227 issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents: 6524
diff changeset
354 'roundup', 'templates')
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
355 if debug or trace_search: print(tdir) # noqa: E701
6524
f961dbbc3573 issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents: 6491
diff changeset
356 if os.path.isdir(tdir):
f961dbbc3573 issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents: 6491
diff changeset
357 templates.update(init.listTemplates(tdir))
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
358
6739
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
359 try:
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
360 # sigh pip 3.10 in virtual env finds another place to bury them.
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
361 # why local and sys.base_prefix are in path I do not know.
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
362 # path is /usr/local/lib/python3.10/site-packages
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
363 tdir = os.path.join(path, sys.base_prefix[1:], 'local', 'share',
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
364 'roundup', 'templates')
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
365 if debug or trace_search: print(tdir) # noqa: E701
6739
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
366 if os.path.isdir(tdir):
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
367 templates.update(init.listTemplates(tdir))
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
368 # path is /usr/local/lib/python3.10/site-packages
6739
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
369
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
370 tdir = os.path.join(path, sys.base_prefix[1:], 'share',
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
371 'roundup', 'templates')
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
372 if debug or trace_search: print(tdir) # noqa: E701
6739
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
373 if os.path.isdir(tdir):
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
374 templates.update(init.listTemplates(tdir))
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
375 except AttributeError:
00fe67eb8a91 Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
376 pass # sys.base_prefix doesn't work under python2
1591
21312a7564fd moving templates around
Richard Jones <richard@users.sourceforge.net>
parents: 1570
diff changeset
377
1593
6318b21b0f73 more places to look for templates
Richard Jones <richard@users.sourceforge.net>
parents: 1591
diff changeset
378 # Try subdirs of the current dir
1916
d157b9b56ebf implemented munging of template name for installed trackers
Richard Jones <richard@users.sourceforge.net>
parents: 1905
diff changeset
379 templates.update(init.listTemplates(os.getcwd()))
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
380 if debug or trace_search: print(os.getcwd() + '/*') # noqa: E701
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
381
1593
6318b21b0f73 more places to look for templates
Richard Jones <richard@users.sourceforge.net>
parents: 1591
diff changeset
382 # Finally, try the current directory as a template
1916
d157b9b56ebf implemented munging of template name for installed trackers
Richard Jones <richard@users.sourceforge.net>
parents: 1905
diff changeset
383 template = init.loadTemplateInfo(os.getcwd())
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
384 if debug or trace_search: print(os.getcwd()) # noqa: E701
1593
6318b21b0f73 more places to look for templates
Richard Jones <richard@users.sourceforge.net>
parents: 1591
diff changeset
385 if template:
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
386 if debug: print(" Found template %s" % # noqa: E701
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
387 template['name'])
1593
6318b21b0f73 more places to look for templates
Richard Jones <richard@users.sourceforge.net>
parents: 1591
diff changeset
388 templates[template['name']] = template
6318b21b0f73 more places to look for templates
Richard Jones <richard@users.sourceforge.net>
parents: 1591
diff changeset
389
1591
21312a7564fd moving templates around
Richard Jones <richard@users.sourceforge.net>
parents: 1570
diff changeset
390 return templates
21312a7564fd moving templates around
Richard Jones <richard@users.sourceforge.net>
parents: 1570
diff changeset
391
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
392 def help_initopts(self):
1591
21312a7564fd moving templates around
Richard Jones <richard@users.sourceforge.net>
parents: 1570
diff changeset
393 templates = self.listTemplates()
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
394 print(_('Templates:'), ', '.join(templates))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
395 import roundup.backends
2856
adec352e2ce0 don't try to import all backends in backends.__init__ unless we *want* to
Richard Jones <richard@users.sourceforge.net>
parents: 2793
diff changeset
396 backends = roundup.backends.list_backends()
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
397 print(_('Back ends:'), ', '.join(backends))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
398
5163
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
399 def _get_choice(self, list_name, prompt, options, argument, default=None):
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
400 if default is None:
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
401 default = options[0] # just pick the first one
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
402 if argument in options:
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
403 return argument
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
404 if self.force:
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
405 return default
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
406 sys.stdout.write('%s: %s\n' % (list_name, ', '.join(options)))
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
407 while argument not in options:
7182
0c6617db0b97 Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents: 7178
diff changeset
408 argument = self.my_input('%s [%s]: ' % (prompt, default))
5163
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
409 if not argument:
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
410 return default
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
411 return argument
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
412
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
413 def do_commit(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
414 ''"""Usage: commit
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
415 Commit changes made to the database during an interactive session.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
416
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
417 The changes made during an interactive session are not
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
418 automatically written to the database - they must be committed
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
419 using this command.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
420
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
421 One-off commands on the command-line are automatically committed if
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
422 they are successful.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
423 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
424 self.db.commit()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
425 self.db_uncommitted = False
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
426 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
427
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
428 def do_create(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
429 ''"""Usage: create classname property=value ...
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
430 Create a new entry of a given class.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
431
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
432 This creates a new entry of the given class using the property
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
433 name=value arguments provided on the command line after the "create"
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
434 command.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
435 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
436 if len(args) < 1:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
437 raise UsageError(_('Not enough arguments supplied'))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
438 from roundup import hyperdb
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
439
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
440 classname = args[0]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
441
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
442 # get the class
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
443 cl = self.get_class(classname)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
444
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
445 # now do a create
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
446 props = {}
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
447 properties = cl.getprops(protected=0)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
448 if len(args) == 1:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
449 # ask for the properties
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
450 for key in properties:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
451 if key == 'id': continue # noqa: E701
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
452 value = properties[key]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
453 name = value.__class__.__name__
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
454 if isinstance(value, hyperdb.Password):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
455 again = None
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
456 while value != again:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
457 value = getpass.getpass(_('%(propname)s (Password): ')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
458 %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
459 {'propname': key.capitalize()})
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
460 again = getpass.getpass(_(' %(propname)s (Again): ')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
461 %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
462 {'propname': key.capitalize()})
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
463 if value != again:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
464 print(_('Sorry, try again...'))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
465 if value:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
466 props[key] = value
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
467 else:
7252
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
468 value = self.my_input(_(
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
469 '%(propname)s (%(proptype)s): ') % {
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
470 'propname': key.capitalize(), 'proptype': name})
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
471 if value:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
472 props[key] = value
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
473 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
474 props = self.props_from_args(args[1:])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
475
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
476 # convert types
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
477 for propname in props:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
478 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
479 props[propname] = hyperdb.rawToHyperdb(self.db, cl, None,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
480 propname,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
481 props[propname])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
482 except hyperdb.HyperdbValueError as message:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
483 raise UsageError(message)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
484
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
485 # check for the key property
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
486 propname = cl.getkey()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
487 if propname and propname not in props:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
488 raise UsageError(_('you must provide the "%(propname)s" '
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
489 'property.') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
490
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
491 # do the actual create
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
492 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
493 sys.stdout.write(cl.create(**props) + '\n')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
494 except (TypeError, IndexError, ValueError) as message:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
495 raise UsageError(message)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
496 self.db_uncommitted = True
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
497 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
498
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
499 def do_display(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
500 ''"""Usage: display designator[,designator]*
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
501
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
502 Show the property values for the given node(s).
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
503
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
504 A designator is a classname and a nodeid concatenated,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
505 eg. bug1, user10, ...
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
506
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
507 This lists the properties and their associated values
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
508 for the given node.
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
509 """
2889
accb3b411ef6 instructions and method for generating config.ini
Richard Jones <richard@users.sourceforge.net>
parents: 2856
diff changeset
510 if len(args) < 1:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
511 raise UsageError(_('Not enough arguments supplied'))
7203
12a3cd86668f auto update 'password_pbkdf2_default_rounds' "
John Rouillard <rouilj@ieee.org>
parents: 7182
diff changeset
512
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
513 # decode the node designator
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
514 for designator in args[0].split(','):
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
515 try:
902
b0d3d3535998 Bugger it. Here's the current shape of the new security implementation.
Richard Jones <richard@users.sourceforge.net>
parents: 880
diff changeset
516 classname, nodeid = hyperdb.splitDesignator(designator)
5248
198b6e810c67 Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents: 5245
diff changeset
517 except hyperdb.DesignatorError as message:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
518 raise UsageError(message)
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
519
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
520 # get the class
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
521 cl = self.get_class(classname)
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
522
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
523 # display the values
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
524 keys = sorted(cl.properties)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
525 for key in keys:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
526 value = cl.get(nodeid, key)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
527 print(_('%(key)s: %(value)s') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
528
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
529 def do_export(self, args, export_files=True):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
530 ''"""Usage: export [[-]class[,class]] export_dir
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
531 Export the database to colon-separated-value files.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
532 To exclude the files (e.g. for the msg or file class),
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
533 use the exporttables command.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
534
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
535 Optionally limit the export to just the named classes
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
536 or exclude the named classes, if the 1st argument starts with '-'.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
537
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
538 This action exports the current data from the database into
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
539 colon-separated-value files that are placed in the nominated
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
540 destination directory.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
541 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
542 # grab the directory to export to
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
543 if len(args) < 1:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
544 raise UsageError(_('Not enough arguments supplied'))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
545
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
546 dir = args[-1]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
547
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
548 # get the list of classes to export
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
549 if len(args) == 2:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
550 if args[0].startswith('-'):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
551 classes = [c for c in self.db.classes
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
552 if c not in args[0][1:].split(',')]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
553 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
554 classes = args[0].split(',')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
555 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
556 classes = self.db.classes
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
557
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
558 class colon_separated(csv.excel):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
559 delimiter = ':'
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
560
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
561 # make sure target dir exists
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
562 if not os.path.exists(dir):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
563 os.makedirs(dir)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
564
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
565 # maximum csv field length exceeding configured size?
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
566 max_len = self.db.config.CSV_FIELD_SIZE
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
567
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
568 # do all the classes specified
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
569 for classname in classes:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
570 cl = self.get_class(classname)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
571
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
572 if not export_files and hasattr(cl, 'export_files'):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
573 sys.stdout.write('Exporting %s WITHOUT the files\r\n' %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
574 classname)
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
575
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
576 with open(os.path.join(dir, classname+'.csv'), 'w') as f:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
577 writer = csv.writer(f, colon_separated)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
578
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
579 propnames = cl.export_propnames()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
580 fields = propnames[:]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
581 fields.append('is retired')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
582 writer.writerow(fields)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
583
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
584 # If a node has a key, sort all nodes by key
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
585 # with retired nodes first. Retired nodes
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
586 # must occur before a non-retired node with
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
587 # the same key. Otherwise you get an
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
588 # IntegrityError: UNIQUE constraint failed:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
589 # _class.__retired__, _<class>._<keyname>
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
590 # on imports to rdbms.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
591 all_nodes = cl.getnodeids()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
592
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
593 classkey = cl.getkey()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
594 if classkey: # False sorts before True, so negate is_retired
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
595 keysort = lambda i: (cl.get(i, classkey), # noqa: E731
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
596 not cl.is_retired(i))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
597 all_nodes.sort(key=keysort)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
598 # if there is no classkey no need to sort
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
599
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
600 for nodeid in all_nodes:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
601 if self.verbose:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
602 sys.stdout.write('\rExporting %s - %s' %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
603 (classname, nodeid))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
604 sys.stdout.flush()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
605 node = cl.getnode(nodeid)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
606 exp = cl.export_list(propnames, nodeid)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
607 lensum = sum([len(repr_export(node[p])) for
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
608 p in propnames])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
609 # for a safe upper bound of field length we add
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
610 # difference between CSV len and sum of all field lengths
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
611 d = sum([len(x) for x in exp]) - lensum
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
612 if not d > 0:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
613 raise AssertionError("Bad assertion d > 0")
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
614 for p in propnames:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
615 ll = len(repr_export(node[p])) + d
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
616 if ll > max_len:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
617 max_len = ll
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
618 writer.writerow(exp)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
619 if export_files and hasattr(cl, 'export_files'):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
620 cl.export_files(dir, nodeid)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
621
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
622 # export the journals
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
623 with open(os.path.join(dir, classname+'-journals.csv'), 'w') as jf:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
624 if self.verbose:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
625 sys.stdout.write("\nExporting Journal for %s\n" %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
626 classname)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
627 sys.stdout.flush()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
628 journals = csv.writer(jf, colon_separated)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
629 for row in cl.export_journals():
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
630 journals.writerow(row)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
631 if max_len > self.db.config.CSV_FIELD_SIZE:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
632 print("Warning: config csv_field_size should be at least %s" %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
633 max_len, file=sys.stderr)
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
634 return 0
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
635
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
636 def do_exporttables(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
637 ''"""Usage: exporttables [[-]class[,class]] export_dir
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
638 Export the database to colon-separated-value files, excluding the
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
639 files below $TRACKER_HOME/db/files/ (which can be archived separately).
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
640 To include the files, use the export command.
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
641
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
642 Optionally limit the export to just the named classes
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
643 or exclude the named classes, if the 1st argument starts with '-'.
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
644
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
645 This action exports the current data from the database into
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
646 colon-separated-value files that are placed in the nominated
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
647 destination directory.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
648 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
649 return self.do_export(args, export_files=False)
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
650
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
651 def do_filter(self, args):
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
652 ''"""Usage: filter classname propname=value ...
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
653 Find the nodes of the given class with a given property value.
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
654
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
655 Find the nodes of the given class with a given property value.
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
656 Multiple values can be specified by separating them with commas.
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
657 If property is a string, all values must match. I.E. it's an
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
658 'and' operation. If the property is a link/multilink any value
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
659 matches. I.E. an 'or' operation.
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
660 """
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
661 if len(args) < 1:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
662 raise UsageError(_('Not enough arguments supplied'))
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
663 classname = args[0]
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
664 # get the class
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
665 cl = self.get_class(classname)
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
666
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
667 # handle the propname=value argument
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
668 props = self.props_from_args(args[1:])
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
669
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
670 # convert the user-input value to a value used for filter
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
671 # multiple , separated values become a list
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
672 for propname, value in props.items():
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
673 if ',' in value:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
674 values = value.split(',')
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
675 else:
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
676 values = [value]
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
677
6177
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
678 props[propname] = []
6250
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
679 # start handling transitive props
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
680 # given filter issue assignedto.roles=Admin
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
681 # start at issue
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
682 curclass = cl
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
683 lastprop = propname # handle case 'issue assignedto=admin'
6250
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
684 if '.' in propname:
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
685 # start splitting transitive prop into components
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
686 # we end when we have no more links
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
687 for pn in propname.split('.'):
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
688 try:
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
689 lastprop = pn # get current component
6250
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
690 # get classname for this link
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
691 try:
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
692 curclassname = curclass.getprops()[pn].classname
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
693 except KeyError:
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
694 raise UsageError(_(
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
695 "Class %(curclassname)s has "
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
696 "no property %(pn)s in %(propname)s." %
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
697 locals()))
6250
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
698 # get class object
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
699 curclass = self.get_class(curclassname)
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
700 except AttributeError:
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
701 # curclass.getprops()[pn].classname raises this
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
702 # when we are at a non link/multilink property
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
703 pass
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
704
6177
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
705 for value in values:
6250
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
706 val = hyperdb.rawToHyperdb(self.db, curclass, None,
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
707 lastprop, value)
6177
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
708 props[propname].append(val)
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
709
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
710 # now do the filter
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
711 try:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
712 id = []
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
713 designator = []
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
714 props = {"filterspec": props}
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
715
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
716 if self.separator:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
717 if self.print_designator:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
718 id = cl.filter(None, **props)
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
719 for i in id:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
720 designator.append(classname + i)
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
721 print(self.separator.join(designator))
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
722 else:
6250
95183d73ac64 issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 6208
diff changeset
723 print(self.separator.join(cl.filter(None, **props)))
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
724 else:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
725 if self.print_designator:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
726 id = cl.filter(None, **props)
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
727 for i in id:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
728 designator.append(classname + i)
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
729 print(designator)
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
730 else:
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
731 print(cl.filter(None, **props))
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
732 except KeyError:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
733 raise UsageError(_('%(classname)s has no property '
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
734 '"%(propname)s"') % locals())
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
735 except (ValueError, TypeError) as message:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
736 raise UsageError(message)
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
737 return 0
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 6001
diff changeset
738
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
739 def do_find(self, args):
4073
145b32238093 Revert docstring markup for use with gettext tool.
Stefan Seefeld <stefan@seefeld.name>
parents: 4067
diff changeset
740 ''"""Usage: find classname propname=value ...
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
741 Find the nodes of the given class with a given link property value.
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
742
2329
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
743 Find the nodes of the given class with a given link property value.
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
744 The value may be either the nodeid of the linked node, or its key
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
745 value.
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
746 """
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
747 if len(args) < 1:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
748 raise UsageError(_('Not enough arguments supplied'))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
749 classname = args[0]
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
750 # get the class
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
751 cl = self.get_class(classname)
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
752
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
753 # handle the propname=value argument
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
754 props = self.props_from_args(args[1:])
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
755
2494
ea7fb2f416db fixed RDBMS Class.find() to handle None value in multiple find...
Richard Jones <richard@users.sourceforge.net>
parents: 2450
diff changeset
756 # convert the user-input value to a value used for find()
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
757 for propname, value in props.items():
2494
ea7fb2f416db fixed RDBMS Class.find() to handle None value in multiple find...
Richard Jones <richard@users.sourceforge.net>
parents: 2450
diff changeset
758 if ',' in value:
ea7fb2f416db fixed RDBMS Class.find() to handle None value in multiple find...
Richard Jones <richard@users.sourceforge.net>
parents: 2450
diff changeset
759 values = value.split(',')
ea7fb2f416db fixed RDBMS Class.find() to handle None value in multiple find...
Richard Jones <richard@users.sourceforge.net>
parents: 2450
diff changeset
760 else:
2504
Richard Jones <richard@users.sourceforge.net>
parents: 2496
diff changeset
761 values = [value]
2494
ea7fb2f416db fixed RDBMS Class.find() to handle None value in multiple find...
Richard Jones <richard@users.sourceforge.net>
parents: 2450
diff changeset
762 d = props[propname] = {}
ea7fb2f416db fixed RDBMS Class.find() to handle None value in multiple find...
Richard Jones <richard@users.sourceforge.net>
parents: 2450
diff changeset
763 for value in values:
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
764 value = hyperdb.rawToHyperdb(self.db, cl, None,
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
765 propname, value)
3314
4372716a675a merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
766 if isinstance(value, list):
4372716a675a merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
767 for entry in value:
4372716a675a merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
768 d[entry] = 1
4372716a675a merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
769 else:
4372716a675a merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents: 3295
diff changeset
770 d[value] = 1
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
771
2307
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
772 # now do the find
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
773 try:
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
774 id = []
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
775 designator = []
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
776 if self.separator:
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
777 if self.print_designator:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
778 id = cl.find(**props)
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
779 for i in id:
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
780 designator.append(classname + i)
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
781 print(self.separator.join(designator))
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
782 else:
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
783 print(self.separator.join(cl.find(**props)))
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
784
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
785 else:
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
786 if self.print_designator:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
787 id = cl.find(**props)
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
788 for i in id:
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
789 designator.append(classname + i)
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
790 print(designator)
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
791 else:
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
792 print(cl.find(**props))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
793 except KeyError:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
794 raise UsageError(_('%(classname)s has no property '
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
795 '"%(propname)s"') % locals())
5248
198b6e810c67 Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents: 5245
diff changeset
796 except (ValueError, TypeError) as message:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
797 raise UsageError(message)
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
798 return 0
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
799
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
800 def do_genconfig(self, args, update=False):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
801 ''"""Usage: genconfig <filename>
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
802 Generate a new tracker config file (ini style) with default
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
803 values in <filename>.
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
804 """
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
805 if len(args) < 1:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
806 raise UsageError(_('Not enough arguments supplied'))
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
807
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
808 if update:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
809 # load current config for writing
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
810 config = CoreConfig(self.tracker_home)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
811
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
812 # change config to update settings to new defaults
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
813 # where prior defaults were chosen
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
814 default_ppdr = config._get_option(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
815 'PASSWORD_PBKDF2_DEFAULT_ROUNDS')._default_value
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
816
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
817 print("") # put a blank line before feedback
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
818 if config.PASSWORD_PBKDF2_DEFAULT_ROUNDS in [10000]:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
819 print(_("Changing option\n"
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
820 " 'password_pbkdf2_default_rounds'\n"
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
821 "from old default of %(old_number)s to new "
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
822 "default of %(new_number)s.") % {
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
823 "old_number":
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
824 config.PASSWORD_PBKDF2_DEFAULT_ROUNDS,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
825 "new_number": default_ppdr
7252
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
826 })
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
827 config.PASSWORD_PBKDF2_DEFAULT_ROUNDS = default_ppdr
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
828
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
829 if config.PASSWORD_PBKDF2_DEFAULT_ROUNDS < default_ppdr:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
830 print(_("Update "
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
831 "'password_pbkdf2_default_rounds' "
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
832 "to a number equal to or larger\nthan %s.") %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
833 default_ppdr)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
834 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
835 # generate default config
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
836 config = CoreConfig()
6191
5713ddd87fd3 Fix help text.
John Rouillard <rouilj@ieee.org>
parents: 6187
diff changeset
837
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
838 config.save(args[0])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
839
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
840 def do_get(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
841 ''"""Usage: get property designator[,designator]*
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
842 Get the given property of one or more designator(s).
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
843
4299
e16a1131ba67 include info on what a designator is in all commands that use them
Richard Jones <richard@users.sourceforge.net>
parents: 4269
diff changeset
844 A designator is a classname and a nodeid concatenated,
e16a1131ba67 include info on what a designator is in all commands that use them
Richard Jones <richard@users.sourceforge.net>
parents: 4269
diff changeset
845 eg. bug1, user10, ...
e16a1131ba67 include info on what a designator is in all commands that use them
Richard Jones <richard@users.sourceforge.net>
parents: 4269
diff changeset
846
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
847 Retrieves the property value of the nodes specified
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
848 by the designators.
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
849 """
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
850 if len(args) < 2:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
851 raise UsageError(_('Not enough arguments supplied'))
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
852 propname = args[0]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
853 designators = args[1].split(',')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
854 linked_props = []
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
855 for designator in designators:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
856 # decode the node designator
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
857 try:
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
858 classname, nodeid = hyperdb.splitDesignator(designator)
5248
198b6e810c67 Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents: 5245
diff changeset
859 except hyperdb.DesignatorError as message:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
860 raise UsageError(message)
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
861
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
862 # get the class
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
863 cl = self.get_class(classname)
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
864 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
865 id = []
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
866 if self.separator:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
867 if self.print_designator:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
868 # see if property is a link or multilink for
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
869 # which getting a desginator make sense.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
870 # Algorithm: Get the properties of the
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
871 # current designator's class. (cl.getprops)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
872 # get the property object for the property the
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
873 # user requested (properties[propname])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
874 # verify its type (isinstance...)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
875 # raise error if not link/multilink
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
876 # get class name for link/multilink property
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
877 # do the get on the designators
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
878 # append the new designators
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
879 # print
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
880 properties = cl.getprops()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
881 property = properties[propname]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
882 if not (isinstance(property, hyperdb.Multilink) or
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
883 isinstance(property, hyperdb.Link)):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
884 raise UsageError(_(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
885 'property %s is not of type'
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
886 ' Multilink or Link so -d flag does not '
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
887 'apply.') % propname)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
888 propclassname = self.db.getclass(property.classname).classname
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
889 id = cl.get(nodeid, propname)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
890 for i in id:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
891 linked_props.append(propclassname + i)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
892 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
893 id = cl.get(nodeid, propname)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
894 for i in id:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
895 linked_props.append(i)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
896 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
897 if self.print_designator:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
898 properties = cl.getprops()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
899 property = properties[propname]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
900 if not (isinstance(property, hyperdb.Multilink) or
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
901 isinstance(property, hyperdb.Link)):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
902 raise UsageError(_(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
903 'property %s is not of type'
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
904 ' Multilink or Link so -d flag does not '
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
905 'apply.') % propname)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
906 propclassname = self.db.getclass(property.classname).classname
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
907 id = cl.get(nodeid, propname)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
908 for i in id:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
909 print(propclassname + i)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
910 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
911 print(cl.get(nodeid, propname))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
912 except IndexError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
913 raise UsageError(_('no such %(classname)s node '
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
914 '"%(nodeid)s"') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
915 except KeyError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
916 raise UsageError(_('no such %(classname)s property '
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
917 '"%(propname)s"') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
918 if self.separator:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
919 print(self.separator.join(linked_props))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
920
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
921 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
922
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
923 def do_help(self, args, nl_re=nl_re, indent_re=indent_re):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
924 ''"""Usage: help topic
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
925 Give help about topic.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
926
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
927 commands -- list commands
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
928 <command> -- help specific to a command
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
929 initopts -- init command options
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
930 all -- all available help
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
931 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
932 if len(args) > 0:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
933 topic = args[0]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
934 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
935 topic = 'help'
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
936
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
937 # try help_ methods
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
938 if topic in self.help:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
939 self.help[topic]()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
940 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
941
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
942 # try command docstrings
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
943 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
944 cmd_docs = self.commands.get(topic)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
945 except KeyError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
946 print(_('Sorry, no help for "%(topic)s"') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
947 return 1
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
948
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
949 # display the help for each match, removing the docstring indent
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
950 for _name, help in cmd_docs:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
951 lines = nl_re.split(_(help.__doc__))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
952 print(lines[0])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
953 indent = indent_re.match(lines[1])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
954 if indent: indent = len(indent.group(1)) # noqa: E701
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
955 for line in lines[1:]:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
956 if indent:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
957 print(line[indent:])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
958 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
959 print(line)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
960 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
961
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
962 def do_history(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
963 ''"""Usage: history designator [skipquiet]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
964 Show the history entries of a designator.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
965
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
966 A designator is a classname and a nodeid concatenated,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
967 eg. bug1, user10, ...
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
968
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
969 Lists the journal entries viewable by the user for the
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
970 node identified by the designator. If skipquiet is the
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
971 second argument, journal entries for quiet properties
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
972 are not shown.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
973 """
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
974
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
975 if len(args) < 1:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
976 raise UsageError(_('Not enough arguments supplied'))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
977 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
978 classname, nodeid = hyperdb.splitDesignator(args[0])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
979 except hyperdb.DesignatorError as message:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
980 raise UsageError(message)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
981
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
982 skipquiet = False
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
983 if len(args) == 2:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
984 if args[1] != 'skipquiet':
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
985 raise UsageError("Second argument is not skipquiet")
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
986 skipquiet = True
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
987
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
988 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
989 print(self.db.getclass(classname).history(nodeid,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
990 skipquiet=skipquiet))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
991 except KeyError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
992 raise UsageError(_('no such class "%(classname)s"') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
993 except IndexError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
994 raise UsageError(_('no such %(classname)s node '
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
995 '"%(nodeid)s"') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
996 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
997
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
998 def do_import(self, args, import_files=True):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
999 ''"""Usage: import import_dir
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1000 Import a database from the directory containing CSV files,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1001 two per class to import.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1002
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1003 The files used in the import are:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1004
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1005 <class>.csv
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1006 This must define the same properties as the class (including
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1007 having a "header" line with those property names.)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1008 <class>-journals.csv
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1009 This defines the journals for the items being imported.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1010
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1011 The imported nodes will have the same nodeid as defined in the
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1012 import file, thus replacing any existing content.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1013
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1014 The new nodes are added to the existing database - if you want to
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1015 create a new database using the imported data, then create a new
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1016 database (or, tediously, retire all the old data.)
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
1017 """
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1018 if len(args) < 1:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
1019 raise UsageError(_('Not enough arguments supplied'))
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1020
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1021 if hasattr(csv, 'field_size_limit'):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1022 csv.field_size_limit(self.db.config.CSV_FIELD_SIZE)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1023
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1024 # directory to import from
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1025 dir = args[0]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1026
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1027 class colon_separated(csv.excel):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1028 delimiter = ':'
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1029
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1030 # import all the files
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1031 for file in os.listdir(dir):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1032 classname, ext = os.path.splitext(file)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1033 # we only care about CSV files
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1034 if ext != '.csv' or classname.endswith('-journals'):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1035 continue
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1036
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1037 cl = self.get_class(classname)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1038
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1039 # ensure that the properties and the CSV file headings match
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1040 with open(os.path.join(dir, file), 'r') as f:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1041 reader = csv.reader(f, colon_separated)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1042 file_props = None
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1043 maxid = 1
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1044 # loop through the file and create a node for each entry
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1045 for n, r in enumerate(reader):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1046 if file_props is None:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1047 file_props = r
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1048 continue
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1049
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1050 if self.verbose:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1051 sys.stdout.write('\rImporting %s - %s' % (classname, n))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1052 sys.stdout.flush()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1053
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1054 # do the import and figure the current highest nodeid
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1055 nodeid = cl.import_list(file_props, r)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1056 if hasattr(cl, 'import_files') and import_files:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1057 cl.import_files(dir, nodeid)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1058 maxid = max(maxid, int(nodeid))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1059
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1060 # (print to sys.stdout here to allow tests to squash it .. ugh)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1061 print(file=sys.stdout)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1062
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1063 # import the journals
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1064 with open(os.path.join(args[0], classname + '-journals.csv'), 'r') as f:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1065 reader = csv.reader(f, colon_separated)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1066 cl.import_journals(reader)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1067
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1068 # (print to sys.stdout here to allow tests to squash it .. ugh)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1069 print('setting', classname, maxid+1, file=sys.stdout)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1070
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1071 # set the id counter
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1072 self.db.setid(classname, str(maxid+1))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1073
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1074 self.db_uncommitted = True
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1075 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1076
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1077 def do_importtables(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1078 ''"""Usage: importtables export_dir
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1079
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1080 This imports the database tables exported using exporttables.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1081 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1082 return self.do_import(args, import_files=False)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1083
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1084 def do_initialise(self, tracker_home, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1085 ''"""Usage: initialise [adminpw]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1086 Initialise a new Roundup tracker.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1087
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1088 The administrator details will be set at this step.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1089
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1090 Execute the tracker's initialisation function dbinit.init()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1091 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1092 # password
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1093 if len(args) > 1:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1094 adminpw = args[1]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1095 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1096 adminpw = ''
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1097 confirm = 'x'
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1098 while adminpw != confirm:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1099 adminpw = getpass.getpass(_('Admin Password: '))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1100 confirm = getpass.getpass(_(' Confirm: '))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1101
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1102 # make sure the tracker home is installed
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1103 if not os.path.exists(tracker_home):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1104 raise UsageError(_('Instance home does not exist') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1105 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1106 tracker = roundup.instance.open(tracker_home)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1107 except roundup.instance.TrackerError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1108 raise UsageError(_('Instance has not been installed') % locals())
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1109
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1110 # is there already a database?
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1111 if tracker.exists():
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1112 if not self.force:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1113 ok = self.my_input(_(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1114 """WARNING: The database is already initialised!
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1115 If you re-initialise it, you will lose all the data!
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1116 Erase it? Y/N: """)) # noqa: E122
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1117 if ok.strip().lower() != 'y':
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1118 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1119
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1120 # nuke it
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1121 tracker.nuke()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1122
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1123 # GO
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1124 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1125 tracker.init(password.Password(adminpw, config=tracker.config),
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1126 tx_Source='cli')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1127 except OptionUnsetError as e:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1128 raise UsageError("In %(tracker_home)s/config.ini - %(error)s" % {
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1129 'error': str(e), 'tracker_home': tracker_home})
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1130
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1131 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1132
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1133 def do_install(self, tracker_home, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1134 ''"""Usage: install [template [backend [key=val[,key=val]]]]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1135 Install a new Roundup tracker.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1136
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1137 The command will prompt for the tracker home directory
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1138 (if not supplied through TRACKER_HOME or the -i option).
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1139 The template and backend may be specified on the command-line
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1140 as arguments, in that order.
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1141
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1142 Command line arguments following the backend allows you to
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1143 pass initial values for config options. For example, passing
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1144 "web_http_auth=no,rdbms_user=dinsdale" will override defaults
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1145 for options http_auth in section [web] and user in section [rdbms].
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1146 Please be careful to not use spaces in this argument! (Enclose
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1147 whole argument in quotes if you need spaces in option value).
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1148
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1149 The initialise command must be called after this command in order
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1150 to initialise the tracker's database. You may edit the tracker's
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1151 initial database contents before running that command by editing
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1152 the tracker's dbinit.py module init() function.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1153
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1154 See also initopts help.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1155 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1156 if len(args) < 1:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1157 raise UsageError(_('Not enough arguments supplied'))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1158
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1159 # make sure the tracker home can be created
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1160 tracker_home = os.path.abspath(tracker_home)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1161 parent = os.path.split(tracker_home)[0]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1162 if not os.path.exists(parent):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1163 raise UsageError(_('Instance home parent directory "%(parent)s"'
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1164 ' does not exist') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1165
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1166 config_ini_file = os.path.join(tracker_home, CoreConfig.INI_FILE)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1167 # check for both old- and new-style configs
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1168 if list(filter(os.path.exists, [config_ini_file,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1169 os.path.join(tracker_home, 'config.py')])):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1170 if not self.force:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1171 ok = self.my_input(_(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1172 """WARNING: There appears to be a tracker in "%(tracker_home)s"!
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1173 If you re-install it, you will lose all the data!
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1174 Erase it? Y/N: """) % locals()) # noqa: E122
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1175 if ok.strip().lower() != 'y':
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1176 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1177
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1178 # clear it out so the install isn't confused
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1179 shutil.rmtree(tracker_home)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1180
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1181 # select template
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1182 templates = self.listTemplates()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1183 template = self._get_choice(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1184 list_name=_('Templates:'),
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1185 prompt=_('Select template'),
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1186 options=templates,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1187 argument=len(args) > 1 and args[1] or '',
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1188 default='classic')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1189
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1190 # select hyperdb backend
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1191 import roundup.backends
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1192 backends = roundup.backends.list_backends()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1193 backend = self._get_choice(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1194 list_name=_('Back ends:'),
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1195 prompt=_('Select backend'),
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1196 options=backends,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1197 argument=len(args) > 2 and args[2] or '',
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1198 default='anydbm')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1199 # XXX perform a unit test based on the user's selections
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1200
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1201 # Process configuration file definitions
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1202 if len(args) > 3:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1203 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1204 defns = dict([item.split("=") for item in args[3].split(",")])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1205 except Exception:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1206 print(_('Error in configuration settings: "%s"') % args[3])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1207 raise
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1208 else:
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1209 defns = {}
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1210
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1211 defns['rdbms_backend'] = backend
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1212
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1213 # load config_ini.ini from template if it exists.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1214 # it sets parameters like template_engine that are
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1215 # template specific.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1216 template_config = UserConfig(templates[template]['path'] +
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1217 "/config_ini.ini")
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1218 for k in template_config.keys():
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1219 if k == 'HOME': # ignore home. It is a default param.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1220 continue
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1221 defns[k] = template_config[k]
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1222
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1223 # install!
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1224 init.install(tracker_home, templates[template]['path'], settings=defns)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1225
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1226 # Remove config_ini.ini file from tracker_home (not template dir).
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1227 # Ignore file not found - not all templates have
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1228 # config_ini.ini files.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1229 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1230 os.remove(tracker_home + "/config_ini.ini")
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1231 except OSError as e: # FileNotFound exception under py3
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1232 if e.errno == 2:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1233 pass
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1234 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1235 raise
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1236
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1237 print(_("""
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1238 ---------------------------------------------------------------------------
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1239 You should now edit the tracker configuration file:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1240 %(config_file)s""") % {"config_file": config_ini_file})
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1241
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1242 # find list of options that need manual adjustments
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1243 # XXX config._get_unset_options() is marked as private
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1244 # (leading underscore). make it public or don't care?
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1245 need_set = CoreConfig(tracker_home)._get_unset_options()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1246 if need_set:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1247 print(_(" ... at a minimum, you must set following options:"))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1248 for section in need_set:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1249 print(" [%s]: %s" % (section, ", ".join(need_set[section])))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1250
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1251 # note about schema modifications
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1252 print(_("""
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1253 If you wish to modify the database schema,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1254 you should also edit the schema file:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1255 %(database_config_file)s
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1256 You may also change the database initialisation file:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1257 %(database_init_file)s
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1258 ... see the documentation on customizing for more information.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1259
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1260 You MUST run the "roundup-admin initialise" command once you've performed
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1261 the above steps.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1262 ---------------------------------------------------------------------------
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1263 """) % {'database_config_file': os.path.join(tracker_home, 'schema.py'),
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1264 'database_init_file': os.path.join(tracker_home, 'initial_data.py')}) \
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1265 # noqa: E122
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1266 return 0
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1267
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1268 def do_list(self, args):
4073
145b32238093 Revert docstring markup for use with gettext tool.
Stefan Seefeld <stefan@seefeld.name>
parents: 4067
diff changeset
1269 ''"""Usage: list classname [property]
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1270 List the instances of a class.
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1271
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1272 Lists all instances of the given class. If the property is not
2329
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
1273 specified, the "label" property is used. The label property is
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
1274 tried in order: the key, "name", "title" and then the first
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
1275 property, alphabetically.
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
1276
2329
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
1277 With -c, -S or -s print a list of item id's if no property
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
1278 specified. If property specified, print list of that property
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
1279 for every class instance.
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
1280 """
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
1281 if len(args) > 2:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
1282 raise UsageError(_('Too many arguments supplied'))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1283 if len(args) < 1:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
1284 raise UsageError(_('Not enough arguments supplied'))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1285 classname = args[0]
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1286
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1287 # get the class
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1288 cl = self.get_class(classname)
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1289
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1290 # figure the property
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1291 if len(args) > 1:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1292 propname = args[1]
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1293 else:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1294 propname = cl.labelprop()
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1295
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
1296 if self.separator:
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
1297 if len(args) == 2:
4073
145b32238093 Revert docstring markup for use with gettext tool.
Stefan Seefeld <stefan@seefeld.name>
parents: 4067
diff changeset
1298 # create a list of propnames since user specified propname
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1299 proplist = []
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
1300 for nodeid in cl.list():
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
1301 try:
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
1302 proplist.append(cl.get(nodeid, propname))
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
1303 except KeyError:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
1304 raise UsageError(_('%(classname)s has no property '
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1305 '"%(propname)s"') % locals())
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
1306 print(self.separator.join(proplist))
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
1307 else:
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
1308 # create a list of index id's since user didn't specify
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
1309 # otherwise
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
1310 print(self.separator.join(cl.list()))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1311 else:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1312 for nodeid in cl.list():
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1313 try:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1314 value = cl.get(nodeid, propname)
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1315 except KeyError:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
1316 raise UsageError(_('%(classname)s has no property '
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1317 '"%(propname)s"') % locals())
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1318 print(_('%(nodeid)4s: %(value)s') % locals())
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1319 return 0
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1320
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1321 def do_migrate(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1322 ''"""Usage: migrate
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1323
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1324 Update a tracker's database to be compatible with the Roundup
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1325 codebase.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1326
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1327 You should run the "migrate" command for your tracker once
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1328 you've installed the latest codebase.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1329
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1330 Do this before you use the web, command-line or mail interface
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1331 and before any users access the tracker.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1332
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1333 This command will respond with either "Tracker updated" (if
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1334 you've not previously run it on an RDBMS backend) or "No
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1335 migration action required" (if you have run it, or have used
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1336 another interface to the tracker, or possibly because you are
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1337 using anydbm).
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1338
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1339 It's safe to run this even if it's not required, so just get
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1340 into the habit.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1341 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1342 if self.db.db_version_updated:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1343 print(_('Tracker updated to schema version %s.') %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1344 self.db.database_schema['version'])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1345 self.db_uncommitted = True
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1346 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1347 print(_('No migration action required. At schema version %s.') %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1348 self.db.database_schema['version'])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1349 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1350
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1351 def do_pack(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1352 ''"""Usage: pack period | date
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1353
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1354 Remove journal entries older than a period of time specified or
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1355 before a certain date.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1356
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1357 A period is specified using the suffixes "y", "m", and "d". The
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1358 suffix "w" (for "week") means 7 days.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1359
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1360 "3y" means three years
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1361 "2y 1m" means two years and one month
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1362 "1m 25d" means one month and 25 days
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1363 "2w 3d" means two weeks and three days
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1364
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1365 Date format is "YYYY-MM-DD" eg:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1366 2001-01-01
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1367
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1368 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1369 if len(args) != 1:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1370 raise UsageError(_('Not enough arguments supplied'))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1371
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1372 # are we dealing with a period or a date
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1373 value = args[0]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1374 date_re = re.compile(r"""
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1375 (?P<date>\d\d\d\d-\d\d?-\d\d?)? # yyyy-mm-dd
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1376 (?P<period>(\d+y\s*)?(\d+m\s*)?(\d+d\s*)?)?
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1377 """, re.VERBOSE)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1378 m = date_re.match(value)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1379 if not m:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1380 raise ValueError(_('Invalid format'))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1381 m = m.groupdict()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1382 if m['period']:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1383 pack_before = date.Date(". - %s" % value)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1384 elif m['date']:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1385 pack_before = date.Date(value)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1386 self.db.pack(pack_before)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1387 self.db_uncommitted = True
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1388 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1389
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1390 def do_perftest(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1391 ''"""Usage: perftest [mode] [arguments]*
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1392
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1393 Time operations in Roundup. Supported arguments:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1394
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1395 [password] [rounds=<integer>] [scheme=<scheme>]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1396
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1397 'password' is the default mode. The tracker's config.ini
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1398 setting for 'password_pbkdf2_default_rounds' is the default
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1399 value for 'rounds'. On the command line, 'rounds' can include
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1400 thousands separator of ',' or '.'. 'scheme' is the default
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1401 coded into Roundup. List supported schemes by using 'scheme='.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1402
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1403 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1404 from roundup.anypy.time_ import perf_counter
6957
f924af12ef50 issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents: 6818
diff changeset
1405
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1406 props = {"rounds": self.db.config.PASSWORD_PBKDF2_DEFAULT_ROUNDS,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1407 "scheme": password.Password.known_schemes[0]}
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1408
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1409 print_supported_schemes = lambda: print(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1410 "Supported schemes (default is first, case "
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1411 "sensitive):\n %s." %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1412 ", ".join(password.Password.known_schemes))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1413
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1414 if (args[0].find("=") != -1):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1415 args.insert(0, 'password')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1416
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1417 props.update(self.props_from_args(args[1:]))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1418
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1419 if args[0] == "password":
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1420 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1421 # convert 10,000,000 or 10.000.000 to 10000000
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1422 r = int(re.sub('[,.]', '', props['rounds']))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1423 if r < 1000:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1424 print(_("Invalid 'rounds'. Must be larger than 999."))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1425 return
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1426 props['rounds'] = r
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1427 except (TypeError, ValueError):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1428 print(_("Invalid 'rounds'. It must be an integer not: %s") %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1429 props['rounds'])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1430 return
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1431 if props['scheme'] is None:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1432 print_supported_schemes()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1433 return
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1434
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1435 self.db.config.PASSWORD_PBKDF2_DEFAULT_ROUNDS = props['rounds']
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1436
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1437 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1438 tic = perf_counter()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1439 pw_hash = password.encodePassword(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1440 "this is a long password to hash",
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1441 props['scheme'],
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1442 None,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1443 config=self.db.config
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1444 )
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1445 toc = perf_counter()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1446 except password.PasswordValueError as e:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1447 print(e)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1448 print_supported_schemes()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1449 return
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1450
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1451 if props['scheme'].startswith('PBKDF2'):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1452 (rounds, salt, _raw_salt, digest) = password.pbkdf2_unpack(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1453 pw_hash)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1454 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1455 rounds = _("scheme does not support rounds.")
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1456
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1457 print(_(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1458 "Hash time: %(time)0.9f seconds, scheme: %(scheme)s, "
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1459 "rounds: %(rounds)s") %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1460 {"time": toc-tic, "scheme": props['scheme'],
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1461 "rounds": rounds})
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1462
7252
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1463 def do_pragma(self, args):
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1464 ''"""Usage: pragma setting=value | 'list'
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1465 Set internal admin settings to a value. E.G.
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1466
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1467 pragma verbose=True
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1468 pragma verbose=yes
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1469 pragma verbose=on
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1470 pragma verbose=1
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1471
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1472 will turn on verbose mode for roundup-admin.
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1473
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1474 pragma list
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1475
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1476 will show all settings and their current values. If verbose
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1477 is enabled hidden settings and descriptions will be shown.
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1478 """
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1479
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1480 if len(args) < 1:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1481 raise UsageError(_('Not enough arguments supplied'))
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1482
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1483 try:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1484 (setting, value) = args[0].split("=", 1)
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1485 except ValueError:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1486 if args[0] != "list":
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1487 raise UsageError(_(
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1488 'Argument must be setting=value, was given: %s.') %
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1489 args[0])
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1490 else:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1491 print(_("Current settings and values "
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1492 "(NYI - not yet implemented):"))
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1493 is_verbose = self.settings['verbose']
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1494 for key in sorted(list(self.settings.keys())):
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1495 if key.startswith('_') and not is_verbose:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1496 continue
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1497 print(" %s=%s" % (key, self.settings[key]))
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1498 if is_verbose:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1499 print(" %s" % self.settings_help[key])
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1500
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1501 return
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1502
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1503 if setting not in self.settings:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1504 raise UsageError(_('Unknown setting %s.') % setting)
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1505 if type(self.settings[setting]) is bool:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1506 value = value.lower()
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1507 if value in ("yes", "true", "on", "1"):
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1508 value = True
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1509 elif value in ("no", "false", "off", "0"):
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1510 value = False
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1511 else:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1512 raise UsageError(_(
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1513 'Incorrect value for boolean setting %(setting)s: '
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1514 '%(value)s.') % {"setting": setting, "value": value})
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1515 elif type(self.settings[setting]) is int:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1516 try:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1517 _val = int(value)
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1518 except ValueError:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1519 raise UsageError(_(
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1520 'Incorrect value for integer setting %(setting)s: '
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1521 '%(value)s.') % {"setting": setting, "value": value})
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1522 value = _val
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1523 elif type(self.settings[setting]) is str:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1524 pass
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1525 else:
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1526 raise UsageError(_('Internal error: pragma can not handle '
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1527 'values of type: %s') %
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1528 type(self.settings[setting]).__name__)
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1529
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1530 self.settings[setting] = value
9c067ed4568b add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 7250
diff changeset
1531
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1532 designator_re = re.compile('([A-Za-z]+)([0-9]+)')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1533
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1534 def do_reindex(self, args, desre=designator_re):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1535 ''"""Usage: reindex [classname|designator]*
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1536 Re-generate a tracker's search indexes.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1537
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1538 This will re-generate the search indexes for a tracker.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1539 This will typically happen automatically.
6957
f924af12ef50 issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents: 6818
diff changeset
1540 """
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1541 if args:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1542 for arg in args:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1543 m = desre.match(arg)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1544 if m:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1545 cl = self.get_class(m.group(1))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1546 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1547 cl.index(m.group(2))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1548 except IndexError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1549 raise UsageError(_('no such item "%(designator)s"') % {
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1550 'designator': arg})
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1551 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1552 cl = self.get_class(arg)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1553 self.db.reindex(arg)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1554 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1555 self.db.reindex(show_progress=True)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1556 return 0
6957
f924af12ef50 issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents: 6818
diff changeset
1557
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1558 def do_restore(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1559 ''"""Usage: restore designator[,designator]*
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1560 Restore the retired node specified by designator.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1561
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1562 A designator is a classname and a nodeid concatenated,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1563 eg. bug1, user10, ...
6957
f924af12ef50 issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents: 6818
diff changeset
1564
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1565 The given nodes will become available for users again.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1566 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1567 if len(args) < 1:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1568 raise UsageError(_('Not enough arguments supplied'))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1569 designators = args[0].split(',')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1570 for designator in designators:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1571 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1572 classname, nodeid = hyperdb.splitDesignator(designator)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1573 except hyperdb.DesignatorError as message:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1574 raise UsageError(message)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1575 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1576 dbclass = self.db.getclass(classname)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1577 except KeyError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1578 raise UsageError(_('no such class "%(classname)s"') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1579 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1580 dbclass.restore(nodeid)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1581 except KeyError as e:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1582 raise UsageError(e.args[0])
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1583 except IndexError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1584 raise UsageError(_('no such %(classname)s node '
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1585 '" % (nodeid)s"') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1586 self.db_uncommitted = True
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1587 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1588
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1589 def do_retire(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1590 ''"""Usage: retire designator[,designator]*
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1591 Retire the node specified by designator.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1592
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1593 A designator is a classname and a nodeid concatenated,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1594 eg. bug1, user10, ...
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1595
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1596 This action indicates that a particular node is not to be retrieved
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1597 by the list or find commands, and its key value may be re-used.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1598 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1599 if len(args) < 1:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1600 raise UsageError(_('Not enough arguments supplied'))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1601 designators = args[0].split(',')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1602 for designator in designators:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1603 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1604 classname, nodeid = hyperdb.splitDesignator(designator)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1605 except hyperdb.DesignatorError as message:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1606 raise UsageError(message)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1607 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1608 self.db.getclass(classname).retire(nodeid)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1609 except KeyError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1610 raise UsageError(_('no such class "%(classname)s"') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1611 except IndexError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1612 raise UsageError(_('no such %(classname)s node '
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1613 '"%(nodeid)s"') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1614 self.db_uncommitted = True
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1615 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1616
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1617 def do_rollback(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1618 ''"""Usage: rollback
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1619 Undo all changes that are pending commit to the database.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1620
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1621 The changes made during an interactive session are not
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1622 automatically written to the database - they must be committed
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1623 manually. This command undoes all those changes, so a commit
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1624 immediately after would make no changes to the database.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1625 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1626 self.db.rollback()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1627 self.db_uncommitted = False
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1628 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1629
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1630 def do_security(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1631 ''"""Usage: security [Role name]
6957
f924af12ef50 issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents: 6818
diff changeset
1632
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1633 Display the Permissions available to one or all Roles.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1634 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1635 if len(args) == 1:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1636 role = args[0]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1637 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1638 roles = [(args[0], self.db.security.role[args[0]])]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1639 except KeyError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1640 sys.stdout.write(_('No such Role "%(role)s"\n') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1641 return 1
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1642 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1643 roles = list(self.db.security.role.items())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1644 role = self.db.config.NEW_WEB_USER_ROLES
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1645 if ',' in role:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1646 sys.stdout.write(_('New Web users get the Roles "%(role)s"\n')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1647 % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1648 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1649 sys.stdout.write(_('New Web users get the Role "%(role)s"\n')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1650 % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1651 role = self.db.config.NEW_EMAIL_USER_ROLES
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1652 if ',' in role:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1653 sys.stdout.write(_('New Email users get the Roles "%(role)s"\n') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1654 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1655 sys.stdout.write(_('New Email users get the Role "%(role)s"\n') % locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1656 roles.sort()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1657 for _rolename, role in roles:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1658 sys.stdout.write(_('Role "%(name)s":\n') % role.__dict__)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1659 for permission in role.permissions:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1660 d = permission.__dict__
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1661 if permission.klass:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1662 if permission.properties:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1663 sys.stdout.write(_(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1664 ' %(description)s (%(name)s for "%(klass)s"' +
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1665 ': %(properties)s only)\n') % d)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1666 # verify that properties exist; report bad props
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1667 bad_props = []
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1668 cl = self.db.getclass(permission.klass)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1669 class_props = cl.getprops(protected=True)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1670 for p in permission.properties:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1671 if p in class_props:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1672 continue
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1673 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1674 bad_props.append(p)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1675 if bad_props:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1676 sys.stdout.write(_(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1677 '\n **Invalid properties for %(class)s: '
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1678 '%(props)s\n\n') % {
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1679 "class": permission.klass,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1680 "props": bad_props})
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1681 return 1
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1682 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1683 sys.stdout.write(_(' %(description)s (%(name)s for '
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1684 '"%(klass)s" only)\n') % d)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1685 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1686 sys.stdout.write(_(' %(description)s (%(name)s)\n') % d)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1687 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1688
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1689 def do_set(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1690 ''"""Usage: set items property=value property=value ...
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1691 Set the given properties of one or more items(s).
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1692
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1693 The items are specified as a class or as a comma-separated
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1694 list of item designators (ie "designator[,designator,...]").
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1695
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1696 A designator is a classname and a nodeid concatenated,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1697 eg. bug1, user10, ...
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1698
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1699 This command sets the properties to the values for all
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1700 designators given. If a class is used, the property will be
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1701 set for all items in the class. If the value is missing
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1702 (ie. "property=") then the property is un-set. If the property
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1703 is a multilink, you specify the linked ids for the multilink
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1704 as comma-separated numbers (ie "1,2,3").
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1705
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1706 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1707 import copy # needed for copying props list
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1708
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1709 if len(args) < 2:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1710 raise UsageError(_('Not enough arguments supplied'))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1711 from roundup import hyperdb
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1712
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1713 designators = args[0].split(',')
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1714 if len(designators) == 1:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1715 designator = designators[0]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1716 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1717 designator = hyperdb.splitDesignator(designator)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1718 designators = [designator]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1719 except hyperdb.DesignatorError:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1720 cl = self.get_class(designator)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1721 designators = [(designator, x) for x in cl.list()]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1722 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1723 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1724 designators = [hyperdb.splitDesignator(x) for x in designators]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1725 except hyperdb.DesignatorError as message:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1726 raise UsageError(message)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1727
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1728 # get the props from the args
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1729 propset = self.props_from_args(args[1:]) # parse the cli once
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1730
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1731 # now do the set for all the nodes
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1732 for classname, itemid in designators:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1733 props = copy.copy(propset) # make a new copy for every designator
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1734 cl = self.get_class(classname)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1735
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1736 for key, value in list(props.items()):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1737 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1738 # You must reinitialize the props every time though.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1739 # if props['nosy'] = '+admin' initally, it gets
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1740 # set to 'demo,admin' (assuming it was set to demo
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1741 # in the db) after rawToHyperdb returns.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1742 # This new value is used for all the rest of the
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1743 # designators if not reinitalized.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1744 props[key] = hyperdb.rawToHyperdb(self.db, cl, itemid,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1745 key, value)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1746 except hyperdb.HyperdbValueError as message:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1747 raise UsageError(message)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1748
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1749 # try the set
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1750 try:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1751 cl.set(itemid, **props)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1752 except (TypeError, IndexError, ValueError) as message:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1753 raise UsageError(message)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1754 self.db_uncommitted = True
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1755 return 0
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1756
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1757 def do_specification(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1758 ''"""Usage: specification classname
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1759 Show the properties for a classname.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1760
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1761 This lists the properties for a given class.
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1762 """
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1763 if len(args) < 1:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1764 raise UsageError(_('Not enough arguments supplied'))
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1765 classname = args[0]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1766 # get the class
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1767 cl = self.get_class(classname)
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1768
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1769 # get the key property
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1770 keyprop = cl.getkey()
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1771 for key in cl.properties:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1772 value = cl.properties[key]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1773 if keyprop == key:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1774 sys.stdout.write(_('%(key)s: %(value)s (key property)\n') %
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1775 locals())
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1776 else:
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1777 sys.stdout.write(_('%(key)s: %(value)s\n') % locals())
6957
f924af12ef50 issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents: 6818
diff changeset
1778
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1779 def do_table(self, args):
4073
145b32238093 Revert docstring markup for use with gettext tool.
Stefan Seefeld <stefan@seefeld.name>
parents: 4067
diff changeset
1780 ''"""Usage: table classname [property[,property]*]
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1781 List the instances of a class in tabular form.
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1782
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1783 Lists all instances of the given class. If the properties are not
2329
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
1784 specified, all properties are displayed. By default, the column
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
1785 widths are the width of the largest value. The width may be
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
1786 explicitly defined by defining the property as "name:width".
e128fd807054 fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2313
diff changeset
1787 For example::
2005
fc52d57c6c3e documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents: 1916
diff changeset
1788
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1789 roundup> table priority id,name:10
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1790 Id Name
2307
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
1791 1 fatal-bug
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
1792 2 bug
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
1793 3 usability
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
1794 4 feature
1544
6db2cbcd390e finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents: 1539
diff changeset
1795
6db2cbcd390e finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents: 1539
diff changeset
1796 Also to make the width of the column the width of the label,
2005
fc52d57c6c3e documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents: 1916
diff changeset
1797 leave a trailing : without a width on the property. For example::
fc52d57c6c3e documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents: 1916
diff changeset
1798
1544
6db2cbcd390e finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents: 1539
diff changeset
1799 roundup> table priority id,name:
6db2cbcd390e finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents: 1539
diff changeset
1800 Id Name
6db2cbcd390e finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents: 1539
diff changeset
1801 1 fata
2307
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
1802 2 bug
1544
6db2cbcd390e finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents: 1539
diff changeset
1803 3 usab
6db2cbcd390e finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents: 1539
diff changeset
1804 4 feat
6db2cbcd390e finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents: 1539
diff changeset
1805
6db2cbcd390e finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents: 1539
diff changeset
1806 will result in a the 4 character wide "Name" column.
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
1807 """
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1808 if len(args) < 1:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
1809 raise UsageError(_('Not enough arguments supplied'))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1810 classname = args[0]
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1811
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1812 # get the class
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1813 cl = self.get_class(classname)
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1814
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1815 # figure the property names to display
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1816 if len(args) > 1:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1817 prop_names = args[1].split(',')
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1818 all_props = cl.getprops()
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1819 for spec in prop_names:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1820 if ':' in spec:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1821 try:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1822 propname, width = spec.split(':')
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1823 except (ValueError, TypeError):
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
1824 raise UsageError(_('"%(spec)s" not '
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1825 'name:width') % locals())
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1826 else:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1827 propname = spec
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
1828 if propname not in all_props:
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
1829 raise UsageError(_('%(classname)s has no property '
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1830 '"%(propname)s"') % locals())
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1831 else:
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
1832 prop_names = cl.getprops()
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1833
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1834 # now figure column widths
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1835 props = []
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1836 for spec in prop_names:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1837 if ':' in spec:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1838 name, width = spec.split(':')
1546
Richard Jones <richard@users.sourceforge.net>
parents: 1544
diff changeset
1839 if width == '':
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1840 # spec includes trailing :, use label/name width
6198
39513b36ca59 Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents: 6195
diff changeset
1841 props.append((name, len(name)))
1546
Richard Jones <richard@users.sourceforge.net>
parents: 1544
diff changeset
1842 else:
6198
39513b36ca59 Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents: 6195
diff changeset
1843 try:
39513b36ca59 Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents: 6195
diff changeset
1844 props.append((name, int(width)))
39513b36ca59 Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents: 6195
diff changeset
1845 except ValueError:
39513b36ca59 Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents: 6195
diff changeset
1846 raise UsageError(_('"%(spec)s" does not have an '
39513b36ca59 Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents: 6195
diff changeset
1847 'integer width: "%(width)s"') %
39513b36ca59 Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents: 6195
diff changeset
1848 locals())
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1849 else:
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1850 # this is going to be slow
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1851 maxlen = len(spec)
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1852 for nodeid in cl.list():
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1853 curlen = len(str(cl.get(nodeid, spec)))
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1854 if curlen > maxlen:
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1855 maxlen = curlen
6198
39513b36ca59 Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents: 6195
diff changeset
1856 props.append((spec, maxlen))
2307
f786a1b9dbdf translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2215
diff changeset
1857
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1858 # now display the heading
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1859 print(' '.join([name.capitalize().ljust(width)
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1860 for name, width in props]))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1861
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1862 # and the table data
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1863 for nodeid in cl.list():
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1864 table_columns = []
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1865 for name, width in props:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1866 if name != 'id':
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1867 try:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1868 value = str(cl.get(nodeid, name))
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1869 except KeyError:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1870 # we already checked if the property is valid - a
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1871 # KeyError here means the node just doesn't have a
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1872 # value for it
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1873 value = ''
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1874 else:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1875 value = str(nodeid)
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1876 f = '%%-%ds' % width
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1877 table_columns.append(f % value[:width])
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1878 print(' '.join(table_columns))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1879 return 0
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1880
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1881 def do_templates(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1882 ''"""Usage: templates [trace_search]
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1883 List templates and their installed directories.
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1884
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1885 With trace_search also list all directories that are
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1886 searched for templates.
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
1887 """
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1888 import textwrap
6431
ada1edcc9132 issue2551142 - Import ... unique constraint failure.
John Rouillard <rouilj@ieee.org>
parents: 6430
diff changeset
1889
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1890 trace_search = False
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1891 if args and args[0] == "trace_search":
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1892 trace_search = True
3669
07d1d8e22271 new "exporttables" command in roundup-admin [SF#1533791]
Richard Jones <richard@users.sourceforge.net>
parents: 3641
diff changeset
1893
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1894 templates = self.listTemplates(trace_search=trace_search)
3179
88dbe6b3d891 merge removal of rcsv
Richard Jones <richard@users.sourceforge.net>
parents: 2998
diff changeset
1895
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1896 for name in sorted(list(templates.keys())):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1897 templates[name]['description'] = textwrap.fill(
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1898 "\n".join([line.lstrip() for line in
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1899 templates[name]['description'].split("\n")]),
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1900 70,
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1901 subsequent_indent=" "
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1902 )
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1903 print("""
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1904 Name: %(name)s
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1905 Path: %(path)s
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1906 Desc: %(description)s
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1907 """ % templates[name])
562
62febbd7ffec You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents: 529
diff changeset
1908
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1909 def do_updateconfig(self, args):
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1910 ''"""Usage: updateconfig <filename>
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1911 Generate an updated tracker config file (ini style) in
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1912 <filename>. Use current settings from existing roundup
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1913 tracker in tracker home.
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
1914 """
7250
ee972b3073cb alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents: 7249
diff changeset
1915 self.do_genconfig(args, update=True)
7209
c1227f883177 Implement password hash testing using new roundup-admin perftest.
John Rouillard <rouilj@ieee.org>
parents: 7207
diff changeset
1916
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1917 def run_command(self, args):
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
1918 """Run a single command
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
1919 """
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1920 command = args[0]
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1921
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1922 # handle help now
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1923 if command == 'help':
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1924 if len(args) > 1:
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1925 self.do_help(args[1:])
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1926 return 0
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1927 self.do_help(['help'])
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1928 return 0
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1929 if command == 'morehelp':
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1930 self.do_help(['help'])
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1931 self.help_commands()
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1932 self.help_all()
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1933 return 0
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1934
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1935 # figure what the command is
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1936 try:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1937 functions = self.commands.get(command)
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1938 except KeyError:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1939 # not a valid command
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
1940 print(_('Unknown command "%(command)s" ("help commands" for a '
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1941 'list)') % locals())
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1942 return 1
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1943
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1944 # check for multiple matches
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1945 if len(functions) > 1:
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1946 print(_('Multiple commands match "%(command)s": %(list)s') %
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1947 {'command': command,
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1948 'list': ', '.join([i[0] for i in functions])})
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1949 return 1
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1950 command, function = functions[0]
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1951
1098
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
1952 # make sure we have a tracker_home
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
1953 while not self.tracker_home:
5163
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
1954 if not self.force:
7182
0c6617db0b97 Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents: 7178
diff changeset
1955 self.tracker_home = self.my_input(_('Enter tracker home: ')).strip()
5163
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
1956 else:
6ae426092d7d Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents: 5110
diff changeset
1957 self.tracker_home = os.curdir
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1958
738
7e093cbaaa98 split instance initialisation into two steps...
Richard Jones <richard@users.sourceforge.net>
parents: 698
diff changeset
1959 # before we open the db, we may be doing an install or init
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1960 if command == 'initialise':
656
eae9b69a0115 [SF#527416] roundup-admin uses undefined value
Richard Jones <richard@users.sourceforge.net>
parents: 649
diff changeset
1961 try:
1098
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
1962 return self.do_initialise(self.tracker_home, args)
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1963 except UsageError as message: # noqa: F841
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1964 print(_('Error: %(message)s') % locals())
656
eae9b69a0115 [SF#527416] roundup-admin uses undefined value
Richard Jones <richard@users.sourceforge.net>
parents: 649
diff changeset
1965 return 1
738
7e093cbaaa98 split instance initialisation into two steps...
Richard Jones <richard@users.sourceforge.net>
parents: 698
diff changeset
1966 elif command == 'install':
7e093cbaaa98 split instance initialisation into two steps...
Richard Jones <richard@users.sourceforge.net>
parents: 698
diff changeset
1967 try:
1098
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
1968 return self.do_install(self.tracker_home, args)
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1969 except UsageError as message: # noqa: F841
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1970 print(_('Error: %(message)s') % locals())
738
7e093cbaaa98 split instance initialisation into two steps...
Richard Jones <richard@users.sourceforge.net>
parents: 698
diff changeset
1971 return 1
6957
f924af12ef50 issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents: 6818
diff changeset
1972 elif command == "templates":
f924af12ef50 issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents: 6818
diff changeset
1973 return self.do_templates(args[1:])
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1974
1098
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
1975 # get the tracker
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1976 try:
1098
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
1977 tracker = roundup.instance.open(self.tracker_home)
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1978 except ValueError as message: # noqa: F841
1098
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
1979 self.tracker_home = ''
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1980 print(_("Error: Couldn't open tracker: %(message)s") % locals())
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1981 return 1
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1982 except NoConfigError as message: # noqa: F841
5230
62a88d69ac52 Add new command updateconfig to admin command. This acts like
John Rouillard <rouilj@ieee.org>
parents: 5229
diff changeset
1983 self.tracker_home = ''
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
1984 print(_("Error: Couldn't open tracker: %(message)s") % locals())
5230
62a88d69ac52 Add new command updateconfig to admin command. This acts like
John Rouillard <rouilj@ieee.org>
parents: 5229
diff changeset
1985 return 1
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
1986 # message used via locals
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
1987 except ParsingOptionError as message: # noqa: F841
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6527
diff changeset
1988 print("%(message)s" % locals())
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6527
diff changeset
1989 return 1
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1990
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1991 # only open the database once!
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1992 if not self.db:
5979
33a7b10618a6 Add support for -u to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 5897
diff changeset
1993 self.db = tracker.open(self.name)
6658
408fd477761f Add i18n object to roundupdb.Database
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6585
diff changeset
1994 # dont use tracker.config["TRACKER_LANGUAGE"] here as the
408fd477761f Add i18n object to roundupdb.Database
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6585
diff changeset
1995 # cli operator likely wants to have i18n as set in the
408fd477761f Add i18n object to roundupdb.Database
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6585
diff changeset
1996 # environment.
408fd477761f Add i18n object to roundupdb.Database
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6585
diff changeset
1997 # This is needed to fetch the locale's of the tracker's home dir.
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
1998 self.db.i18n = get_translation(tracker_home=tracker.tracker_home)
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1999
4781
6e9b9743de89 Implementation for:
John Rouillard <rouilj@ieee.org>
parents: 4486
diff changeset
2000 self.db.tx_Source = 'cli'
6e9b9743de89 Implementation for:
John Rouillard <rouilj@ieee.org>
parents: 4486
diff changeset
2001
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2002 # do the command
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2003 ret = 0
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2004 try:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2005 ret = function(args[1:])
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
2006 except UsageError as message: # noqa: F841
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
2007 print(_('Error: %(message)s') % locals())
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
2008 print()
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
2009 print(function.__doc__)
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2010 ret = 1
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
2011 except Exception:
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2012 import traceback
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2013 traceback.print_exc()
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2014 ret = 1
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2015 return ret
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2016
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2017 def interactive(self):
4067
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
2018 """Run in an interactive mode
7309ac3b6e24 Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents: 4066
diff changeset
2019 """
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
2020 print(_('Roundup %s ready for input.\nType "help" for help.'
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
2021 % roundup_version))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2022 try:
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
2023 import readline # noqa: F401
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2024 except ImportError:
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
2025 print(_('Note: command history and editing not available'))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2026
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2027 while 1:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2028 try:
7182
0c6617db0b97 Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents: 7178
diff changeset
2029 command = self.my_input('roundup> ')
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2030 except EOFError:
5250
ac7fe3483206 Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents: 5248
diff changeset
2031 print(_('exit...'))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2032 break
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
2033 if not command: continue # noqa: E701
5245
bc16d91b7a50 Fix token_split() so its one error throws ValueError w/out extra arg.
Eric S. Raymond <esr@thyrsus.com>
parents: 5232
diff changeset
2034 try:
7178
db06d4aeb978 unshadow stdlib token from roundup's token.
John Rouillard <rouilj@ieee.org>
parents: 7093
diff changeset
2035 args = token_r.token_split(command)
5245
bc16d91b7a50 Fix token_split() so its one error throws ValueError w/out extra arg.
Eric S. Raymond <esr@thyrsus.com>
parents: 5232
diff changeset
2036 except ValueError:
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
2037 continue # Ignore invalid quoted token
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
2038 if not args: continue # noqa: E701
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
2039 if args[0] in ('quit', 'exit'): break # noqa: E701
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2040 self.run_command(args)
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2041
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2042 # exit.. check for transactions
3889
f7766d5ba962 fix [SF#297014]: roundup-admin interactive tracks uncommitted state
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3803
diff changeset
2043 if self.db and self.db_uncommitted:
7182
0c6617db0b97 Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents: 7178
diff changeset
2044 commit = self.my_input(_('There are unsaved changes. Commit them (y/N)? '))
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2045 if commit and commit[0].lower() == 'y':
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2046 self.db.commit()
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2047 return 0
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2048
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2049 def main(self):
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2050 try:
3637
31c79e3aa600 Fix verbose option for roundup-admin (for import and export)
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3602
diff changeset
2051 opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdsS:vV')
5248
198b6e810c67 Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents: 5245
diff changeset
2052 except getopt.GetoptError as e:
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2053 self.usage(str(e))
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2054 return 1
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2055
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2056 # handle command-line args
1098
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
2057 self.tracker_home = os.environ.get('TRACKER_HOME', '')
5979
33a7b10618a6 Add support for -u to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 5897
diff changeset
2058 self.name = 'admin'
33a7b10618a6 Add support for -u to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 5897
diff changeset
2059 self.password = '' # unused
4357
13b3155869e0 Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents: 4299
diff changeset
2060 if 'ROUNDUP_LOGIN' in os.environ:
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
2061 login_env = os.environ['ROUNDUP_LOGIN'].split(':')
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
2062 self.name = login_env[0]
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
2063 if len(login_env) > 1:
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
2064 self.password = login_env[1]
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
2065 self.separator = None
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
2066 self.print_designator = 0
3602
064515f658e8 verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
2067 self.verbose = 0
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2068 for opt, arg in opts:
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2069 if opt == '-h':
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2070 self.usage()
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2071 return 0
3602
064515f658e8 verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
2072 elif opt == '-v':
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
2073 print('%s (python %s)' % (roundup_version,
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
2074 sys.version.split()[0]))
2186
3f89c8ffe4f1 version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents: 2184
diff changeset
2075 return 0
3602
064515f658e8 verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
2076 elif opt == '-V':
064515f658e8 verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
2077 self.verbose = 1
064515f658e8 verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
2078 elif opt == '-i':
1098
c5819344714c more doc
Richard Jones <richard@users.sourceforge.net>
parents: 1096
diff changeset
2079 self.tracker_home = arg
3602
064515f658e8 verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
2080 elif opt == '-c':
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
2081 if self.separator is not None:
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
2082 self.usage('Only one of -c, -S and -s may be specified')
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
2083 return 1
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
2084 self.separator = ','
3602
064515f658e8 verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
2085 elif opt == '-S':
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
2086 if self.separator is not None:
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
2087 self.usage('Only one of -c, -S and -s may be specified')
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
2088 return 1
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
2089 self.separator = arg
3602
064515f658e8 verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
2090 elif opt == '-s':
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
2091 if self.separator is not None:
1676
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
2092 self.usage('Only one of -c, -S and -s may be specified')
4856faf558a2 Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents: 1652
diff changeset
2093 return 1
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
2094 self.separator = ' '
3602
064515f658e8 verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
2095 elif opt == '-d':
1566
053065585406 added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents: 1563
diff changeset
2096 self.print_designator = 1
5979
33a7b10618a6 Add support for -u to roundup-admin
John Rouillard <rouilj@ieee.org>
parents: 5897
diff changeset
2097 elif opt == '-u':
6585
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
2098 login_opt = arg.split(':')
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
2099 self.name = login_opt[0]
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
2100 if len(login_opt) > 1:
d4371b131c9c flake 8 improvements
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
2101 self.password = login_opt[1]
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2102
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2103 # if no command - go interactive
1133
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1108
diff changeset
2104 # wrap in a try/finally so we always close off the db
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2105 ret = 0
1133
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1108
diff changeset
2106 try:
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1108
diff changeset
2107 if not args:
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1108
diff changeset
2108 self.interactive()
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1108
diff changeset
2109 else:
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1108
diff changeset
2110 ret = self.run_command(args)
6959
3211745e8d7c flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6957
diff changeset
2111 if self.db: self.db.commit() # noqa: E701
1133
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1108
diff changeset
2112 return ret
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1108
diff changeset
2113 finally:
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1108
diff changeset
2114 if self.db:
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1108
diff changeset
2115 self.db.close()
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2116
6180
4f45ce95f016 pep8 changes.
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
2117
484
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2118 if __name__ == '__main__':
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2119 tool = AdminTool()
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2120 sys.exit(tool.main())
b35f229dd049 I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2121
2767
f6072f395f87 do_install: consider both old- and new-style layouts in reinstall check;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2736
diff changeset
2122 # vim: set filetype=python sts=4 sw=4 et si :

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