Mercurial > p > roundup > code
annotate roundup/admin.py @ 8566:e4191aa7b402 default tip
doc: issue2551415 correct doc for change input->input_payload
in 2.5 the rest interface changed a variable name from input to
input_payload. An earlier commit changed the rest docs. This commit
adds an item for it to the upgrading 2.4.0->2.5.0 section. Also cross
reference added to the rest docs with the updated examples.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 09 Apr 2026 00:19:06 -0400 |
| parents | 9c3ec0a5c7fc |
| children |
| rev | line source |
|---|---|
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
8296
4d3b371ed543
fix: issue1895197 - translated help texts in admin.py not displayed correctly.
John Rouillard <rouilj@ieee.org>
parents:
8240
diff
changeset
|
2 # -*- coding: utf-8 -*- |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3 # |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
4 # 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
|
5 # 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
|
6 # 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
|
7 # disclaimer are retained in their original form. |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
8 # |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
9 # 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
|
10 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
11 # 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
|
12 # POSSIBILITY OF SUCH DAMAGE. |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
13 # |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
14 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
15 # 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
|
16 # 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
|
17 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
18 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
|
2307
f786a1b9dbdf
translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2215
diff
changeset
|
19 # |
|
1244
8dd4f736370b
merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents:
1230
diff
changeset
|
20 |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
21 """Administration commands for maintaining Roundup trackers. |
|
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
22 """ |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1916
diff
changeset
|
23 __docformat__ = 'restructuredtext' |
| 6959 | 24 import csv |
| 25 import getopt | |
| 26 import getpass | |
| 27 import operator | |
| 28 import os | |
| 29 import re | |
| 30 import shutil | |
| 31 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
|
32 |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
33 import roundup.instance |
|
773
6e6c63a57df9
[SF#569415] {version]]
Richard Jones <richard@users.sourceforge.net>
parents:
763
diff
changeset
|
34 from roundup import __version__ as roundup_version |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
35 from roundup import date, hyperdb, init, password, support, token_r |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
36 from roundup.anypy import scandir_ # noqa: F401 define os.scandir |
|
5401
4cf48ff01e04
Python 3 preparation: replace raw_input uses.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5250
diff
changeset
|
37 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
|
38 from roundup.anypy.strings import repr_export |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
39 from roundup.configuration import ( |
|
8540
e8d1da6e3571
bug: fix traceback in roundup-admin init with bad config values
John Rouillard <rouilj@ieee.org>
parents:
8487
diff
changeset
|
40 ConfigurationError, |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
41 CoreConfig, |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
42 NoConfigError, |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
43 Option, |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
44 OptionUnsetError, |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
45 OptionValueError, |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
46 ParsingOptionError, |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
47 UserConfig, |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
48 ) |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
49 from roundup.exceptions import UsageError |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
50 from roundup.i18n import _, get_translation |
|
8487
b09ef85f0da6
feat: add nanoid pkg trace_id gen and decorator for setting processName
John Rouillard <rouilj@ieee.org>
parents:
8472
diff
changeset
|
51 from roundup.logcontext import gen_trace_id, set_processName, store_trace_reason |
|
5250
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
52 |
|
5455
118f5ffd194e
import UserDict from collections or UserDict
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5414
diff
changeset
|
53 try: |
|
118f5ffd194e
import UserDict from collections or UserDict
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5414
diff
changeset
|
54 from UserDict import UserDict |
|
118f5ffd194e
import UserDict from collections or UserDict
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5414
diff
changeset
|
55 except ImportError: |
|
118f5ffd194e
import UserDict from collections or UserDict
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5414
diff
changeset
|
56 from collections import UserDict |
|
118f5ffd194e
import UserDict from collections or UserDict
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5414
diff
changeset
|
57 |
| 6180 | 58 |
|
8557
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
59 def _safe_os_getlogin(): |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
60 """Run os.getlogin handling OSError exception. |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
61 |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
62 Used when calling @store_trace_reason to add username to string. |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
63 """ |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
64 |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
65 try: |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
66 return os.getlogin() |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
67 except OSError: |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
68 return "--unknown--" |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
69 |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
70 |
|
5455
118f5ffd194e
import UserDict from collections or UserDict
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5414
diff
changeset
|
71 class CommandDict(UserDict): |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
72 """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
|
73 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
74 Original code submitted by Engelbert Gruber. |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
75 """ |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
76 _marker = ('CommandDictMarker') |
| 6180 | 77 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
78 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
|
79 if key in self.data: |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
80 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
|
81 keylist = sorted(self.data) |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
82 |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
83 matching_keys = [(ki, self.data[ki]) for ki in keylist |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
84 if ki.startswith(key)] |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
85 |
| 6585 | 86 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
|
87 raise KeyError(key) |
| 6585 | 88 # FIXME: what happens if default is not self._marker but |
| 89 # there are no matching keys? Should (default, self.data[default]) | |
| 90 # be returned??? | |
| 91 return matching_keys | |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
92 |
| 6180 | 93 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
94 class AdminTool: |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
95 """ A collection of methods used in maintaining Roundup trackers. |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
96 |
|
1244
8dd4f736370b
merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents:
1230
diff
changeset
|
97 Typically these methods are accessed through the roundup-admin |
|
8dd4f736370b
merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents:
1230
diff
changeset
|
98 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
|
99 loop for the roundup-admin script. |
|
8dd4f736370b
merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents:
1230
diff
changeset
|
100 |
|
8dd4f736370b
merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents:
1230
diff
changeset
|
101 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
|
102 given in the method docstring. |
|
8dd4f736370b
merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents:
1230
diff
changeset
|
103 |
|
8dd4f736370b
merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents:
1230
diff
changeset
|
104 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
|
105 """ |
|
7182
0c6617db0b97
Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents:
7178
diff
changeset
|
106 |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
107 # import here to make AdminTool.readline accessible or |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
108 # mockable from tests. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
109 try: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
110 import readline # noqa: I001, PLC0415 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
111 except ImportError: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
112 readline = None |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
113 |
|
7182
0c6617db0b97
Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents:
7178
diff
changeset
|
114 # 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
|
115 # 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
|
116 # 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
|
117 my_input = my_input |
|
0c6617db0b97
Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents:
7178
diff
changeset
|
118 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
119 def __init__(self): |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
120 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
|
121 for k in AdminTool.__dict__: |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
122 if k[:3] == 'do_': |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
123 self.commands[k[3:]] = getattr(self, k) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
124 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
|
125 for k in AdminTool.__dict__: |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
126 if k[:5] == 'help_': |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
127 self.help[k[5:]] = getattr(self, k) |
|
7253
393ae88bf7b1
Cache result of tracker open in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7252
diff
changeset
|
128 self.tracker = None |
| 1098 | 129 self.tracker_home = '' |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
130 self.db = None |
|
3889
f7766d5ba962
fix [SF#297014]: roundup-admin interactive tracks uncommitted state
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3803
diff
changeset
|
131 self.db_uncommitted = False |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
132 self._default_savepoint_setting = 10000 |
|
5163
6ae426092d7d
Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents:
5110
diff
changeset
|
133 self.force = None |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
134 self.settings = { |
|
7549
73dfa9df9fb0
issue685275 - show retired/unretired items in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7547
diff
changeset
|
135 'display_header': False, |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
136 'display_protected': False, |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
137 'indexer_backend': "as set in config.ini", |
|
7802
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
138 'history_features': 0, |
|
7795
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
139 'history_length': -1, |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
140 '_reopen_tracker': False, |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
141 'savepoint_limit': self._default_savepoint_setting, |
|
7547
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
142 'show_retired': "no", |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
143 '_retired_val': False, |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
144 'verbose': False, |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
145 '_inttest': 3, |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
146 '_floattest': 3.5, |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
147 } |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
148 self.settings_help = { |
|
7549
73dfa9df9fb0
issue685275 - show retired/unretired items in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7547
diff
changeset
|
149 'display_header': |
|
7668
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
150 _("Have 'display designator[,designator*]' show header inside\n" |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
151 " []'s before items. Includes retired/active status.\n"), |
|
7549
73dfa9df9fb0
issue685275 - show retired/unretired items in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7547
diff
changeset
|
152 |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
153 'display_protected': |
|
7668
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
154 _("Have 'display designator' and 'specification class' show\n" |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
155 " protected fields: creator, id etc.\n"), |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
156 |
|
7802
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
157 'history_features': |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
158 _("Controls history options. It is a bitstring where setting\n" |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
159 " the bit disables the feature. A value of 0 (default)\n" |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
160 " enables all features. Value 1 disables loading of\n" |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
161 " history. Value 2 disables saving history. Value 4\n" |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
162 " disables loading init file. Since it is a bitstring a\n" |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
163 " value of 6 disables both loading init file and saving\n" |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
164 " history.\n"), |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
165 |
|
7796
5f3b49bb7742
add missing help text for history_length pragma. Also don't crash report missing text if text is missing
John Rouillard <rouilj@ieee.org>
parents:
7795
diff
changeset
|
166 'history_length': |
|
5f3b49bb7742
add missing help text for history_length pragma. Also don't crash report missing text if text is missing
John Rouillard <rouilj@ieee.org>
parents:
7795
diff
changeset
|
167 _("Set the number of lines of history to keep for this session.\n" |
|
5f3b49bb7742
add missing help text for history_length pragma. Also don't crash report missing text if text is missing
John Rouillard <rouilj@ieee.org>
parents:
7795
diff
changeset
|
168 " -1 is infinite.\n"), |
|
5f3b49bb7742
add missing help text for history_length pragma. Also don't crash report missing text if text is missing
John Rouillard <rouilj@ieee.org>
parents:
7795
diff
changeset
|
169 |
| 7300 | 170 'indexer_backend': |
|
7668
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
171 _("Set indexer to use when running 'reindex' NYI\n"), |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
172 |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
173 '_reopen_tracker': |
|
7668
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
174 _("Force reopening of tracker when running each command.\n"), |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
175 |
|
7668
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
176 'savepoint_limit': |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
177 _("set the number of rows imported before a database commit is\n" |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
178 " done. Used only for imports on PostgreSQL.\n"), |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
179 'show_retired': _("Show retired items in table, list etc. " |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
180 "One of 'no', 'only', 'both'\n"), |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
181 '_retired_val': _("internal mapping for show_retired.\n"), |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
182 'verbose': _("Enable verbose output: tracing, descriptions...\n"), |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
183 |
|
7668
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
184 '_inttest': "Integer valued setting. For testing only.\n", |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
185 '_floattest': "Float valued setting. For testing only.\n", |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
186 } |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
187 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
188 def get_class(self, classname): |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
189 """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
|
190 """ |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
191 try: |
|
489
5db2dad23f09
[SF#500140] AdminTool.get_class() returns nothing
Richard Jones <richard@users.sourceforge.net>
parents:
484
diff
changeset
|
192 return self.db.getclass(classname) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
193 except KeyError: |
| 6180 | 194 raise UsageError(_('no such class "%(classname)s"') % locals()) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
195 |
|
649
29f7e41ee437
Ran it through pychecker, made fixes
Richard Jones <richard@users.sourceforge.net>
parents:
626
diff
changeset
|
196 def props_from_args(self, args): |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
197 """ 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
|
198 |
|
8dd4f736370b
merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents:
1230
diff
changeset
|
199 The args list is specified as ``prop=value prop=value ...``. |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
200 A missing value is recorded as None. |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
201 """ |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
202 props = {} |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
203 for arg in args: |
| 6585 | 204 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
|
205 # if = not in string, will return one element |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
206 if len(key_val) != 2: |
| 6180 | 207 raise UsageError(_('argument "%(arg)s" not propname=value') % |
| 208 locals()) | |
| 6585 | 209 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
|
210 if value: |
|
b0de30171e57
implemented set for all items in a class, and unset
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
211 props[key] = value |
|
b0de30171e57
implemented set for all items in a class, and unset
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
212 else: |
|
b0de30171e57
implemented set for all items in a class, and unset
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
213 props[key] = None |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
214 return props |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
215 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
216 def usage(self, message=''): |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
217 """ Display a simple usage message. |
|
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
218 """ |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
219 if message: |
| 6585 | 220 message = _('Problem: %(message)s\n\n') % locals() |
| 6180 | 221 sys.stdout.write(_("""%(message)sUsage: roundup-admin [options] [<command> <arguments>] |
| 1098 | 222 |
| 223 Options: | |
| 224 -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
|
225 -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
|
226 -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
|
227 -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
|
228 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
|
229 -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
|
230 -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
|
231 Same as '-S " "'. |
|
7546
534f8bdb8f94
Add -P pragma=value command line option to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7545
diff
changeset
|
232 -P pragma=value -- Set a pragma on command line rather than interactively. |
|
534f8bdb8f94
Add -P pragma=value command line option to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7545
diff
changeset
|
233 Can be used multiple times. |
|
3602
064515f658e8
verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents:
3544
diff
changeset
|
234 -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
|
235 -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
|
236 |
|
053065585406
added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents:
1563
diff
changeset
|
237 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
|
238 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
239 Help: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
240 roundup-admin -h |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
241 roundup-admin help -- this help |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
242 roundup-admin help <command> -- command-specific help |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
243 roundup-admin help all -- all available help |
| 6180 | 244 """) % locals()) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
245 self.help_commands() |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
246 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
247 def help_commands(self): |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
248 """List the commands available with their help summary. |
|
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
249 """ |
| 6180 | 250 sys.stdout.write(_('Commands: ')) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
251 commands = [''] |
|
5250
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
252 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
|
253 h = _(command.__doc__).split('\n')[0] |
|
8296
4d3b371ed543
fix: issue1895197 - translated help texts in admin.py not displayed correctly.
John Rouillard <rouilj@ieee.org>
parents:
8240
diff
changeset
|
254 # ascii colon and space, U+003A ':' as ascii repr (for |
|
4d3b371ed543
fix: issue1895197 - translated help texts in admin.py not displayed correctly.
John Rouillard <rouilj@ieee.org>
parents:
8240
diff
changeset
|
255 # Chinese locales), 'fallback' |
|
4d3b371ed543
fix: issue1895197 - translated help texts in admin.py not displayed correctly.
John Rouillard <rouilj@ieee.org>
parents:
8240
diff
changeset
|
256 for seq in [': ', '\uff1a', 'fallback']: |
|
4d3b371ed543
fix: issue1895197 - translated help texts in admin.py not displayed correctly.
John Rouillard <rouilj@ieee.org>
parents:
8240
diff
changeset
|
257 if seq == 'fallback': |
|
4d3b371ed543
fix: issue1895197 - translated help texts in admin.py not displayed correctly.
John Rouillard <rouilj@ieee.org>
parents:
8240
diff
changeset
|
258 # command hasn't been printed yet so ... |
|
4d3b371ed543
fix: issue1895197 - translated help texts in admin.py not displayed correctly.
John Rouillard <rouilj@ieee.org>
parents:
8240
diff
changeset
|
259 commands.append(' ' + h.lstrip()) |
|
4d3b371ed543
fix: issue1895197 - translated help texts in admin.py not displayed correctly.
John Rouillard <rouilj@ieee.org>
parents:
8240
diff
changeset
|
260 break |
|
4d3b371ed543
fix: issue1895197 - translated help texts in admin.py not displayed correctly.
John Rouillard <rouilj@ieee.org>
parents:
8240
diff
changeset
|
261 if seq in h: |
|
4d3b371ed543
fix: issue1895197 - translated help texts in admin.py not displayed correctly.
John Rouillard <rouilj@ieee.org>
parents:
8240
diff
changeset
|
262 commands.append(' ' + h.split(seq, 1)[1].lstrip()) |
|
4d3b371ed543
fix: issue1895197 - translated help texts in admin.py not displayed correctly.
John Rouillard <rouilj@ieee.org>
parents:
8240
diff
changeset
|
263 break |
|
8472
224ccb8b49ca
refactor: change some classes to use __slots__
John Rouillard <rouilj@ieee.org>
parents:
8446
diff
changeset
|
264 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
265 commands.sort() |
|
2307
f786a1b9dbdf
translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2215
diff
changeset
|
266 commands.append(_( |
|
f786a1b9dbdf
translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2215
diff
changeset
|
267 """Commands may be abbreviated as long as the abbreviation |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
268 matches only one command, e.g. l == li == lis == list.""")) |
|
5110
87b0358790ed
Adding some tests for admin.py. Specifically for issue2550572: setting
John Rouillard <rouilj@ieee.org>
parents:
5104
diff
changeset
|
269 sys.stdout.write('\n'.join(commands) + '\n\n') |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
270 |
| 6959 | 271 indent_re = re.compile(r'^(\s+)\S+') |
| 272 | |
| 273 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
|
274 """ Produce an HTML command list. |
|
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
275 """ |
|
5250
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
276 commands = sorted(iter(self.commands.values()), |
| 6180 | 277 key=operator.attrgetter('__name__')) |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
278 print("<table>") |
|
1244
8dd4f736370b
merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents:
1230
diff
changeset
|
279 for command in commands: |
|
2307
f786a1b9dbdf
translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2215
diff
changeset
|
280 h = _(command.__doc__).split('\n') |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
281 name = command.__name__[3:] |
|
8393
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
282 # first line is "<name> <params and stuff> |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
283 usage = h[0][len(name) + 1:].replace('<','<').replace('>','>')[7:] |
|
5250
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
284 print(""" |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
285 <tr><td valign=top><strong>%(name)s</strong></td> |
|
8393
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
286 <td><p><tt>%(usage)s</tt></p> |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
287 """ % locals()) |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
288 indent = indent_re.match(h[1]) |
| 6959 | 289 if indent: indent = len(indent.group(1)) # noqa: E701 |
|
8393
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
290 lines_to_process = len(h[1:]) |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
291 print('<p>') |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
292 for lineno, line in enumerate(h[1:]): |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
293 line = line.replace('<','<').replace('>','>') |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
294 if indent: |
|
8393
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
295 clean_line = line[indent:] |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
296 else: |
|
8393
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
297 clean_line = line |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
298 if not clean_line: |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
299 print('</p><p>') |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
300 continue |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
301 if clean_line.startswith(' '): # indented example line |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
302 print("<pre>%s</pre>" % clean_line) |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
303 else: |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
304 print(clean_line) |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
305 if lineno == lines_to_process: |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
306 print('</p>') |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
307 print('</td></tr>\n') |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
308 print("</table>") |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
309 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
310 def help_all(self): |
|
5250
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
311 print(_(""" |
|
2329
e128fd807054
fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2313
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 or on the command line as "-i tracker". |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
318 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
319 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
|
320 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
321 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
|
322 printed results: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
323 . Strings are, well, strings. |
|
2329
e128fd807054
fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2313
diff
changeset
|
324 . 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
|
325 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
|
326 below. |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
327 . 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
|
328 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
|
329 . 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
|
330 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
|
331 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
|
332 of nodes joined by commas is accepted. |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
333 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
334 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
|
335 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
|
336 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
|
337 quotes. Examples: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
338 hello world (2 tokens: hello, world) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
339 "hello world" (1 token: hello world) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
340 "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
|
341 Roch\\'e Compaan (2 tokens: Roch'e Compaan) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
342 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
|
343 \\\\ (1 token: \\) |
|
e128fd807054
fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2313
diff
changeset
|
344 \\n\\r\\t (1 token: a newline, carriage-return and tab) |
|
7859
9a74dfeb8620
feat: can use escaped tokens inside quotes including quotes.
John Rouillard <rouilj@ieee.org>
parents:
7847
diff
changeset
|
345 f "test\\"q" (2 tokens: f test"q) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
346 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
347 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
|
348 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
|
349 nodes. |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
350 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
351 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
|
352 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
|
353 the -c) option. |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
354 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
355 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
|
356 login may be specified as either "name" or "name:password". |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
357 . ROUNDUP_LOGIN environment variable |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
358 . the -u command-line option |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
359 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
|
360 command-line. (See admin guide before using -u.) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
361 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
362 Date format examples: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
363 "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
|
364 "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
|
365 "01-25" means <Date yyyy-01-25.00:00:00> |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
366 "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
|
367 "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
|
368 "14:25" means <Date yyyy-mm-dd.19:25:00> |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
369 "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
|
370 "." means "right now" |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
371 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
372 Command help: |
|
5250
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
373 """)) |
|
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
374 for name, command in list(self.commands.items()): |
| 6180 | 375 print(_('%s:') % name) |
|
5250
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
376 print(' ', _(command.__doc__)) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
377 |
| 6959 | 378 nl_re = re.compile('[\r\n]') |
| 379 # indent_re defined above | |
| 380 | |
|
6957
f924af12ef50
issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents:
6818
diff
changeset
|
381 def listTemplates(self, trace_search=False): |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
382 """ List all the available templates. |
|
1591
21312a7564fd
moving templates around
Richard Jones <richard@users.sourceforge.net>
parents:
1570
diff
changeset
|
383 |
|
1863
d2ad3309c415
Clarify listTemplates docstring...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1775
diff
changeset
|
384 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
|
385 |
|
3894
44f2158fe76e
Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3889
diff
changeset
|
386 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
|
387 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
|
388 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
|
389 2. <prefix>/share/roundup/templates/* |
|
1863
d2ad3309c415
Clarify listTemplates docstring...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1775
diff
changeset
|
390 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
|
391 installed using setup.py without a prefix |
|
6527
5ad7fb912227
issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents:
6524
diff
changeset
|
392 3. <roundup.admin.__file__>/../../<sys.prefix>/share/\ |
|
5ad7fb912227
issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents:
6524
diff
changeset
|
393 roundup/templates/* which is where they will be found if |
|
5ad7fb912227
issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents:
6524
diff
changeset
|
394 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
|
395 4. <current working dir>/* |
|
1863
d2ad3309c415
Clarify listTemplates docstring...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1775
diff
changeset
|
396 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
|
397 5. <current working dir> |
|
1863
d2ad3309c415
Clarify listTemplates docstring...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1775
diff
changeset
|
398 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
|
399 """ |
|
1591
21312a7564fd
moving templates around
Richard Jones <richard@users.sourceforge.net>
parents:
1570
diff
changeset
|
400 # 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
|
401 # and <egg-directory>/share/roundup/templates |
|
1591
21312a7564fd
moving templates around
Richard Jones <richard@users.sourceforge.net>
parents:
1570
diff
changeset
|
402 # -- 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
|
403 # like: |
|
3894
44f2158fe76e
Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3889
diff
changeset
|
404 # /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
|
405 # 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
|
406 # /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
|
407 # (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
|
408 # |
|
44f2158fe76e
Marek Kubica's patch to find templates installed by easy_install
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3889
diff
changeset
|
409 # 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
|
410 debug = False |
|
1652
7fb3bf18babb
attempt to fix the template finding
Richard Jones <richard@users.sourceforge.net>
parents:
1634
diff
changeset
|
411 templates = {} |
| 6959 | 412 if debug: print(__file__) # noqa: E701 |
|
4900
349a83aca61f
Correctly locate templates in a virtualenv (issue2550841)
John Kristensen <john@jerrykan.com>
parents:
4781
diff
changeset
|
413 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
|
414 path = __file__ |
|
7fb3bf18babb
attempt to fix the template finding
Richard Jones <richard@users.sourceforge.net>
parents:
1634
diff
changeset
|
415 # move up N elements in the path |
| 6180 | 416 for _i in range(N): |
|
1652
7fb3bf18babb
attempt to fix the template finding
Richard Jones <richard@users.sourceforge.net>
parents:
1634
diff
changeset
|
417 path = os.path.dirname(path) |
|
7fb3bf18babb
attempt to fix the template finding
Richard Jones <richard@users.sourceforge.net>
parents:
1634
diff
changeset
|
418 tdir = os.path.join(path, 'share', 'roundup', 'templates') |
| 6959 | 419 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
|
420 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
|
421 templates = init.listTemplates(tdir) |
| 6959 | 422 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
|
423 break |
|
1591
21312a7564fd
moving templates around
Richard Jones <richard@users.sourceforge.net>
parents:
1570
diff
changeset
|
424 |
|
6524
f961dbbc3573
issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents:
6491
diff
changeset
|
425 # 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
|
426 # install dir. E.G. a wheel install |
|
f961dbbc3573
issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents:
6491
diff
changeset
|
427 # 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
|
428 # to create a base path for searching. |
|
f961dbbc3573
issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents:
6491
diff
changeset
|
429 |
|
6527
5ad7fb912227
issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents:
6524
diff
changeset
|
430 import sys |
|
5ad7fb912227
issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents:
6524
diff
changeset
|
431 # __file__ should be something like: |
|
5ad7fb912227
issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents:
6524
diff
changeset
|
432 # /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
|
433 # 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
|
434 # strip leading / to make os.path.join work right. |
|
6527
5ad7fb912227
issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents:
6524
diff
changeset
|
435 path = __file__ |
| 6585 | 436 for _N in 1, 2: |
|
6527
5ad7fb912227
issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents:
6524
diff
changeset
|
437 path = os.path.dirname(path) |
|
5ad7fb912227
issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents:
6524
diff
changeset
|
438 # path is /usr/local/lib/python3.10/site-packages |
|
5ad7fb912227
issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents:
6524
diff
changeset
|
439 tdir = os.path.join(path, sys.prefix[1:], 'share', |
|
5ad7fb912227
issue2551167 - update wheel support.
John Rouillard <rouilj@ieee.org>
parents:
6524
diff
changeset
|
440 'roundup', 'templates') |
| 6959 | 441 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
|
442 if os.path.isdir(tdir): |
|
f961dbbc3573
issue2551167 roundup issues when using pip install
John Rouillard <rouilj@ieee.org>
parents:
6491
diff
changeset
|
443 templates.update(init.listTemplates(tdir)) |
| 6585 | 444 |
|
6739
00fe67eb8a91
Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents:
6658
diff
changeset
|
445 try: |
|
00fe67eb8a91
Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents:
6658
diff
changeset
|
446 # 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
|
447 # 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
|
448 # 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
|
449 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
|
450 'roundup', 'templates') |
| 6959 | 451 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
|
452 if os.path.isdir(tdir): |
|
00fe67eb8a91
Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents:
6658
diff
changeset
|
453 templates.update(init.listTemplates(tdir)) |
| 6959 | 454 # 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
|
455 |
|
00fe67eb8a91
Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents:
6658
diff
changeset
|
456 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
|
457 'roundup', 'templates') |
| 6959 | 458 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
|
459 if os.path.isdir(tdir): |
|
00fe67eb8a91
Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents:
6658
diff
changeset
|
460 templates.update(init.listTemplates(tdir)) |
|
00fe67eb8a91
Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents:
6658
diff
changeset
|
461 except AttributeError: |
|
00fe67eb8a91
Update locations templates and locale files are stored
John Rouillard <rouilj@ieee.org>
parents:
6658
diff
changeset
|
462 pass # sys.base_prefix doesn't work under python2 |
|
1591
21312a7564fd
moving templates around
Richard Jones <richard@users.sourceforge.net>
parents:
1570
diff
changeset
|
463 |
|
1593
6318b21b0f73
more places to look for templates
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
464 # 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
|
465 templates.update(init.listTemplates(os.getcwd())) |
| 6959 | 466 if debug or trace_search: print(os.getcwd() + '/*') # noqa: E701 |
| 467 | |
|
1593
6318b21b0f73
more places to look for templates
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
468 # 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
|
469 template = init.loadTemplateInfo(os.getcwd()) |
| 6959 | 470 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
|
471 if template: |
| 6959 | 472 if debug: print(" Found template %s" % # noqa: E701 |
| 473 template['name']) | |
|
1593
6318b21b0f73
more places to look for templates
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
474 templates[template['name']] = template |
|
6318b21b0f73
more places to look for templates
Richard Jones <richard@users.sourceforge.net>
parents:
1591
diff
changeset
|
475 |
|
1591
21312a7564fd
moving templates around
Richard Jones <richard@users.sourceforge.net>
parents:
1570
diff
changeset
|
476 return templates |
|
21312a7564fd
moving templates around
Richard Jones <richard@users.sourceforge.net>
parents:
1570
diff
changeset
|
477 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
478 def help_initopts(self): |
|
1591
21312a7564fd
moving templates around
Richard Jones <richard@users.sourceforge.net>
parents:
1570
diff
changeset
|
479 templates = self.listTemplates() |
|
5250
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
480 print(_('Templates:'), ', '.join(templates)) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
481 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
|
482 backends = roundup.backends.list_backends() |
|
5250
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
483 print(_('Back ends:'), ', '.join(backends)) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
484 |
|
5163
6ae426092d7d
Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents:
5110
diff
changeset
|
485 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
|
486 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
|
487 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
|
488 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
|
489 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
|
490 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
|
491 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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
499 def do_commit(self, args): # noqa: ARG002 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
500 ''"""Usage: commit |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
501 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
|
502 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
503 The changes made during an interactive session are not |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
504 automatically written to the database - they must be committed |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
505 using this command. |
|
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 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
|
508 they are successful. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
509 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
510 self.db.commit() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
511 self.db_uncommitted = False |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
512 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
513 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
514 def do_create(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
515 ''"""Usage: create classname property=value ... |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
516 Create a new entry of a given class. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
517 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
518 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
|
519 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
|
520 command. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
521 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
522 if len(args) < 1: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
523 raise UsageError(_('Not enough arguments supplied')) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
524 from roundup import hyperdb |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
525 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
526 classname = args[0] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
527 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
528 # get the class |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
529 cl = self.get_class(classname) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
530 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
531 # now do a create |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
532 props = {} |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
533 properties = cl.getprops(protected=0) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
534 if len(args) == 1: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
535 # ask for the properties |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
536 for key in properties: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
537 if key == 'id': continue # noqa: E701 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
538 value = properties[key] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
539 name = value.__class__.__name__ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
540 if isinstance(value, hyperdb.Password): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
541 again = None |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
542 while value != again: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
543 value = getpass.getpass(_('%(propname)s (Password): ') |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
544 % |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
545 {'propname': key.capitalize()}) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
546 again = getpass.getpass(_(' %(propname)s (Again): ') |
|
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 {'propname': key.capitalize()}) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
549 if value != again: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
550 print(_('Sorry, try again...')) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
551 if value: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
552 props[key] = value |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
553 else: |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
554 value = self.my_input(_( |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
555 '%(propname)s (%(proptype)s): ') % { |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
556 'propname': key.capitalize(), 'proptype': name}) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
557 if value: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
558 props[key] = value |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
559 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
560 props = self.props_from_args(args[1:]) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
561 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
562 # convert types |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
563 try: |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
564 for propname in props: |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
565 props[propname] = hyperdb.rawToHyperdb(self.db, cl, None, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
566 propname, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
567 props[propname]) |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
568 except hyperdb.HyperdbValueError as message: |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
569 raise UsageError(message) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
570 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
571 # check for the key property |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
572 propname = cl.getkey() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
573 if propname and propname not in props: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
574 raise UsageError(_('you must provide the "%(propname)s" ' |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
575 'property.') % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
576 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
577 # do the actual create |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
578 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
579 sys.stdout.write(cl.create(**props) + '\n') |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
580 except (TypeError, IndexError, ValueError) as message: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
581 raise UsageError(message) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
582 self.db_uncommitted = True |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
583 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
584 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
585 def do_display(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
586 ''"""Usage: display designator[,designator]* |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
587 Show the property values for the given node(s). |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
588 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
589 A designator is a classname and a nodeid concatenated, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
590 eg. bug1, user10, ... |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
591 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
592 This lists the properties and their associated values |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
593 for the given node. |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
594 """ |
|
2889
accb3b411ef6
instructions and method for generating config.ini
Richard Jones <richard@users.sourceforge.net>
parents:
2856
diff
changeset
|
595 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
|
596 raise UsageError(_('Not enough arguments supplied')) |
|
7203
12a3cd86668f
auto update 'password_pbkdf2_default_rounds' "
John Rouillard <rouilj@ieee.org>
parents:
7182
diff
changeset
|
597 |
|
7588
8329b2227adb
fix: restore roundup-admin display output format w/o pragmas
John Rouillard <rouilj@ieee.org>
parents:
7566
diff
changeset
|
598 display_protected = self.settings['display_protected'] |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
599 display_header = self.settings['display_header'] |
|
7588
8329b2227adb
fix: restore roundup-admin display output format w/o pragmas
John Rouillard <rouilj@ieee.org>
parents:
7566
diff
changeset
|
600 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
601 # decode the node designator |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
602 for designator in args[0].split(','): |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
603 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
|
604 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
|
605 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
|
606 raise UsageError(message) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
607 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
608 # get the class |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
609 cl = self.get_class(classname) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
610 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
611 # display the values |
|
7543
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
612 normal_props = sorted(cl.properties) |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
613 |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
614 keys = sorted(cl.getprops()) if display_protected else normal_props |
|
7543
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
615 |
|
7588
8329b2227adb
fix: restore roundup-admin display output format w/o pragmas
John Rouillard <rouilj@ieee.org>
parents:
7566
diff
changeset
|
616 if display_header: |
|
7549
73dfa9df9fb0
issue685275 - show retired/unretired items in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7547
diff
changeset
|
617 status = "retired" if cl.is_retired(nodeid) else "active" |
|
73dfa9df9fb0
issue685275 - show retired/unretired items in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7547
diff
changeset
|
618 print('\n[%s (%s)]' % (designator, status)) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
619 for key in keys: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
620 value = cl.get(nodeid, key) |
|
7547
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
621 # prepend * for protected properties else just indent |
|
7543
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
622 # with space. |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
623 if display_protected or display_header: # noqa: SIM108 |
|
7588
8329b2227adb
fix: restore roundup-admin display output format w/o pragmas
John Rouillard <rouilj@ieee.org>
parents:
7566
diff
changeset
|
624 protected = "*" if key not in normal_props else ' ' |
|
8329b2227adb
fix: restore roundup-admin display output format w/o pragmas
John Rouillard <rouilj@ieee.org>
parents:
7566
diff
changeset
|
625 else: |
|
8329b2227adb
fix: restore roundup-admin display output format w/o pragmas
John Rouillard <rouilj@ieee.org>
parents:
7566
diff
changeset
|
626 protected = "" |
|
7543
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
627 print(_('%(protected)s%(key)s: %(value)s') % locals()) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
628 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
629 def do_export(self, args, export_files=True): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
630 ''"""Usage: export [[-]class[,class]] export_dir |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
631 Export the database and file content. |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
632 |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
633 Database content is exported to colon separated files. |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
634 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
|
635 use the exporttables command. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
636 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
637 Optionally limit the export to just the named classes |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
638 or exclude the named classes, if the 1st argument |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
639 starts with '-'. |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
640 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
641 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
|
642 colon-separated-value files that are placed in the nominated |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
643 export_dir directory. |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
644 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
645 # grab the directory to export to |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
646 if len(args) < 1: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
647 raise UsageError(_('Not enough arguments supplied')) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
648 |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
649 export_dir = args[-1] |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
650 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
651 # get the list of classes to export |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
652 if len(args) == 2: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
653 if args[0].startswith('-'): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
654 classes = [c for c in self.db.classes |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
655 if c not in args[0][1:].split(',')] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
656 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
657 classes = args[0].split(',') |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
658 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
659 classes = self.db.classes |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
660 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
661 class colon_separated(csv.excel): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
662 delimiter = ':' |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
663 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
664 # make sure target dir exists |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
665 if not os.path.exists(export_dir): |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
666 os.makedirs(export_dir) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
667 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
668 # maximum csv field length exceeding configured size? |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
669 max_len = self.db.config.CSV_FIELD_SIZE |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
670 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
671 # do all the classes specified |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
672 for classname in classes: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
673 cl = self.get_class(classname) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
674 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
675 if not export_files and hasattr(cl, 'export_files'): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
676 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
|
677 classname) |
|
1566
053065585406
added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents:
1563
diff
changeset
|
678 |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
679 with open(os.path.join(export_dir, classname + '.csv'), 'w') as f: |
|
7882
77c109725a7e
fix: import/export under windows.
John Rouillard <rouilj@ieee.org>
parents:
7869
diff
changeset
|
680 writer = csv.writer(f, colon_separated, lineterminator='\n') |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
681 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
682 propnames = cl.export_propnames() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
683 fields = propnames[:] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
684 fields.append('is retired') |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
685 writer.writerow(fields) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
686 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
687 # 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
|
688 # with retired nodes first. Retired nodes |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
689 # must occur before a non-retired node with |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
690 # the same key. Otherwise you get an |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
691 # IntegrityError: UNIQUE constraint failed: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
692 # _class.__retired__, _<class>._<keyname> |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
693 # on imports to rdbms. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
694 all_nodes = cl.getnodeids() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
695 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
696 classkey = cl.getkey() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
697 if classkey: # False sorts before True, so negate is_retired |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
698 keysort = lambda i: ( # noqa: E731 |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
699 cl.get(i, classkey), # noqa: B023 cl is not loop var |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
700 not cl.is_retired(i), # noqa: B023 cl is not loop var |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
701 ) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
702 all_nodes.sort(key=keysort) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
703 # if there is no classkey no need to sort |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
704 |
|
7847
d523d5c648e9
feat: add Progress output for admin export/exporttables
John Rouillard <rouilj@ieee.org>
parents:
7832
diff
changeset
|
705 for nodeid in support.Progress( "Exporting %s" % |
|
d523d5c648e9
feat: add Progress output for admin export/exporttables
John Rouillard <rouilj@ieee.org>
parents:
7832
diff
changeset
|
706 classname, all_nodes): |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
707 if self.verbose: |
|
7847
d523d5c648e9
feat: add Progress output for admin export/exporttables
John Rouillard <rouilj@ieee.org>
parents:
7832
diff
changeset
|
708 sys.stdout.write('\rExporting %s - %s ' % |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
709 (classname, nodeid)) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
710 sys.stdout.flush() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
711 node = cl.getnode(nodeid) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
712 exp = cl.export_list(propnames, nodeid) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
713 lensum = sum([len(repr_export(node[p])) for |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
714 p in propnames]) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
715 # 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
|
716 # 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
|
717 d = sum([len(x) for x in exp]) - lensum |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
718 if not d > 0: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
719 raise AssertionError("Bad assertion d > 0") |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
720 for p in propnames: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
721 ll = len(repr_export(node[p])) + d |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
722 if ll > max_len: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
723 max_len = ll |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
724 writer.writerow(exp) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
725 if export_files and hasattr(cl, 'export_files'): |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
726 cl.export_files(export_dir, nodeid) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
727 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
728 # export the journals |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
729 with open(os.path.join(export_dir, |
|
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
730 classname + '-journals.csv'), 'w') as jf: |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
731 if self.verbose: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
732 sys.stdout.write("\nExporting Journal for %s\n" % |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
733 classname) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
734 sys.stdout.flush() |
|
7882
77c109725a7e
fix: import/export under windows.
John Rouillard <rouilj@ieee.org>
parents:
7869
diff
changeset
|
735 journals = csv.writer(jf, colon_separated, lineterminator='\n') |
|
7847
d523d5c648e9
feat: add Progress output for admin export/exporttables
John Rouillard <rouilj@ieee.org>
parents:
7832
diff
changeset
|
736 for row in support.Progress(" Writing journals", |
|
d523d5c648e9
feat: add Progress output for admin export/exporttables
John Rouillard <rouilj@ieee.org>
parents:
7832
diff
changeset
|
737 cl.export_journals()): |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
738 journals.writerow(row) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
739 if max_len > self.db.config.CSV_FIELD_SIZE: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
740 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
|
741 max_len, file=sys.stderr) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
742 return 0 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
743 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
744 def do_exporttables(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
745 ''"""Usage: exporttables [[-]class[,class]] export_dir |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
746 Export only the database to files, no file content. |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
747 |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
748 Database content is exported to colon separated files. |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
749 The files below $TRACKER_HOME/db/files/ (which can be |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
750 archived separately) are not part of the export. |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
751 To include the files, use the export command. |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
752 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
753 Optionally limit the export to just the named classes |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
754 or exclude the named classes, if the 1st argument |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
755 starts with '-'. |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
756 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
757 This action exports the current data from the database into |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
758 colon-separated-value files that are placed in the export_dir |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
759 destination directory. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
760 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
761 return self.do_export(args, export_files=False) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
762 |
|
6176
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
763 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
|
764 ''"""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
|
765 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
|
766 |
|
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
767 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
|
768 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
|
769 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
|
770 '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
|
771 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
|
772 """ |
|
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
773 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
|
774 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
|
775 classname = args[0] |
|
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
776 # get the class |
|
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
777 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
|
778 |
|
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
779 # 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
|
780 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
|
781 |
|
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
782 # 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
|
783 # multiple , separated values become a list |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
784 for propname, prop_value in props.items(): |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
785 values = prop_value.split(',') if ',' in prop_value \ |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
786 else [prop_value] |
|
6176
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
787 |
|
6177
41907e1f9c3f
Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents:
6176
diff
changeset
|
788 props[propname] = [] |
|
6250
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
789 # start handling transitive props |
|
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
790 # 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
|
791 # start at issue |
|
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
792 curclass = cl |
| 6585 | 793 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
|
794 if '.' in propname: |
|
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
795 # 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
|
796 # 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
|
797 for pn in propname.split('.'): |
|
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
798 try: |
| 6585 | 799 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
|
800 # get classname for this link |
|
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
801 try: |
|
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
802 curclassname = curclass.getprops()[pn].classname |
|
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
803 except KeyError: |
| 6959 | 804 raise UsageError(_( |
| 805 "Class %(curclassname)s has " | |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
806 "no property %(pn)s in %(propname)s.") % |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
807 locals()) |
|
6250
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
808 # get class object |
|
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
809 curclass = self.get_class(curclassname) |
|
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
810 except AttributeError: |
|
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
811 # 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
|
812 # 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
|
813 pass |
|
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
814 |
|
6177
41907e1f9c3f
Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents:
6176
diff
changeset
|
815 for value in values: |
|
6250
95183d73ac64
issue2550522 - add transitive searching to filter in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
6208
diff
changeset
|
816 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
|
817 lastprop, value) |
|
6177
41907e1f9c3f
Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents:
6176
diff
changeset
|
818 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
|
819 |
|
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
820 # now do the filter |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
821 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
|
822 try: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
823 output_items = cl.filter(None, **props) |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
824 if self.print_designator: |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
825 output_items = [classname + i for i in output_items] |
|
6176
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
826 |
|
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
827 if self.separator: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
828 print(self.separator.join(output_items)) |
|
6176
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
829 else: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
830 print(output_items) |
|
6176
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
831 except KeyError: |
|
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
832 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
|
833 '"%(propname)s"') % locals()) |
|
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
834 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
|
835 raise UsageError(message) |
|
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
836 return 0 |
|
d25638d1826c
Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents:
6001
diff
changeset
|
837 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
838 def do_find(self, args): |
|
4073
145b32238093
Revert docstring markup for use with gettext tool.
Stefan Seefeld <stefan@seefeld.name>
parents:
4067
diff
changeset
|
839 ''"""Usage: find classname propname=value ... |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
840 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
|
841 |
|
2329
e128fd807054
fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2313
diff
changeset
|
842 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
|
843 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
|
844 value. |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
845 """ |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
846 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
|
847 raise UsageError(_('Not enough arguments supplied')) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
848 classname = args[0] |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
849 # get the class |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
850 cl = self.get_class(classname) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
851 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
852 # handle the propname=value argument |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
853 props = self.props_from_args(args[1:]) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
854 |
|
2494
ea7fb2f416db
fixed RDBMS Class.find() to handle None value in multiple find...
Richard Jones <richard@users.sourceforge.net>
parents:
2450
diff
changeset
|
855 # convert the user-input value to a value used for find() |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
856 for propname, prop_value in props.items(): |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
857 values = prop_value.split(',') if ',' in prop_value \ |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
858 else [prop_value] |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
859 |
|
2494
ea7fb2f416db
fixed RDBMS Class.find() to handle None value in multiple find...
Richard Jones <richard@users.sourceforge.net>
parents:
2450
diff
changeset
|
860 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
|
861 for value in values: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
862 val = hyperdb.rawToHyperdb(self.db, cl, None, |
| 6180 | 863 propname, value) |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
864 if isinstance(val, list): |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
865 for entry in val: |
|
3314
4372716a675a
merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents:
3295
diff
changeset
|
866 d[entry] = 1 |
|
4372716a675a
merge from maint-0-8
Richard Jones <richard@users.sourceforge.net>
parents:
3295
diff
changeset
|
867 else: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
868 d[val] = 1 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
869 |
|
2307
f786a1b9dbdf
translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2215
diff
changeset
|
870 # now do the find |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
871 try: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
872 output_items = cl.find(**props) |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
873 if self.print_designator: |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
874 output_items = [classname + i for i in output_items] |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
875 |
|
1566
053065585406
added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents:
1563
diff
changeset
|
876 if self.separator: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
877 print(self.separator.join(output_items)) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
878 else: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
879 print(output_items) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
880 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
|
881 raise UsageError(_('%(classname)s has no property ' |
| 6180 | 882 '"%(propname)s"') % locals()) |
|
5248
198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents:
5245
diff
changeset
|
883 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
|
884 raise UsageError(message) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
885 return 0 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
886 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
887 def do_genconfig(self, args, update=False): |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
888 ''"""Usage: genconfig filename |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
889 Create a new tracker config file with default values in filename. |
|
8393
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
890 See also updateconfig. |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
891 """ |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
892 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
|
893 raise UsageError(_('Not enough arguments supplied')) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
894 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
895 if update: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
896 # load current config for writing |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
897 config = CoreConfig(self.tracker_home) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
898 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
899 # change config to update settings to new defaults |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
900 # where prior defaults were chosen |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
901 default_ppdr = config._get_option( |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
902 'PASSWORD_PBKDF2_DEFAULT_ROUNDS')._default_value |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
903 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
904 print("") # put a blank line before feedback |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
905 if config.PASSWORD_PBKDF2_DEFAULT_ROUNDS in [10000]: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
906 print(_("Changing option\n" |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
907 " 'password_pbkdf2_default_rounds'\n" |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
908 "from old default of %(old_number)s to new " |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
909 "default of %(new_number)s.") % { |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
910 "old_number": |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
911 config.PASSWORD_PBKDF2_DEFAULT_ROUNDS, |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
912 "new_number": default_ppdr, |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
913 }) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
914 config.PASSWORD_PBKDF2_DEFAULT_ROUNDS = default_ppdr |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
915 |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
916 if default_ppdr > config.PASSWORD_PBKDF2_DEFAULT_ROUNDS: |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
917 print(_("Update " |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
918 "'password_pbkdf2_default_rounds' " |
|
7869
eb1fbbd53b6c
fix: roundup-admin updateconfig warn on mysql_{charset/collation} mismatch
John Rouillard <rouilj@ieee.org>
parents:
7859
diff
changeset
|
919 "to a number equal to or larger\n than %s.\n") % |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
920 default_ppdr) |
|
7869
eb1fbbd53b6c
fix: roundup-admin updateconfig warn on mysql_{charset/collation} mismatch
John Rouillard <rouilj@ieee.org>
parents:
7859
diff
changeset
|
921 |
|
eb1fbbd53b6c
fix: roundup-admin updateconfig warn on mysql_{charset/collation} mismatch
John Rouillard <rouilj@ieee.org>
parents:
7859
diff
changeset
|
922 if not config.RDBMS_MYSQL_COLLATION.startswith( |
|
eb1fbbd53b6c
fix: roundup-admin updateconfig warn on mysql_{charset/collation} mismatch
John Rouillard <rouilj@ieee.org>
parents:
7859
diff
changeset
|
923 config.RDBMS_MYSQL_CHARSET + "_"): |
|
eb1fbbd53b6c
fix: roundup-admin updateconfig warn on mysql_{charset/collation} mismatch
John Rouillard <rouilj@ieee.org>
parents:
7859
diff
changeset
|
924 print(_("Check the rdbms mysql_* settings. Your charset and " |
|
eb1fbbd53b6c
fix: roundup-admin updateconfig warn on mysql_{charset/collation} mismatch
John Rouillard <rouilj@ieee.org>
parents:
7859
diff
changeset
|
925 "collations may need\n" |
|
eb1fbbd53b6c
fix: roundup-admin updateconfig warn on mysql_{charset/collation} mismatch
John Rouillard <rouilj@ieee.org>
parents:
7859
diff
changeset
|
926 " to be changed. See upgrading instructions.\n")) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
927 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
928 # generate default config |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
929 config = CoreConfig() |
| 6191 | 930 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
931 config.save(args[0]) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
932 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
933 def do_get(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
934 ''"""Usage: get property designator[,designator]* |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
935 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
|
936 |
|
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
|
937 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
|
938 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
|
939 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
940 Retrieves the property value of the nodes specified |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
941 by the designators. |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
942 """ |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
943 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
|
944 raise UsageError(_('Not enough arguments supplied')) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
945 propname = args[0] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
946 designators = args[1].split(',') |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
947 linked_props = [] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
948 for designator in designators: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
949 # 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
|
950 try: |
|
053065585406
added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents:
1563
diff
changeset
|
951 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
|
952 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
|
953 raise UsageError(message) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
954 |
|
1676
4856faf558a2
Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents:
1652
diff
changeset
|
955 # get the class |
|
4856faf558a2
Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents:
1652
diff
changeset
|
956 cl = self.get_class(classname) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
957 try: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
958 if not (self.separator or self.print_designator): |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
959 print(cl.get(nodeid, propname)) |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
960 continue |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
961 |
|
7755
417c8ddc98ac
fix: undo last minute edit and try to get make checkin clean.
John Rouillard <rouilj@ieee.org>
parents:
7754
diff
changeset
|
962 properties = cl.getprops() |
|
417c8ddc98ac
fix: undo last minute edit and try to get make checkin clean.
John Rouillard <rouilj@ieee.org>
parents:
7754
diff
changeset
|
963 prop_obj = properties[propname] |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
964 if not (isinstance(prop_obj, |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
965 (hyperdb.Link, hyperdb.Multilink))): |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
966 raise UsageError(_( |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
967 'property %s is not of type' |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
968 ' Multilink or Link so -d flag does not ' |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
969 'apply.') % propname) |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
970 propclassname = self.db.getclass( |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
971 prop_obj.classname).classname |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
972 |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
973 output_items = cl.get(nodeid, propname) |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
974 if self.print_designator: |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
975 output_items = [propclassname + i for i in output_items] |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
976 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
977 if self.separator: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
978 print(self.separator.join(output_items)) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
979 else: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
980 # default is to list each on a line |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
981 print('\n'.join(output_items)) |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
982 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
983 except IndexError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
984 raise UsageError(_('no such %(classname)s node ' |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
985 '"%(nodeid)s"') % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
986 except KeyError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
987 raise UsageError(_('no such %(classname)s property ' |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
988 '"%(propname)s"') % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
989 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
990 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
991 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
|
992 ''"""Usage: help topic |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
993 Give help about topic. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
994 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
995 commands -- list commands |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
996 <command> -- help specific to a command |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
997 initopts -- init command options |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
998 all -- all available help |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
999 """ |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1000 topic = args[0] if len(args) > 0 else 'help' |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1001 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1002 # try help_ methods |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1003 if topic in self.help: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1004 self.help[topic]() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1005 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1006 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1007 # try command docstrings |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1008 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1009 cmd_docs = self.commands.get(topic) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1010 except KeyError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1011 print(_('Sorry, no help for "%(topic)s"') % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1012 return 1 |
|
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 # display the help for each match, removing the docstring indent |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1015 for _name, do_function in cmd_docs: |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1016 lines = nl_re.split(_(do_function.__doc__)) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1017 print(lines[0]) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1018 indent = indent_re.match(lines[1]) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1019 if indent: indent = len(indent.group(1)) # noqa: E701 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1020 for line in lines[1:]: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1021 if indent: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1022 print(line[indent:]) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1023 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1024 print(line) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1025 return 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 def do_history(self, args): |
|
7797
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1028 ''"""Usage: history designator [skipquiet] [raw] |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1029 Show the history entries of a designator. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1030 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1031 A designator is a classname and a nodeid concatenated, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1032 eg. bug1, user10, ... |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1033 |
|
7797
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1034 Lists the journal entries viewable by the user for the node |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1035 identified by the designator. If skipquiet is added, journal |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1036 entries for quiet properties are not shown. If raw is added, |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1037 the output is the raw representation of the journal entries. |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1038 """ |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1039 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1040 if len(args) < 1: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1041 raise UsageError(_('Not enough arguments supplied')) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1042 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1043 classname, nodeid = hyperdb.splitDesignator(args[0]) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1044 except hyperdb.DesignatorError as message: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1045 raise UsageError(message) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1046 |
|
7797
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1047 valid_args = ['skipquiet', 'raw'] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1048 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1049 if len(args) >= 2: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1050 check = [a for a in args[1:] if a not in valid_args] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1051 if check: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1052 raise UsageError( |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1053 _("Unexpected argument(s): %s. " |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1054 "Expected 'skipquiet' or 'raw'.") % ", ".join(check)) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1055 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1056 skipquiet = 'skipquiet' in args[1:] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1057 raw = 'raw' in args[1:] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1058 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1059 getclass = self.db.getclass |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
1060 |
|
7797
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1061 def get_prop_name(key, prop_name): |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1062 # getclass and classname from enclosing method |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1063 klass = getclass(classname) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1064 try: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1065 property_obj = klass.properties[prop_name] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1066 except KeyError: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1067 # the property has been removed from the schema. |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1068 return None |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1069 if isinstance(property_obj, |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1070 (hyperdb.Link, hyperdb.Multilink)): |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1071 prop_class = getclass(property_obj.classname) |
|
7800
2d4684e4702d
fix: enhancement to history command output and % template fix.
John Rouillard <rouilj@ieee.org>
parents:
7799
diff
changeset
|
1072 label_prop_name = prop_class.labelprop(default_to_id=True) |
|
2d4684e4702d
fix: enhancement to history command output and % template fix.
John Rouillard <rouilj@ieee.org>
parents:
7799
diff
changeset
|
1073 if label_prop_name not in ['id', 'title']: |
|
2d4684e4702d
fix: enhancement to history command output and % template fix.
John Rouillard <rouilj@ieee.org>
parents:
7799
diff
changeset
|
1074 # Don't return 'id', its value is the key. If name is |
|
2d4684e4702d
fix: enhancement to history command output and % template fix.
John Rouillard <rouilj@ieee.org>
parents:
7799
diff
changeset
|
1075 # empty, the caller will use the classname with the key |
|
2d4684e4702d
fix: enhancement to history command output and % template fix.
John Rouillard <rouilj@ieee.org>
parents:
7799
diff
changeset
|
1076 # as the identifier: show "issue23" not "23(23)". |
|
2d4684e4702d
fix: enhancement to history command output and % template fix.
John Rouillard <rouilj@ieee.org>
parents:
7799
diff
changeset
|
1077 # Also don't use the title. It's too long in most |
|
2d4684e4702d
fix: enhancement to history command output and % template fix.
John Rouillard <rouilj@ieee.org>
parents:
7799
diff
changeset
|
1078 # cases. show: "issue23" not "please help me with |
|
2d4684e4702d
fix: enhancement to history command output and % template fix.
John Rouillard <rouilj@ieee.org>
parents:
7799
diff
changeset
|
1079 # samba use athentication issue(23)" |
|
2d4684e4702d
fix: enhancement to history command output and % template fix.
John Rouillard <rouilj@ieee.org>
parents:
7799
diff
changeset
|
1080 return prop_class.get(key, label_prop_name) |
|
2d4684e4702d
fix: enhancement to history command output and % template fix.
John Rouillard <rouilj@ieee.org>
parents:
7799
diff
changeset
|
1081 # None indicates that there is no viable label_prop |
|
7797
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1082 return None |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1083 return None |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1084 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1085 def get_prop_class(prop_name): |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1086 # getclass and classname from enclosing method |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1087 klass = getclass(classname) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1088 try: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1089 property_obj = klass.properties[prop_name] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1090 except KeyError: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1091 # the property has been removed from the schema. |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1092 return None |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1093 if isinstance(property_obj, |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1094 (hyperdb.Link, hyperdb.Multilink)): |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1095 prop_class = getclass(property_obj.classname) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1096 return prop_class.classname |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1097 return None # it's not a link |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1098 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1099 def _format_tuple_change(data, prop): |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1100 ''' ('-', ['2', '4'] -> |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1101 "removed fred(2), jim(6)" |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1102 ''' |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1103 if data[0] == '-': |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1104 op = _("removed") |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1105 elif data[0] == '+': |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1106 op = _("added") |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1107 else: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1108 raise ValueError(_("Unknown history set operation '%s'. " |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1109 "Expected +/-.") % op) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1110 op_params = data[1] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1111 name = get_prop_name(op_params[0], prop) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1112 if name is not None: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1113 list_items = ["%s(%s)" % |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1114 (get_prop_name(o, prop), o) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1115 for o in op_params] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1116 else: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1117 propclass = get_prop_class(prop) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1118 if propclass: # noqa: SIM108 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1119 list_items = ["%s%s" % (propclass, o) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1120 for o in op_params] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1121 else: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1122 list_items = op_params |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1123 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1124 return "%s: %s" % (op, ", ".join(list_items)) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1125 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1126 def format_report_class(_data): |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1127 """Eat the empty data dictionary or None""" |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1128 return classname |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1129 |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
1130 def format_link(data): |
|
7797
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1131 '''data = ('issue', '157', 'dependson')''' |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1132 # .Hint added issue23 to superseder |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1133 f = _("added %(class)s%(item_id)s to %(propname)s") |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1134 return f % { |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1135 'class': data[0], 'item_id': data[1], 'propname': data[2]} |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1136 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1137 def format_set(data): |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1138 '''data = set {'fyi': None, 'priority': '5'} |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1139 set {'fyi': '....\ned through cleanly', 'priority': '3'} |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1140 ''' |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1141 result = [] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1142 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1143 # Note that set data is the old value. So don't use |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1144 # current/future tense in sentences. |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1145 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1146 for prop, value in data.items(): |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1147 if isinstance(value, str): |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1148 name = get_prop_name(value, prop) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1149 if name: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1150 result.append( |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1151 # .Hint read as: assignedto was admin(1) |
|
7821
aa1fd8704469
fix(i18n): clean up translator hint
John Rouillard <rouilj@ieee.org>
parents:
7802
diff
changeset
|
1152 # where assignedto is the property |
|
aa1fd8704469
fix(i18n): clean up translator hint
John Rouillard <rouilj@ieee.org>
parents:
7802
diff
changeset
|
1153 # admin is the key name for value 1 |
|
7800
2d4684e4702d
fix: enhancement to history command output and % template fix.
John Rouillard <rouilj@ieee.org>
parents:
7799
diff
changeset
|
1154 _("%(prop)s was %(name)s(%(value)s)") % { |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
1155 "prop": prop, "name": name, "value": value}) |
|
7797
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1156 else: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1157 # use repr so strings with embedded \n etc. don't |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1158 # generate newlines in output. Try to keep each |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1159 # journal entry on 1 line. |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1160 result.append(_("%(prop)s was %(value)s") % { |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1161 "prop": prop, "value": repr(value)}) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1162 elif isinstance(value, list): |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1163 # test to see if there is a key prop. |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1164 # Assumption, geting None here means no key |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1165 # is defined for the property's class. |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1166 name = get_prop_name(value[0], prop) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1167 if name is not None: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1168 list_items = ["%s(%s)" % |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1169 (get_prop_name(v, prop), v) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1170 for v in value] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1171 else: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1172 prop_class = get_prop_class(prop) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1173 if prop_class: # noqa: SIM108 |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
1174 list_items = ["%s%s" % (prop_class, v) |
|
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
1175 for v in value] |
|
7797
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1176 else: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1177 list_items = value |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1178 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1179 result.append(_("%(prop)s was [%(value_list)s]") % { |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1180 "prop": prop, "value_list": ", ".join(list_items)}) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1181 elif isinstance(value, tuple): |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1182 # operation data |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1183 decorated = [_format_tuple_change(data, prop) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1184 for data in value] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1185 result.append(# .Hint modified nosy: added demo(3) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1186 _("modified %(prop)s: %(how)s") % { |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1187 "prop": prop, "how": ", ".join(decorated)}) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1188 else: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1189 result.append(_("%(prop)s was %(value)s") % { |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1190 "prop": prop, "value": value}) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1191 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1192 return '; '.join(result) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1193 |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
1194 def format_unlink(data): |
|
7797
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1195 '''data = ('issue', '157', 'dependson')''' |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1196 return "removed %s%s from %s" % (data[0], data[1], data[2]) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1197 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1198 formatters = { |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1199 "create": format_report_class, |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1200 "link": format_link, |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1201 "restored": format_report_class, |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1202 "retired": format_report_class, |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1203 "set": format_set, |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1204 "unlink": format_unlink, |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1205 } |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1206 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1207 try: |
|
7797
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1208 # returns a tuple: ( |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1209 # [0] = nodeid |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1210 # [1] = date |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1211 # [2] = userid |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1212 # [3] = operation |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1213 # [4] = details |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1214 raw_history = self.db.getclass(classname).history(nodeid, |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1215 skipquiet=skipquiet) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1216 if raw: |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1217 print(raw_history) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1218 return 0 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1219 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1220 def make_readable(hist): |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1221 return "%s(%s) %s %s" % (self.db.user.get(hist[2], 'username'), |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1222 hist[1], |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1223 hist[3], |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1224 formatters.get(hist[3], lambda x: x)( |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1225 hist[4])) |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1226 printable_history = [make_readable(hist) for hist in raw_history] |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1227 |
|
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
1228 print("\n".join(printable_history)) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1229 except KeyError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1230 raise UsageError(_('no such class "%(classname)s"') % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1231 except IndexError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1232 raise UsageError(_('no such %(classname)s node ' |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1233 '"%(nodeid)s"') % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1234 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1235 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1236 def do_import(self, args, import_files=True): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1237 ''"""Usage: import import_dir |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
1238 Import a database and file contents from the directory. |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1239 |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
1240 The directory should have the same format as one containing |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
1241 the output of export. There are two files imported per class. |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1242 The files used in the import are: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1243 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1244 <class>.csv |
|
8393
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
1245 This must define the same properties as the class |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
1246 (including having a "header" line with those |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
1247 property names.) |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
1248 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1249 <class>-journals.csv |
|
8393
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
1250 This defines the journals for the items |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
1251 being imported. |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1252 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1253 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
|
1254 import file, thus replacing any existing content. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1255 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1256 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
|
1257 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
|
1258 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
|
1259 """ |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1260 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
|
1261 raise UsageError(_('Not enough arguments supplied')) |
|
7250
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 if hasattr(csv, 'field_size_limit'): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1264 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
|
1265 |
|
7668
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
1266 # default value is 10000, only go through this if default |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
1267 # is different. |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1268 if self.settings['savepoint_limit'] != self._default_savepoint_setting: |
|
7687
4dda4a9dfe0b
doc: add comment on method to set savepoint_limit dynamically
John Rouillard <rouilj@ieee.org>
parents:
7668
diff
changeset
|
1269 # create a new option on the fly in the config under the |
|
4dda4a9dfe0b
doc: add comment on method to set savepoint_limit dynamically
John Rouillard <rouilj@ieee.org>
parents:
7668
diff
changeset
|
1270 # rdbms section. It is used by the postgresql backend's |
|
4dda4a9dfe0b
doc: add comment on method to set savepoint_limit dynamically
John Rouillard <rouilj@ieee.org>
parents:
7668
diff
changeset
|
1271 # checkpoint_data method. |
|
7668
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
1272 self.db.config.add_option(Option(self.db.config, |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
1273 "rdbms", "savepoint_limit")) |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
1274 self.db.config.options["RDBMS_SAVEPOINT_LIMIT"].set( |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
1275 self.settings['savepoint_limit']) |
|
5b41018617f2
fix: out of memory error when importing under postgresql
John Rouillard <rouilj@ieee.org>
parents:
7650
diff
changeset
|
1276 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1277 # directory to import from |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1278 import_dir = args[0] |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1279 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1280 class colon_separated(csv.excel): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1281 delimiter = ':' |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1282 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1283 # import all the files |
|
8088
1045425c23b2
refactor!: replace os.listdir() with os.scandir()
John Rouillard <rouilj@ieee.org>
parents:
7998
diff
changeset
|
1284 for dir_entry in os.scandir(import_dir): |
|
1045425c23b2
refactor!: replace os.listdir() with os.scandir()
John Rouillard <rouilj@ieee.org>
parents:
7998
diff
changeset
|
1285 filename = dir_entry.name |
|
1045425c23b2
refactor!: replace os.listdir() with os.scandir()
John Rouillard <rouilj@ieee.org>
parents:
7998
diff
changeset
|
1286 classname, ext = os.path.splitext(filename) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1287 # we only care about CSV files |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1288 if ext != '.csv' or classname.endswith('-journals'): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1289 continue |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1290 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1291 cl = self.get_class(classname) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1292 |
|
8224
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1293 maxid = self.import_class(dir_entry.path, colon_separated, cl, |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1294 import_dir, import_files) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1295 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1296 # import the journals |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1297 with open(os.path.join(import_dir, classname + '-journals.csv'), 'r') as f: |
|
7882
77c109725a7e
fix: import/export under windows.
John Rouillard <rouilj@ieee.org>
parents:
7869
diff
changeset
|
1298 reader = csv.reader(f, colon_separated, lineterminator='\n') |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1299 cl.import_journals(reader) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1300 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1301 # (print to sys.stdout here to allow tests to squash it .. ugh) |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
1302 print('setting', classname, maxid + 1, file=sys.stdout) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1303 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1304 # set the id counter |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
1305 self.db.setid(classname, str(maxid + 1)) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1306 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1307 self.db_uncommitted = True |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1308 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1309 |
|
8224
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1310 def import_class(self, filepath, csv_format_class, hyperdb_class, |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1311 import_dir, import_files): |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1312 """Import class given csv class filepath, csv_format_class and |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1313 hyperdb_class, directory for import, and boolean to import |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1314 files. |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1315 |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1316 Optionally import files as well if import_files is True |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1317 otherwise just import database data. |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1318 |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1319 Returns: maxid seen in csv file |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1320 """ |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1321 |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1322 maxid = 1 |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1323 |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1324 # ensure that the properties and the CSV file headings match |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1325 with open(filepath, 'r') as f: |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1326 reader = csv.reader(f, csv_format_class, lineterminator='\n') |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1327 file_props = None |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1328 # loop through the file and create a node for each entry |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1329 for n, r in enumerate(reader): |
|
8541
7a7f6ee0a09e
bug: import/importables fail to set newid correctly.
John Rouillard <rouilj@ieee.org>
parents:
8540
diff
changeset
|
1330 # read the file header |
|
8224
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1331 if file_props is None: |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1332 file_props = r |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1333 continue |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1334 |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1335 if self.verbose: |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1336 sys.stdout.write('\rImporting %s - %s' % ( |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1337 hyperdb_class.classname, n)) |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1338 sys.stdout.flush() |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1339 |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1340 # do the import and figure the current highest nodeid |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1341 nodeid = hyperdb_class.import_list(file_props, r) |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1342 if hasattr(hyperdb_class, 'import_files') and import_files: |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1343 hyperdb_class.import_files(import_dir, nodeid) |
|
8541
7a7f6ee0a09e
bug: import/importables fail to set newid correctly.
John Rouillard <rouilj@ieee.org>
parents:
8540
diff
changeset
|
1344 |
|
7a7f6ee0a09e
bug: import/importables fail to set newid correctly.
John Rouillard <rouilj@ieee.org>
parents:
8540
diff
changeset
|
1345 maxid = max(maxid, int(nodeid)) |
|
8224
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1346 |
|
8541
7a7f6ee0a09e
bug: import/importables fail to set newid correctly.
John Rouillard <rouilj@ieee.org>
parents:
8540
diff
changeset
|
1347 # (print to sys.stdout here to allow tests to squash it .. ugh) |
|
7a7f6ee0a09e
bug: import/importables fail to set newid correctly.
John Rouillard <rouilj@ieee.org>
parents:
8540
diff
changeset
|
1348 print(file=sys.stdout) |
|
8224
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1349 |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1350 return maxid |
|
5913ec1673c2
refactor: extract code as method from do_import
John Rouillard <rouilj@ieee.org>
parents:
8119
diff
changeset
|
1351 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1352 def do_importtables(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1353 ''"""Usage: importtables export_dir |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
1354 This imports the database tables exported using exporttables. |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1355 |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
1356 It does not import the content of files like msgs and files. |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1357 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1358 return self.do_import(args, import_files=False) |
|
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 def do_initialise(self, tracker_home, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1361 ''"""Usage: initialise [adminpw] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1362 Initialise a new Roundup tracker. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1363 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1364 The administrator details will be set at this step. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1365 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1366 Execute the tracker's initialisation function dbinit.init() |
|
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 # password |
|
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 adminpw = args[1] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1371 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1372 adminpw = '' |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1373 confirm = 'x' |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1374 while adminpw != confirm: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1375 adminpw = getpass.getpass(_('Admin Password: ')) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1376 confirm = getpass.getpass(_(' Confirm: ')) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1377 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1378 # make sure the tracker home is installed |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1379 if not os.path.exists(tracker_home): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1380 raise UsageError(_('Instance home does not exist') % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1381 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1382 tracker = roundup.instance.open(tracker_home) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1383 except roundup.instance.TrackerError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1384 raise UsageError(_('Instance has not been installed') % locals()) |
|
7427
36916abe36e9
Handle traceback when OptionValueError raised during init.
John Rouillard <rouilj@ieee.org>
parents:
7397
diff
changeset
|
1385 except OptionValueError as e: |
|
36916abe36e9
Handle traceback when OptionValueError raised during init.
John Rouillard <rouilj@ieee.org>
parents:
7397
diff
changeset
|
1386 raise UsageError(e) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1387 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1388 # is there already a database? |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1389 if tracker.exists(): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1390 if not self.force: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1391 ok = self.my_input(_( |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1392 """WARNING: The database is already initialised! |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1393 If you re-initialise it, you will lose all the data! |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1394 Erase it? Y/N: """)) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1395 if ok.strip().lower() != 'y': |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1396 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1397 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1398 # nuke it |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1399 tracker.nuke() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1400 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1401 # GO |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1402 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1403 tracker.init(password.Password(adminpw, config=tracker.config), |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1404 tx_Source='cli') |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1405 except OptionUnsetError as e: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1406 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
|
1407 'error': str(e), 'tracker_home': tracker_home}) |
|
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 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1410 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1411 def do_install(self, tracker_home, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1412 ''"""Usage: install [template [backend [key=val[,key=val]]]] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1413 Install a new Roundup tracker. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1414 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1415 The command will prompt for the tracker home directory |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1416 (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
|
1417 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
|
1418 as arguments, in that order. |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1419 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1420 Command line arguments following the backend allows you to |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1421 pass initial values for config options. For example, passing |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1422 "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
|
1423 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
|
1424 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
|
1425 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
|
1426 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1427 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
|
1428 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
|
1429 initial database contents before running that command by editing |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1430 the tracker's dbinit.py module init() function. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1431 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1432 See also initopts help. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1433 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1434 if len(args) < 1: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1435 raise UsageError(_('Not enough arguments supplied')) |
|
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 # make sure the tracker home can be created |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1438 tracker_home = os.path.abspath(tracker_home) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1439 parent = os.path.split(tracker_home)[0] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1440 if not os.path.exists(parent): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1441 raise UsageError(_('Instance home parent directory "%(parent)s"' |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1442 ' does not exist') % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1443 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1444 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
|
1445 # check for both old- and new-style configs |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1446 if list(filter(os.path.exists, [config_ini_file, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1447 os.path.join(tracker_home, 'config.py')])): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1448 if not self.force: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1449 ok = self.my_input(_( |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1450 """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
|
1451 If you re-install it, you will lose all the data! |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1452 Erase it? Y/N: """) % locals()) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1453 if ok.strip().lower() != 'y': |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1454 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1455 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1456 # clear it out so the install isn't confused |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1457 shutil.rmtree(tracker_home) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1458 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1459 # select template |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1460 templates = self.listTemplates() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1461 template = self._get_choice( |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1462 list_name=_('Templates:'), |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1463 prompt=_('Select template'), |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1464 options=templates, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1465 argument=len(args) > 1 and args[1] or '', |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1466 default='classic') |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1467 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1468 # select hyperdb backend |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1469 import roundup.backends |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1470 backends = roundup.backends.list_backends() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1471 backend = self._get_choice( |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1472 list_name=_('Back ends:'), |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1473 prompt=_('Select backend'), |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1474 options=backends, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1475 argument=len(args) > 2 and args[2] or '', |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1476 default='anydbm') |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1477 # 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
|
1478 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1479 # Process configuration file definitions |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1480 if len(args) > 3: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1481 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1482 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
|
1483 except Exception: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1484 print(_('Error in configuration settings: "%s"') % args[3]) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1485 raise |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1486 else: |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1487 defns = {} |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1488 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1489 defns['rdbms_backend'] = backend |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1490 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1491 # load config_ini.ini from template if it exists. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1492 # it sets parameters like template_engine that are |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1493 # template specific. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1494 template_config = UserConfig(templates[template]['path'] + |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1495 "/config_ini.ini") |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1496 |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1497 # .keys() is required. UserConfig has no __iter__ or __next__ |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1498 for k in template_config.keys(): # noqa: SIM118 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1499 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
|
1500 continue |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1501 defns[k] = template_config[k] |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1502 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1503 # install! |
|
8540
e8d1da6e3571
bug: fix traceback in roundup-admin init with bad config values
John Rouillard <rouilj@ieee.org>
parents:
8487
diff
changeset
|
1504 try: |
|
e8d1da6e3571
bug: fix traceback in roundup-admin init with bad config values
John Rouillard <rouilj@ieee.org>
parents:
8487
diff
changeset
|
1505 init.install(tracker_home, templates[template]['path'], settings=defns) |
|
e8d1da6e3571
bug: fix traceback in roundup-admin init with bad config values
John Rouillard <rouilj@ieee.org>
parents:
8487
diff
changeset
|
1506 except ConfigurationError as e: |
|
e8d1da6e3571
bug: fix traceback in roundup-admin init with bad config values
John Rouillard <rouilj@ieee.org>
parents:
8487
diff
changeset
|
1507 raise UsageError(e) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1508 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1509 # 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
|
1510 # Ignore file not found - not all templates have |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1511 # config_ini.ini files. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1512 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1513 os.remove(tracker_home + "/config_ini.ini") |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1514 except OSError as e: # FileNotFound exception under py3 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1515 if e.errno == 2: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1516 pass |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1517 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1518 raise |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1519 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1520 print(_(""" |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1521 --------------------------------------------------------------------------- |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1522 You should now edit the tracker configuration file: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1523 %(config_file)s""") % {"config_file": config_ini_file}) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1524 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1525 # find list of options that need manual adjustments |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1526 # XXX config._get_unset_options() is marked as private |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1527 # (leading underscore). make it public or don't care? |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1528 need_set = CoreConfig(tracker_home)._get_unset_options() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1529 if need_set: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1530 print(_(" ... at a minimum, you must set following options:")) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1531 for section in need_set: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1532 print(" [%s]: %s" % (section, ", ".join(need_set[section]))) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1533 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1534 # note about schema modifications |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1535 print(_(""" |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1536 If you wish to modify the database schema, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1537 you should also edit the schema file: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1538 %(database_config_file)s |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1539 You may also change the database initialisation file: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1540 %(database_init_file)s |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1541 ... see the documentation on customizing for more information. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1542 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1543 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
|
1544 the above steps. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1545 --------------------------------------------------------------------------- |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1546 """) % {'database_config_file': os.path.join(tracker_home, 'schema.py'), |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1547 'database_init_file': os.path.join(tracker_home, 'initial_data.py')}) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1548 return 0 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1549 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1550 def do_list(self, args): |
|
4073
145b32238093
Revert docstring markup for use with gettext tool.
Stefan Seefeld <stefan@seefeld.name>
parents:
4067
diff
changeset
|
1551 ''"""Usage: list classname [property] |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1552 List the instances of a class. |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1553 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1554 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
|
1555 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
|
1556 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
|
1557 property, alphabetically. |
|
1566
053065585406
added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents:
1563
diff
changeset
|
1558 |
|
2329
e128fd807054
fix invalid backslash escapes; wrap long lines
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2313
diff
changeset
|
1559 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
|
1560 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
|
1561 for every class instance. |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
1562 """ |
|
1676
4856faf558a2
Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents:
1652
diff
changeset
|
1563 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
|
1564 raise UsageError(_('Too many arguments supplied')) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1565 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
|
1566 raise UsageError(_('Not enough arguments supplied')) |
|
7547
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1567 |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1568 retired = self.settings['_retired_val'] |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1569 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1570 classname = args[0] |
| 6180 | 1571 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1572 # get the class |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1573 cl = self.get_class(classname) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1574 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1575 # figure the property |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1576 propname = args[1] if len(args) > 1 else cl.labelprop() |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1577 |
|
1566
053065585406
added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents:
1563
diff
changeset
|
1578 if self.separator: |
|
1676
4856faf558a2
Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents:
1652
diff
changeset
|
1579 if len(args) == 2: |
|
4073
145b32238093
Revert docstring markup for use with gettext tool.
Stefan Seefeld <stefan@seefeld.name>
parents:
4067
diff
changeset
|
1580 # create a list of propnames since user specified propname |
| 6180 | 1581 proplist = [] |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1582 try: |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
1583 proplist = [cl.get(nodeid, propname) for nodeid in |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1584 cl.getnodeids(retired=retired)] |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1585 except KeyError: |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1586 raise UsageError(_('%(classname)s has no property ' |
| 6180 | 1587 '"%(propname)s"') % locals()) |
|
5250
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
1588 print(self.separator.join(proplist)) |
|
1676
4856faf558a2
Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents:
1652
diff
changeset
|
1589 else: |
|
4856faf558a2
Get rid of TABs, use spaces instead.
Jean Jordaan <neaj@users.sourceforge.net>
parents:
1652
diff
changeset
|
1590 # 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
|
1591 # otherwise |
|
7547
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1592 print(self.separator.join(cl.getnodeids(retired=retired))) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1593 else: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1594 try: |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1595 for nodeid in cl.getnodeids(retired=retired): |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1596 value = cl.get(nodeid, propname) |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1597 print(_('%(nodeid)4s: %(value)s') % locals()) |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1598 except KeyError: |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1599 raise UsageError(_('%(classname)s has no property ' |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1600 '"%(propname)s"') % locals()) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1601 return 0 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1602 |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1603 def do_migrate(self, args): # noqa: ARG002 - args unused |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1604 ''"""Usage: migrate |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1605 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
|
1606 codebase. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1607 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1608 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
|
1609 you've installed the latest codebase. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1610 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1611 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
|
1612 and before any users access the tracker. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1613 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1614 This command will respond with either "Tracker updated" (if |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1615 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
|
1616 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
|
1617 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
|
1618 using anydbm). |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1619 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1620 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
|
1621 into the habit. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1622 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1623 if self.db.db_version_updated: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1624 print(_('Tracker updated to schema version %s.') % |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1625 self.db.database_schema['version']) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1626 self.db_uncommitted = True |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1627 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1628 print(_('No migration action required. At schema version %s.') % |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1629 self.db.database_schema['version']) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1630 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1631 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1632 def do_pack(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1633 ''"""Usage: pack period | date |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
1634 Remove journal entries older than the date/period. |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1635 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1636 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
|
1637 suffix "w" (for "week") means 7 days. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1638 |
|
8393
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
1639 "3y" means three years |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
1640 "2y 1m" means two years and one month |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
1641 "1m 25d" means one month and 25 days |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
1642 "2w 3d" means two weeks and three days |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1643 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1644 Date format is "YYYY-MM-DD" eg: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1645 2001-01-01 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1646 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1647 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1648 if len(args) != 1: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1649 raise UsageError(_('Not enough arguments supplied')) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1650 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1651 # are we dealing with a period or a date |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1652 value = args[0] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1653 date_re = re.compile(r""" |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1654 (?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
|
1655 (?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
|
1656 """, re.VERBOSE) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1657 m = date_re.match(value) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1658 if not m: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1659 raise ValueError(_('Invalid format')) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1660 m = m.groupdict() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1661 if m['period']: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1662 pack_before = date.Date(". - %s" % value) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1663 elif m['date']: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1664 pack_before = date.Date(value) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1665 self.db.pack(pack_before) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1666 self.db_uncommitted = True |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1667 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1668 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1669 def do_perftest(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1670 ''"""Usage: perftest [mode] [arguments]* |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
1671 Time operations in Roundup. |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1672 |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
1673 Supported arguments: |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1674 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1675 [password] [rounds=<integer>] [scheme=<scheme>] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1676 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1677 '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
|
1678 setting for 'password_pbkdf2_default_rounds' is the default |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1679 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
|
1680 thousands separator of ',' or '.'. 'scheme' is the default |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1681 coded into Roundup. List supported schemes by using 'scheme='. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1682 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1683 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1684 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
|
1685 |
|
8240
1189c742e4b3
fix: crash roundup-admin perftest password without rounds= argument.
John Rouillard <rouilj@ieee.org>
parents:
8224
diff
changeset
|
1686 # default rounds from db.config is an int not str |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1687 props = {"rounds": self.db.config.PASSWORD_PBKDF2_DEFAULT_ROUNDS, |
|
7375
9bd7ed918121
issue2551253 - Modify password PBKDF2 method to use SHA512
John Rouillard <rouilj@ieee.org>
parents:
7371
diff
changeset
|
1688 "scheme": password.Password.default_scheme} |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1689 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1690 print_supported_schemes = lambda: print( |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1691 "Supported schemes (default is first, case " |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1692 "sensitive):\n %s." % |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1693 ", ".join(password.Password.known_schemes)) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1694 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1695 if (args[0].find("=") != -1): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1696 args.insert(0, 'password') |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1697 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1698 props.update(self.props_from_args(args[1:])) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1699 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1700 if args[0] == "password": |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1701 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1702 # convert 10,000,000 or 10.000.000 to 10000000 |
|
8240
1189c742e4b3
fix: crash roundup-admin perftest password without rounds= argument.
John Rouillard <rouilj@ieee.org>
parents:
8224
diff
changeset
|
1703 r = int(re.sub('[,.]', '', props['rounds'])) \ |
|
1189c742e4b3
fix: crash roundup-admin perftest password without rounds= argument.
John Rouillard <rouilj@ieee.org>
parents:
8224
diff
changeset
|
1704 if not isinstance(props['rounds'], int) \ |
|
1189c742e4b3
fix: crash roundup-admin perftest password without rounds= argument.
John Rouillard <rouilj@ieee.org>
parents:
8224
diff
changeset
|
1705 else props['rounds'] |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1706 if r < 1000: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1707 print(_("Invalid 'rounds'. Must be larger than 999.")) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1708 return |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1709 props['rounds'] = r |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1710 except (TypeError, ValueError): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1711 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
|
1712 props['rounds']) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1713 return |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1714 if props['scheme'] is None: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1715 print_supported_schemes() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1716 return |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1717 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1718 self.db.config.PASSWORD_PBKDF2_DEFAULT_ROUNDS = props['rounds'] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1719 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1720 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1721 tic = perf_counter() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1722 pw_hash = password.encodePassword( |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1723 "this is a long password to hash", |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1724 props['scheme'], |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1725 None, |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1726 config=self.db.config, |
|
7250
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 toc = perf_counter() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1729 except password.PasswordValueError as e: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1730 print(e) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1731 print_supported_schemes() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1732 return |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1733 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1734 if props['scheme'].startswith('PBKDF2'): |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
1735 (rounds, _salt, _raw_salt, _digest) = password.pbkdf2_unpack( |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1736 pw_hash) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1737 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1738 rounds = _("scheme does not support rounds.") |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1739 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1740 print(_( |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1741 "Hash time: %(time)0.9f seconds, scheme: %(scheme)s, " |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1742 "rounds: %(rounds)s") % |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
1743 {"time": toc - tic, "scheme": props['scheme'], |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1744 "rounds": rounds}) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1745 |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1746 def do_pragma(self, args): |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1747 ''"""Usage: pragma setting=value | 'list' |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
1748 Set internal admin settings to a value. |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
1749 |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
1750 For example: |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1751 |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1752 pragma verbose=True |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1753 pragma verbose=yes |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1754 pragma verbose=on |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1755 pragma verbose=1 |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1756 |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1757 will turn on verbose mode for roundup-admin. |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1758 |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1759 pragma list |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1760 |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1761 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
|
1762 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
|
1763 """ |
|
7543
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
1764 """ |
|
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
1765 The following are to be implemented: |
|
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
1766 exportfiles={true|false} - Not Implemented - If true |
|
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
1767 (default) export/import db tables and files. If |
|
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
1768 False, export/import just database tables, not |
|
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
1769 files. Use for faster database migration. |
|
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
1770 Replaces exporttables/importtables with |
|
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
1771 exportfiles=false then export/import |
|
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
1772 """ |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1773 |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1774 if len(args) < 1: |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1775 raise UsageError(_('Not enough arguments supplied')) |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1776 |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1777 try: |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1778 (setting, value) = args[0].split("=", 1) |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1779 except ValueError: |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1780 if args[0] != "list": |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1781 raise UsageError(_( |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1782 'Argument must be setting=value, was given: %s.') % |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1783 args[0]) |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1784 |
|
7773
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
1785 print(_("Current settings and values " |
|
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
1786 "(NYI - not yet implemented):")) |
|
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
1787 is_verbose = self.settings['verbose'] |
|
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
1788 for key in sorted(self.settings.keys()): |
|
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
1789 if key.startswith('_') and not is_verbose: |
|
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
1790 continue |
|
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
1791 print(" %s=%s" % (key, self.settings[key])) |
|
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
1792 if is_verbose: |
|
7796
5f3b49bb7742
add missing help text for history_length pragma. Also don't crash report missing text if text is missing
John Rouillard <rouilj@ieee.org>
parents:
7795
diff
changeset
|
1793 try: |
|
5f3b49bb7742
add missing help text for history_length pragma. Also don't crash report missing text if text is missing
John Rouillard <rouilj@ieee.org>
parents:
7795
diff
changeset
|
1794 print(" %s" % self.settings_help[key]) |
|
5f3b49bb7742
add missing help text for history_length pragma. Also don't crash report missing text if text is missing
John Rouillard <rouilj@ieee.org>
parents:
7795
diff
changeset
|
1795 except KeyError: |
|
5f3b49bb7742
add missing help text for history_length pragma. Also don't crash report missing text if text is missing
John Rouillard <rouilj@ieee.org>
parents:
7795
diff
changeset
|
1796 print(_(" Help for this pragma is missing. " |
|
5f3b49bb7742
add missing help text for history_length pragma. Also don't crash report missing text if text is missing
John Rouillard <rouilj@ieee.org>
parents:
7795
diff
changeset
|
1797 "Please report it to the Roundup project.\n")) |
|
7773
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
1798 |
|
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
1799 return |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1800 |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1801 if setting not in self.settings: |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1802 raise UsageError(_('Unknown setting %s. Try "pragma list".') |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1803 % setting) |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1804 if isinstance(self.settings[setting], bool): |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1805 value = value.lower() |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1806 if value in ("yes", "true", "on", "1"): |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1807 value = True |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1808 elif value in ("no", "false", "off", "0"): |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1809 value = False |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1810 else: |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1811 raise UsageError(_( |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1812 'Incorrect value for boolean setting %(setting)s: ' |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1813 '%(value)s.') % {"setting": setting, "value": value}) |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1814 elif isinstance(self.settings[setting], int): |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1815 try: |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1816 _val = int(value) |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1817 except ValueError: |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1818 raise UsageError(_( |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1819 'Incorrect value for integer setting %(setting)s: ' |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1820 '%(value)s.') % {"setting": setting, "value": value}) |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1821 value = _val |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
1822 elif isinstance(self.settings[setting], str): |
|
7547
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1823 if setting == "show_retired": |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1824 if value not in ["no", "only", "both"]: |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1825 raise UsageError(_( |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1826 'Incorrect value for setting %(setting)s: ' |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1827 '%(value)s. Should be no, both, or only.') % { |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1828 "setting": setting, "value": value}) |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1829 if value == "both": |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1830 self.settings['_retired_val'] = None |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1831 elif value == "only": # numerical value not boolean |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1832 self.settings['_retired_val'] = True |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1833 else: # numerical value not boolean |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
1834 self.settings['_retired_val'] = False |
|
7252
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1835 else: |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1836 raise UsageError(_('Internal error: pragma can not handle ' |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1837 'values of type: %s') % |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1838 type(self.settings[setting]).__name__) |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1839 self.settings[setting] = value |
|
9c067ed4568b
add pragma command to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7250
diff
changeset
|
1840 |
|
8440
254f70dfc585
bug, refactor, test: make pragma history_length work interactively
John Rouillard <rouilj@ieee.org>
parents:
8439
diff
changeset
|
1841 # history_length has to be pushed to readline to have any effect. |
|
254f70dfc585
bug, refactor, test: make pragma history_length work interactively
John Rouillard <rouilj@ieee.org>
parents:
8439
diff
changeset
|
1842 if setting == "history_length": |
|
254f70dfc585
bug, refactor, test: make pragma history_length work interactively
John Rouillard <rouilj@ieee.org>
parents:
8439
diff
changeset
|
1843 self.readline.set_history_length( |
|
254f70dfc585
bug, refactor, test: make pragma history_length work interactively
John Rouillard <rouilj@ieee.org>
parents:
8439
diff
changeset
|
1844 self.settings['history_length']) |
|
254f70dfc585
bug, refactor, test: make pragma history_length work interactively
John Rouillard <rouilj@ieee.org>
parents:
8439
diff
changeset
|
1845 |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1846 def do_readline(self, args): |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1847 ''"""Usage: readline initrc_line | 'emacs' | 'history' | 'reload' | 'vi' |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1848 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1849 Using 'reload' will reload the file ~/.roundup_admin_rlrc. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1850 'history' will show (and number) all commands in the history. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1851 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1852 You can change input mode using the 'emacs' or 'vi' parameters. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1853 The default is emacs. This is the same as using:: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1854 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1855 readline set editing-mode emacs |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1856 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1857 or:: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1858 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1859 readline set editing-mode vi |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1860 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1861 Any command that can be placed in a readline .inputrc file can |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1862 be executed using the readline command. You can assign |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1863 dump-variables to control O using:: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1864 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1865 readline Control-o: dump-variables |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1866 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1867 Assigning multi-key values also works. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1868 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1869 pyreadline3 support on windows: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1870 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1871 Mode switching doesn't work, emacs only. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1872 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1873 Binding single key commands works with:: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1874 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1875 readline Control-w: history-search-backward |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1876 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1877 Multiple key sequences don't work. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1878 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1879 Setting values may work. Difficult to tell because the library |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1880 has no way to view the live settings. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1881 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1882 """ |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1883 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1884 # TODO: allow history 20 # most recent 20 commands |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1885 # history 100-200 # show commands 100-200 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1886 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1887 if not self.readline: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1888 print(_("Readline support is not available.")) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1889 return |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1890 # The if test allows pyreadline3 settings like: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1891 # bind_exit_key("Control-z") get through to |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1892 # parse_and_bind(). It is not obvious that this form of |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1893 # command is supported. Pyreadline3 is supposed to parse |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1894 # readline style commands, so we use those for emacs/vi. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1895 # Trying set-mode(...) as in the pyreadline3 init file |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1896 # didn't work in testing. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1897 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1898 if len(args) == 1 and args[0].find('(') == -1: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1899 if args[0] == "vi": |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1900 self.readline.parse_and_bind("set editing-mode vi") |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1901 print(_("Enabled vi mode.")) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1902 elif args[0] == "emacs": |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1903 self.readline.parse_and_bind("set editing-mode emacs") |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1904 print(_("Enabled emacs mode.")) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1905 elif args[0] == "history": |
|
8440
254f70dfc585
bug, refactor, test: make pragma history_length work interactively
John Rouillard <rouilj@ieee.org>
parents:
8439
diff
changeset
|
1906 history_size = self.readline.get_current_history_length() |
|
254f70dfc585
bug, refactor, test: make pragma history_length work interactively
John Rouillard <rouilj@ieee.org>
parents:
8439
diff
changeset
|
1907 print("history size", history_size) |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1908 print('\n'.join([ |
|
8440
254f70dfc585
bug, refactor, test: make pragma history_length work interactively
John Rouillard <rouilj@ieee.org>
parents:
8439
diff
changeset
|
1909 "%3d %s" % ((i + 1), |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1910 self.readline.get_history_item(i + 1)) |
|
8440
254f70dfc585
bug, refactor, test: make pragma history_length work interactively
John Rouillard <rouilj@ieee.org>
parents:
8439
diff
changeset
|
1911 for i in range(history_size) |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1912 ])) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1913 elif args[0] == "reload": |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1914 try: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1915 # readline is a singleton. In testing previous |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1916 # tests using read_init_file are loading from ~ |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1917 # not the test directory because it doesn't |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1918 # matter. But for reload we want to test with the |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1919 # init file under the test directory. Calling |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1920 # read_init_file() calls with the ~/.. init |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1921 # location and I can't seem to reset it |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1922 # or the readline state. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1923 # So call with explicit file here. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1924 self.readline.read_init_file( |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1925 self.get_readline_init_file()) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1926 except FileNotFoundError as e: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1927 # If user invoked reload explicitly, report |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1928 # if file not found. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1929 # |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1930 # DOES NOT WORK with pyreadline3. Exception |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1931 # is not raised if file is missing. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1932 # |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1933 # Also e.filename is None under cygwin. A |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1934 # simple test case does set e.filename |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1935 # correctly?? sigh. So I just call |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1936 # get_readline_init_file again to get |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1937 # filename. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1938 fn = e.filename or self.get_readline_init_file() |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1939 print(_("Init file %s not found.") % fn) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1940 else: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1941 print(_("File %s reloaded.") % |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1942 self.get_readline_init_file()) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1943 else: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1944 print(_("Unknown readline parameter %s") % args[0]) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1945 return |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1946 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1947 self.readline.parse_and_bind(" ".join(args)) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1948 return |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
1949 |
|
7395
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1950 designator_re = re.compile('([A-Za-z]+)([0-9]+)$') |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1951 designator_rng = re.compile('([A-Za-z]+):([0-9]+)-([0-9]+)$') |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1952 |
|
7395
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1953 def do_reindex(self, args, desre=designator_re, desrng=designator_rng): |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1954 ''"""Usage: reindex [classname|classname:#-#|designator]* |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1955 Re-generate a tracker's search indexes. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1956 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1957 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
|
1958 This will typically happen automatically. |
|
7395
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1959 |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1960 You can incrementally reindex using an argument like: |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1961 |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1962 reindex issue:23-1000 |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1963 |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1964 to reindex issue class items 23-1000. Missing items |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1965 are reported but do not stop indexing of the range. |
|
6957
f924af12ef50
issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents:
6818
diff
changeset
|
1966 """ |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1967 if args: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1968 for arg in args: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1969 m = desre.match(arg) |
|
7395
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1970 r = desrng.match(arg) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1971 if m: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1972 cl = self.get_class(m.group(1)) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1973 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1974 cl.index(m.group(2)) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1975 except IndexError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1976 raise UsageError(_('no such item "%(designator)s"') % { |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1977 'designator': arg}) |
|
7395
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1978 elif r: |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1979 cl = self.get_class(r.group(1)) |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1980 for item in support.Progress( |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1981 'Reindexing %s' % r.group(1), |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1982 range(int(r.group(2)), int(r.group(3)))): |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1983 try: |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1984 cl.index(str(item)) |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1985 except IndexError: |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1986 print(_('no such item "%(class)s%(id)s"') % { |
| 7566 | 1987 'class': r.group(1), |
| 1988 'id': item}) | |
| 1989 | |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1990 else: |
|
7395
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1991 cl = self.get_class(arg) # Bad class raises UsageError |
|
312d52305583
- issue2551190 - Allow roundup-admin reindex to work in batches.
John Rouillard <rouilj@ieee.org>
parents:
7392
diff
changeset
|
1992 self.db.reindex(arg, show_progress=True) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1993 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1994 self.db.reindex(show_progress=True) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1995 return 0 |
|
6957
f924af12ef50
issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents:
6818
diff
changeset
|
1996 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1997 def do_restore(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1998 ''"""Usage: restore designator[,designator]* |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
1999 Restore the retired node specified by designator. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2000 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2001 A designator is a classname and a nodeid concatenated, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2002 eg. bug1, user10, ... |
|
6957
f924af12ef50
issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents:
6818
diff
changeset
|
2003 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2004 The given nodes will become available for users again. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2005 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2006 if len(args) < 1: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2007 raise UsageError(_('Not enough arguments supplied')) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2008 designators = args[0].split(',') |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2009 for designator in designators: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2010 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2011 classname, nodeid = hyperdb.splitDesignator(designator) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2012 except hyperdb.DesignatorError as message: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2013 raise UsageError(message) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2014 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2015 dbclass = self.db.getclass(classname) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2016 except KeyError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2017 raise UsageError(_('no such class "%(classname)s"') % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2018 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2019 dbclass.restore(nodeid) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2020 except KeyError as e: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2021 raise UsageError(e.args[0]) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2022 except IndexError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2023 raise UsageError(_('no such %(classname)s node ' |
|
8105
e579aef218aa
fix: broken translatable error message template
John Rouillard <rouilj@ieee.org>
parents:
8095
diff
changeset
|
2024 '"%(nodeid)s"') % locals()) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2025 self.db_uncommitted = True |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2026 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2027 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2028 def do_retire(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2029 ''"""Usage: retire designator[,designator]* |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2030 Retire the node specified by designator. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2031 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2032 A designator is a classname and a nodeid concatenated, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2033 eg. bug1, user10, ... |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2034 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2035 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
|
2036 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
|
2037 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2038 if len(args) < 1: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2039 raise UsageError(_('Not enough arguments supplied')) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2040 designators = args[0].split(',') |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2041 for designator in designators: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2042 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2043 classname, nodeid = hyperdb.splitDesignator(designator) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2044 except hyperdb.DesignatorError as message: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2045 raise UsageError(message) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2046 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2047 self.db.getclass(classname).retire(nodeid) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2048 except KeyError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2049 raise UsageError(_('no such class "%(classname)s"') % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2050 except IndexError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2051 raise UsageError(_('no such %(classname)s node ' |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2052 '"%(nodeid)s"') % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2053 self.db_uncommitted = True |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2054 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2055 |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2056 def do_rollback(self, args): # noqa: ARG002 - args unused |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2057 ''"""Usage: rollback |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2058 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
|
2059 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2060 The changes made during an interactive session are not |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2061 automatically written to the database - they must be committed |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2062 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
|
2063 immediately after would make no changes to the database. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2064 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2065 self.db.rollback() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2066 self.db_uncommitted = False |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2067 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2068 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2069 def do_security(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2070 ''"""Usage: security [Role name] |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
2071 Display the Permissions available to one or all Roles. |
|
6957
f924af12ef50
issue2551233 - create new roundup-admin command "templates"
John Rouillard <rouilj@ieee.org>
parents:
6818
diff
changeset
|
2072 |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
2073 Also validates that any properties defined in a |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
2074 permission are valid. |
|
7379
40cab56a97f1
Document that security subcommand reports invalid properties.
John Rouillard <rouilj@ieee.org>
parents:
7375
diff
changeset
|
2075 |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
2076 Run this after changing your permissions to catch |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
2077 typos. |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2078 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2079 if len(args) == 1: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2080 role = args[0] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2081 try: |
|
7650
4de48eadf5f4
bug: Fix roundup-admin security command. Lowercase optionalarg.
John Rouillard <rouilj@ieee.org>
parents:
7588
diff
changeset
|
2082 roles = [(args[0].lower(), |
|
4de48eadf5f4
bug: Fix roundup-admin security command. Lowercase optionalarg.
John Rouillard <rouilj@ieee.org>
parents:
7588
diff
changeset
|
2083 self.db.security.role[args[0].lower()])] |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2084 except KeyError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2085 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
|
2086 return 1 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2087 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2088 roles = list(self.db.security.role.items()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2089 role = self.db.config.NEW_WEB_USER_ROLES |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2090 if ',' in role: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2091 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
|
2092 % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2093 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2094 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
|
2095 % locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2096 role = self.db.config.NEW_EMAIL_USER_ROLES |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2097 if ',' in role: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2098 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
|
2099 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2100 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
|
2101 roles.sort() |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2102 for _rolename, role in roles: |
|
8472
224ccb8b49ca
refactor: change some classes to use __slots__
John Rouillard <rouilj@ieee.org>
parents:
8446
diff
changeset
|
2103 sys.stdout.write(_('Role "%(name)s":\n') % role.props_dict()) |
|
8119
c12377fb4144
Change permission representation
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8105
diff
changeset
|
2104 for permission in role.permission_list(): |
|
8472
224ccb8b49ca
refactor: change some classes to use __slots__
John Rouillard <rouilj@ieee.org>
parents:
8446
diff
changeset
|
2105 d = permission.props_dict() |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2106 if permission.klass: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2107 if permission.properties: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2108 sys.stdout.write(_( |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2109 ' %(description)s (%(name)s for "%(klass)s"' + |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2110 ': %(properties)s only)\n') % d) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2111 # verify that properties exist; report bad props |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2112 bad_props = [] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2113 cl = self.db.getclass(permission.klass) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2114 class_props = cl.getprops(protected=True) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2115 for p in permission.properties: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2116 if p in class_props: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2117 continue |
|
7773
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
2118 |
|
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
2119 bad_props.append(p) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2120 if bad_props: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2121 sys.stdout.write(_( |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2122 '\n **Invalid properties for %(class)s: ' |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2123 '%(props)s\n\n') % { |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2124 "class": permission.klass, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2125 "props": bad_props}) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2126 return 1 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2127 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2128 sys.stdout.write(_(' %(description)s (%(name)s for ' |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2129 '"%(klass)s" only)\n') % d) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2130 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2131 sys.stdout.write(_(' %(description)s (%(name)s)\n') % d) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2132 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2133 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2134 def do_set(self, args): |
|
7380
6480443c2607
set items can take 1 or more property=value
John Rouillard <rouilj@ieee.org>
parents:
7379
diff
changeset
|
2135 ''"""Usage: set items property=value [property=value ...] |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2136 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
|
2137 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2138 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
|
2139 list of item designators (ie "designator[,designator,...]"). |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2140 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2141 A designator is a classname and a nodeid concatenated, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2142 eg. bug1, user10, ... |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2143 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2144 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
|
2145 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
|
2146 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
|
2147 (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
|
2148 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
|
2149 as comma-separated numbers (ie "1,2,3"). |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2150 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2151 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2152 import copy # needed for copying props list |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2153 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2154 if len(args) < 2: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2155 raise UsageError(_('Not enough arguments supplied')) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2156 from roundup import hyperdb |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2157 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2158 designators = args[0].split(',') |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2159 if len(designators) == 1: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2160 designator = designators[0] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2161 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2162 designator = hyperdb.splitDesignator(designator) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2163 designators = [designator] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2164 except hyperdb.DesignatorError: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2165 cl = self.get_class(designator) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2166 designators = [(designator, x) for x in cl.list()] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2167 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2168 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2169 designators = [hyperdb.splitDesignator(x) for x in designators] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2170 except hyperdb.DesignatorError as message: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2171 raise UsageError(message) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2172 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2173 # get the props from the args |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2174 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
|
2175 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2176 # now do the set for all the nodes |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2177 for classname, itemid in designators: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2178 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
|
2179 cl = self.get_class(classname) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2180 |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2181 try: |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2182 for key, value in list(props.items()): |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2183 # You must reinitialize the props every time though. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2184 # if props['nosy'] = '+admin' initally, it gets |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2185 # 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
|
2186 # in the db) after rawToHyperdb returns. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2187 # 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
|
2188 # designators if not reinitalized. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2189 props[key] = hyperdb.rawToHyperdb(self.db, cl, itemid, |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2190 key, value) |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2191 except hyperdb.HyperdbValueError as message: |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2192 raise UsageError(message) |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2193 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2194 # try the set |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2195 try: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2196 cl.set(itemid, **props) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2197 except (TypeError, IndexError, ValueError) as message: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2198 raise UsageError(message) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2199 self.db_uncommitted = True |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2200 return 0 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2201 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2202 def do_specification(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2203 ''"""Usage: specification classname |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2204 Show the properties for a classname. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2205 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2206 This lists the properties for a given class. |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2207 """ |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2208 if len(args) < 1: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2209 raise UsageError(_('Not enough arguments supplied')) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2210 classname = args[0] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2211 # get the class |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2212 cl = self.get_class(classname) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2213 |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2214 # get the key property |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2215 keyprop = cl.getkey() |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2216 properties = cl.getprops() if self.settings['display_protected'] \ |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2217 else cl.properties |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2218 |
|
7543
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
2219 for key in properties: |
|
fc9daba984c0
- issue2551103 - add pragma 'display_protected' to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7439
diff
changeset
|
2220 value = properties[key] |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2221 if keyprop == key: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2222 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
|
2223 locals()) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2224 else: |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2225 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
|
2226 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2227 def do_table(self, args): |
|
4073
145b32238093
Revert docstring markup for use with gettext tool.
Stefan Seefeld <stefan@seefeld.name>
parents:
4067
diff
changeset
|
2228 ''"""Usage: table classname [property[,property]*] |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2229 List the instances of a class in tabular form. |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2230 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2231 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
|
2232 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
|
2233 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
|
2234 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
|
2235 For example:: |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1916
diff
changeset
|
2236 |
|
8393
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
2237 roundup> table priority id,name:10 |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
2238 Id Name |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
2239 1 fatal-bug |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
2240 2 bug |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
2241 3 usability |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
2242 4 feature |
|
1544
6db2cbcd390e
finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents:
1539
diff
changeset
|
2243 |
|
6db2cbcd390e
finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents:
1539
diff
changeset
|
2244 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
|
2245 leave a trailing : without a width on the property. For example:: |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1916
diff
changeset
|
2246 |
|
8393
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
2247 roundup> table priority id,name: |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
2248 Id Name |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
2249 1 fata |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
2250 2 bug |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
2251 3 usab |
|
e5d07fac0249
build: remove extra <p></p> generated by blank lines.
John Rouillard <rouilj@ieee.org>
parents:
8296
diff
changeset
|
2252 4 feat |
|
1544
6db2cbcd390e
finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents:
1539
diff
changeset
|
2253 |
|
6db2cbcd390e
finally, tables autosize columns [SF#609070]
Richard Jones <richard@users.sourceforge.net>
parents:
1539
diff
changeset
|
2254 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
|
2255 """ |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2256 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
|
2257 raise UsageError(_('Not enough arguments supplied')) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2258 classname = args[0] |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2259 |
|
7547
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
2260 retired = self.settings['_retired_val'] |
|
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
2261 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2262 # get the class |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2263 cl = self.get_class(classname) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2264 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2265 # figure the property names to display |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2266 if len(args) > 1: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2267 prop_names = args[1].split(',') |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2268 all_props = cl.getprops() |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2269 for spec in prop_names: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2270 if ':' in spec: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2271 try: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2272 propname, width = spec.split(':') |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2273 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
|
2274 raise UsageError(_('"%(spec)s" not ' |
| 6180 | 2275 'name:width') % locals()) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2276 else: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2277 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
|
2278 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
|
2279 raise UsageError(_('%(classname)s has no property ' |
| 6180 | 2280 '"%(propname)s"') % locals()) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2281 else: |
|
4357
13b3155869e0
Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents:
4299
diff
changeset
|
2282 prop_names = cl.getprops() |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2283 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2284 # now figure column widths |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2285 props = [] |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2286 for spec in prop_names: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2287 if ':' in spec: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2288 name, width = spec.split(':') |
| 1546 | 2289 if width == '': |
| 6585 | 2290 # 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
|
2291 props.append((name, len(name))) |
| 1546 | 2292 else: |
|
6198
39513b36ca59
Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents:
6195
diff
changeset
|
2293 try: |
|
39513b36ca59
Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents:
6195
diff
changeset
|
2294 props.append((name, int(width))) |
|
39513b36ca59
Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents:
6195
diff
changeset
|
2295 except ValueError: |
|
39513b36ca59
Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents:
6195
diff
changeset
|
2296 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
|
2297 'integer width: "%(width)s"') % |
|
39513b36ca59
Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents:
6195
diff
changeset
|
2298 locals()) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2299 else: |
| 6180 | 2300 # this is going to be slow |
| 2301 maxlen = len(spec) | |
|
7547
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
2302 for nodeid in cl.getnodeids(retired=retired): |
| 6180 | 2303 curlen = len(str(cl.get(nodeid, spec))) |
| 2304 if curlen > maxlen: | |
| 2305 maxlen = curlen | |
|
6198
39513b36ca59
Add set tests. Test and fix table command.
John Rouillard <rouilj@ieee.org>
parents:
6195
diff
changeset
|
2306 props.append((spec, maxlen)) |
|
2307
f786a1b9dbdf
translatabe strings adjustments, postponed help text translation
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2215
diff
changeset
|
2307 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2308 # now display the heading |
| 6180 | 2309 print(' '.join([name.capitalize().ljust(width) |
| 2310 for name, width in props])) | |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2311 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2312 # and the table data |
|
7547
c8c4514f4c3e
issue685275 - show retired/unretire commands
John Rouillard <rouilj@ieee.org>
parents:
7546
diff
changeset
|
2313 for nodeid in cl.getnodeids(retired=retired): |
| 6585 | 2314 table_columns = [] |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2315 for name, width in props: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2316 if name != 'id': |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2317 try: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2318 value = str(cl.get(nodeid, name)) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2319 except KeyError: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2320 # we already checked if the property is valid - a |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2321 # KeyError here means the node just doesn't have a |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2322 # value for it |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2323 value = '' |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2324 else: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2325 value = str(nodeid) |
| 6180 | 2326 f = '%%-%ds' % width |
| 6585 | 2327 table_columns.append(f % value[:width]) |
| 2328 print(' '.join(table_columns)) | |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2329 return 0 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2330 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2331 def do_templates(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2332 ''"""Usage: templates [trace_search] |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2333 List templates and their installed directories. |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2334 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2335 With trace_search also list all directories that are |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2336 searched for templates. |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
2337 """ |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2338 import textwrap |
|
6431
ada1edcc9132
issue2551142 - Import ... unique constraint failure.
John Rouillard <rouilj@ieee.org>
parents:
6430
diff
changeset
|
2339 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2340 trace_search = False |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2341 if args and args[0] == "trace_search": |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2342 trace_search = True |
|
3669
07d1d8e22271
new "exporttables" command in roundup-admin [SF#1533791]
Richard Jones <richard@users.sourceforge.net>
parents:
3641
diff
changeset
|
2343 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2344 templates = self.listTemplates(trace_search=trace_search) |
|
3179
88dbe6b3d891
merge removal of rcsv
Richard Jones <richard@users.sourceforge.net>
parents:
2998
diff
changeset
|
2345 |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2346 for name in sorted(templates.keys()): |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2347 templates[name]['description'] = textwrap.fill( |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2348 "\n".join([line.lstrip() for line in |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2349 templates[name]['description'].split("\n")]), |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2350 70, |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2351 subsequent_indent=" ", |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2352 ) |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2353 print(""" |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2354 Name: %(name)s |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2355 Path: %(path)s |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2356 Desc: %(description)s |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2357 """ % 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
|
2358 |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2359 def do_updateconfig(self, args): |
|
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2360 ''"""Usage: updateconfig <filename> |
|
8095
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
2361 Merge existing tracker config with new settings. |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
2362 |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
2363 Output the updated config file to <filename>. Use current |
|
5aed4911836b
docs: normalize all help strings and make html output look better.
John Rouillard <rouilj@ieee.org>
parents:
8091
diff
changeset
|
2364 settings from existing roundup tracker in tracker home. |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
2365 """ |
|
7250
ee972b3073cb
alphabetize all do_X methods.
John Rouillard <rouilj@ieee.org>
parents:
7249
diff
changeset
|
2366 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
|
2367 |
|
7392
bd6523c84a95
Fix test failure caused by making genconfig trackerless
John Rouillard <rouilj@ieee.org>
parents:
7380
diff
changeset
|
2368 def usageError_feedback(self, message, function): |
|
8540
e8d1da6e3571
bug: fix traceback in roundup-admin init with bad config values
John Rouillard <rouilj@ieee.org>
parents:
8487
diff
changeset
|
2369 print(_('\nError: %s') % message) |
|
7392
bd6523c84a95
Fix test failure caused by making genconfig trackerless
John Rouillard <rouilj@ieee.org>
parents:
7380
diff
changeset
|
2370 print() |
|
bd6523c84a95
Fix test failure caused by making genconfig trackerless
John Rouillard <rouilj@ieee.org>
parents:
7380
diff
changeset
|
2371 print(function.__doc__) |
|
bd6523c84a95
Fix test failure caused by making genconfig trackerless
John Rouillard <rouilj@ieee.org>
parents:
7380
diff
changeset
|
2372 return 1 |
|
bd6523c84a95
Fix test failure caused by making genconfig trackerless
John Rouillard <rouilj@ieee.org>
parents:
7380
diff
changeset
|
2373 |
|
8487
b09ef85f0da6
feat: add nanoid pkg trace_id gen and decorator for setting processName
John Rouillard <rouilj@ieee.org>
parents:
8472
diff
changeset
|
2374 @set_processName("roundup-admin") |
|
8446
14c7c07b32d8
feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents:
8440
diff
changeset
|
2375 @gen_trace_id() |
|
8557
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
2376 @store_trace_reason("admin", extract=( |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
2377 '"roundup-admin(%s): "' % _safe_os_getlogin() + |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
2378 "'%s' % args[1][:2]" |
|
f80c566f5726
feat: improve store_trace_reason with extract parameter
John Rouillard <rouilj@ieee.org>
parents:
8541
diff
changeset
|
2379 )) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2380 def run_command(self, args): |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
2381 """Run a single command |
|
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
2382 """ |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2383 command = args[0] |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2384 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2385 # handle help now |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2386 if command == 'help': |
| 6180 | 2387 if len(args) > 1: |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2388 self.do_help(args[1:]) |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2389 else: |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2390 self.do_help(['help']) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2391 return 0 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2392 if command == 'morehelp': |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2393 self.do_help(['help']) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2394 self.help_commands() |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2395 self.help_all() |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2396 return 0 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2397 |
|
7998
851ddd72f9ce
issue2550983 - help_commands_html unused
John Rouillard <rouilj@ieee.org>
parents:
7882
diff
changeset
|
2398 if command == 'htmlhelp': |
|
851ddd72f9ce
issue2550983 - help_commands_html unused
John Rouillard <rouilj@ieee.org>
parents:
7882
diff
changeset
|
2399 self.help_commands_html() |
|
851ddd72f9ce
issue2550983 - help_commands_html unused
John Rouillard <rouilj@ieee.org>
parents:
7882
diff
changeset
|
2400 return 0 |
|
851ddd72f9ce
issue2550983 - help_commands_html unused
John Rouillard <rouilj@ieee.org>
parents:
7882
diff
changeset
|
2401 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2402 # figure what the command is |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2403 try: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2404 functions = self.commands.get(command) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2405 except KeyError: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2406 # not a valid command |
|
5250
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
2407 print(_('Unknown command "%(command)s" ("help commands" for a ' |
| 6585 | 2408 'list)') % locals()) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2409 return 1 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2410 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2411 # check for multiple matches |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2412 if len(functions) > 1: |
| 6585 | 2413 print(_('Multiple commands match "%(command)s": %(list)s') % |
| 6180 | 2414 {'command': command, |
| 2415 'list': ', '.join([i[0] for i in functions])}) | |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2416 return 1 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2417 command, function = functions[0] |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2418 |
|
7392
bd6523c84a95
Fix test failure caused by making genconfig trackerless
John Rouillard <rouilj@ieee.org>
parents:
7380
diff
changeset
|
2419 if command in ['genconfig', 'templates']: |
|
bd6523c84a95
Fix test failure caused by making genconfig trackerless
John Rouillard <rouilj@ieee.org>
parents:
7380
diff
changeset
|
2420 try: |
|
7773
ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
John Rouillard <rouilj@ieee.org>
parents:
7755
diff
changeset
|
2421 return function(args[1:]) |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2422 except UsageError as message: |
| 7566 | 2423 return self.usageError_feedback(message, function) |
|
7392
bd6523c84a95
Fix test failure caused by making genconfig trackerless
John Rouillard <rouilj@ieee.org>
parents:
7380
diff
changeset
|
2424 |
| 1098 | 2425 # make sure we have a tracker_home |
| 2426 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
|
2427 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
|
2428 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
|
2429 else: |
|
6ae426092d7d
Some patches from wking to make admin.py bypass checks like nuking a
John Rouillard <rouilj@ieee.org>
parents:
5110
diff
changeset
|
2430 self.tracker_home = os.curdir |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2431 |
|
738
7e093cbaaa98
split instance initialisation into two steps...
Richard Jones <richard@users.sourceforge.net>
parents:
698
diff
changeset
|
2432 # 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
|
2433 if command == 'initialise': |
|
656
eae9b69a0115
[SF#527416] roundup-admin uses undefined value
Richard Jones <richard@users.sourceforge.net>
parents:
649
diff
changeset
|
2434 try: |
| 1098 | 2435 return self.do_initialise(self.tracker_home, args) |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2436 except UsageError as message: |
| 7566 | 2437 return self.usageError_feedback(message, function) |
|
738
7e093cbaaa98
split instance initialisation into two steps...
Richard Jones <richard@users.sourceforge.net>
parents:
698
diff
changeset
|
2438 elif command == 'install': |
|
7e093cbaaa98
split instance initialisation into two steps...
Richard Jones <richard@users.sourceforge.net>
parents:
698
diff
changeset
|
2439 try: |
| 1098 | 2440 return self.do_install(self.tracker_home, args) |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2441 except UsageError as message: |
| 7566 | 2442 return self.usageError_feedback(message, function) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2443 |
| 1098 | 2444 # get the tracker |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2445 try: |
|
7253
393ae88bf7b1
Cache result of tracker open in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7252
diff
changeset
|
2446 if self.tracker and not self.settings['_reopen_tracker']: |
|
393ae88bf7b1
Cache result of tracker open in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7252
diff
changeset
|
2447 tracker = self.tracker |
|
393ae88bf7b1
Cache result of tracker open in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7252
diff
changeset
|
2448 else: |
|
393ae88bf7b1
Cache result of tracker open in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7252
diff
changeset
|
2449 if self.settings["verbose"]: |
|
393ae88bf7b1
Cache result of tracker open in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7252
diff
changeset
|
2450 print("Reopening tracker") |
|
393ae88bf7b1
Cache result of tracker open in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7252
diff
changeset
|
2451 tracker = roundup.instance.open(self.tracker_home) |
|
393ae88bf7b1
Cache result of tracker open in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
7252
diff
changeset
|
2452 self.tracker = tracker |
|
7544
4c90a57c89e3
initialize indexer_backend pragma from config.
John Rouillard <rouilj@ieee.org>
parents:
7543
diff
changeset
|
2453 self.settings['indexer_backend'] = self.tracker.config['INDEXER'] |
|
4c90a57c89e3
initialize indexer_backend pragma from config.
John Rouillard <rouilj@ieee.org>
parents:
7543
diff
changeset
|
2454 |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2455 except ValueError as message: # noqa: F841 -- used from locals |
| 1098 | 2456 self.tracker_home = '' |
| 6180 | 2457 print(_("Error: Couldn't open tracker: %(message)s") % locals()) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2458 return 1 |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2459 except NoConfigError as message: # noqa: F841 -- used from locals |
|
5230
62a88d69ac52
Add new command updateconfig to admin command. This acts like
John Rouillard <rouilj@ieee.org>
parents:
5229
diff
changeset
|
2460 self.tracker_home = '' |
| 6180 | 2461 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
|
2462 return 1 |
| 6959 | 2463 # message used via locals |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2464 except ParsingOptionError as message: # noqa: F841 -- used from locals |
|
6557
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6527
diff
changeset
|
2465 print("%(message)s" % locals()) |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6527
diff
changeset
|
2466 return 1 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2467 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2468 # only open the database once! |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2469 if not self.db: |
|
5979
33a7b10618a6
Add support for -u to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
5897
diff
changeset
|
2470 self.db = tracker.open(self.name) |
| 7439 | 2471 # don't use tracker.config["TRACKER_LANGUAGE"] here as the |
|
6658
408fd477761f
Add i18n object to roundupdb.Database
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6585
diff
changeset
|
2472 # 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
|
2473 # environment. |
|
408fd477761f
Add i18n object to roundupdb.Database
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6585
diff
changeset
|
2474 # This is needed to fetch the locale's of the tracker's home dir. |
| 6959 | 2475 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
|
2476 |
| 4781 | 2477 self.db.tx_Source = 'cli' |
| 2478 | |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2479 # do the command |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2480 ret = 0 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2481 try: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2482 ret = function(args[1:]) |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2483 except UsageError as message: |
|
7392
bd6523c84a95
Fix test failure caused by making genconfig trackerless
John Rouillard <rouilj@ieee.org>
parents:
7380
diff
changeset
|
2484 ret = self.usageError_feedback(message, function) |
| 6180 | 2485 except Exception: |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2486 import traceback |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2487 traceback.print_exc() |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2488 ret = 1 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2489 return ret |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2490 |
|
7802
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2491 def history_features(self, feature): |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2492 """ self.settings['history_features'] = 0: load rc, load/save history |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2493 self.settings['history_features'] = 1: do not load history |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2494 self.settings['history_features'] = 2: do not save history |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2495 self.settings['history_features'] = 4: don't load rc |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2496 """ |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2497 |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2498 features = { # bit bashing |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2499 'load_history': 1, |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2500 'save_history': 2, |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2501 'load_rc': 4} |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2502 |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2503 # setting the bit disables the feature, so use not. |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2504 return not self.settings['history_features'] & features[feature] |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2505 |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2506 def get_readline_init_file(self): |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2507 return os.path.join(os.path.expanduser("~"), |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2508 ".roundup_admin_rlrc") |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2509 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2510 def interactive(self): |
|
4067
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
2511 """Run in an interactive mode |
|
7309ac3b6e24
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4066
diff
changeset
|
2512 """ |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2513 print(_('Roundup %s ready for input.\nType "help" for help.') |
|
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2514 % roundup_version) |
|
7795
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2515 |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2516 initfile = self.get_readline_init_file() |
|
7795
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2517 histfile = os.path.join(os.path.expanduser("~"), |
|
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2518 ".roundup_admin_history") |
|
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2519 |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2520 if self.readline: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2521 # clear any history that might be left over from caller |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2522 # when reusing AdminTool from tests or program. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2523 self.readline.clear_history() |
|
7798
f84f7879c768
fix: handle case where readline init file is missing
John Rouillard <rouilj@ieee.org>
parents:
7797
diff
changeset
|
2524 try: |
|
7802
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2525 if self.history_features('load_rc'): |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2526 self.readline.read_init_file(initfile) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2527 except FileNotFoundError: |
|
7798
f84f7879c768
fix: handle case where readline init file is missing
John Rouillard <rouilj@ieee.org>
parents:
7797
diff
changeset
|
2528 # file is optional |
|
f84f7879c768
fix: handle case where readline init file is missing
John Rouillard <rouilj@ieee.org>
parents:
7797
diff
changeset
|
2529 pass |
|
f84f7879c768
fix: handle case where readline init file is missing
John Rouillard <rouilj@ieee.org>
parents:
7797
diff
changeset
|
2530 |
|
7795
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2531 try: |
|
7802
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2532 if self.history_features('load_history'): |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2533 self.readline.read_history_file(histfile) |
|
7799
10da9e12c10f
fix: replace FileNotFoundError with IOError
John Rouillard <rouilj@ieee.org>
parents:
7798
diff
changeset
|
2534 except IOError: # FileNotFoundError under python3 |
|
7795
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2535 # no history file yet |
|
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2536 pass |
|
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2537 |
|
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2538 # Default history length is unlimited. |
|
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2539 # Set persistently in readline init file |
|
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2540 # Pragma history_length allows setting on a per |
|
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2541 # invocation basis at startup |
|
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2542 if self.settings['history_length'] != -1: |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2543 self.readline.set_history_length( |
|
7795
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2544 self.settings['history_length']) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2545 |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2546 if hasattr(self.readline, 'backend'): |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2547 # FIXME after min 3.13 version; no backend prints pyreadline3 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2548 print(_("Readline enabled using %s.") % self.readline.backend) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2549 else: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2550 print(_("Readline enabled using unknown library.")) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2551 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2552 else: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2553 print(_('Command history and line editing not available')) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2554 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2555 autosave_enabled = sys.stdin.isatty() and sys.stdout.isatty() |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2556 while 1: |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2557 try: |
|
7182
0c6617db0b97
Add testing interactive mode to roundup_admin. remove redundant imports
John Rouillard <rouilj@ieee.org>
parents:
7178
diff
changeset
|
2558 command = self.my_input('roundup> ') |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2559 # clear an input hook in case it was used to prefill |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2560 # buffer. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2561 self.readline.set_pre_input_hook() |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2562 except EOFError: |
|
5250
ac7fe3483206
Make admin.py 2/3-agnostic.
Eric S. Raymond <esr@thyrsus.com>
parents:
5248
diff
changeset
|
2563 print(_('exit...')) |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2564 break |
| 6959 | 2565 if not command: continue # noqa: E701 |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2566 if command.startswith('!'): # Pull numbered command from history |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2567 print_only = command.endswith(":p") |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2568 try: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2569 hist_num = int(command[1:]) \ |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2570 if not print_only else int(command[1:-2]) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2571 command = self.readline.get_history_item(hist_num) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2572 except ValueError: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2573 # pass the unknown command |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2574 pass |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2575 else: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2576 if autosave_enabled and \ |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2577 hasattr(self.readline, "replace_history_item"): |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2578 # history has the !23 input. Replace it if possible. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2579 # replace_history_item not supported by pyreadline3 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2580 # so !23 will show up in history not the command. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2581 self.readline.replace_history_item( |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2582 self.readline.get_current_history_length() - 1, |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2583 command) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2584 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2585 if print_only: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2586 # fill the edit buffer with the command |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2587 # the user selected. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2588 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2589 # from https://stackoverflow.com/questions/8505163/is-it-possible-to-prefill-a-input-in-python-3s-command-line-interface |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2590 # This triggers: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2591 # B023 Function definition does not bind loop variable |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2592 # `command` |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2593 # in ruff. command will be the value of the command |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2594 # variable at the time the function is run. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2595 # Not the value at define time. This is ok since |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2596 # hook is run before command is changed by the |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2597 # return from (readline) input. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2598 def hook(): |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2599 self.readline.insert_text(command) # noqa: B023 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2600 self.readline.redisplay() |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2601 self.readline.set_pre_input_hook(hook) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2602 # we clear the hook after the next line is read. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2603 continue |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2604 |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2605 if not autosave_enabled: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2606 # needed to make testing work and also capture |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2607 # commands received on stdin from file/other command |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2608 # output. Disable saving with pragma on command line: |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2609 # -P history_features=2. |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2610 self.readline.add_history(command) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2611 |
|
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
|
2612 try: |
|
7178
db06d4aeb978
unshadow stdlib token from roundup's token.
John Rouillard <rouilj@ieee.org>
parents:
7093
diff
changeset
|
2613 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
|
2614 except ValueError: |
| 6180 | 2615 continue # Ignore invalid quoted token |
| 6959 | 2616 if not args: continue # noqa: E701 |
|
8435
1a93dc58f975
feat: add 'q' as alias to quit to exit interactive roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8393
diff
changeset
|
2617 if args[0] in ('q', 'quit', 'exit') and len(args) == 1: |
|
1a93dc58f975
feat: add 'q' as alias to quit to exit interactive roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8393
diff
changeset
|
2618 break # noqa: E701 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2619 self.run_command(args) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2620 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2621 # 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
|
2622 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
|
2623 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
|
2624 if commit and commit[0].lower() == 'y': |
|
8446
14c7c07b32d8
feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents:
8440
diff
changeset
|
2625 self.run_command(["commit"]) |
|
7795
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2626 |
|
d7d68da9878f
save roundup-admin history between sessions.
John Rouillard <rouilj@ieee.org>
parents:
7773
diff
changeset
|
2627 # looks like histfile is saved with mode 600 |
|
8439
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2628 if self.readline and self.history_features('save_history'): |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2629 self.readline.write_history_file(histfile) |
|
3bdae15252c6
feat: add support for ! history and readline command in roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
8435
diff
changeset
|
2630 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2631 return 0 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2632 |
|
7752
b2dbab2b34bc
fix(refactor): multiple fixups using ruff linter; more testing.
John Rouillard <rouilj@ieee.org>
parents:
7687
diff
changeset
|
2633 def main(self): # noqa: PLR0912, PLR0911 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2634 try: |
|
7546
534f8bdb8f94
Add -P pragma=value command line option to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7545
diff
changeset
|
2635 opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdP:sS:vV') |
|
5248
198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents:
5245
diff
changeset
|
2636 except getopt.GetoptError as e: |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2637 self.usage(str(e)) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2638 return 1 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2639 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2640 # handle command-line args |
| 1098 | 2641 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
|
2642 self.name = 'admin' |
|
33a7b10618a6
Add support for -u to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
5897
diff
changeset
|
2643 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
|
2644 if 'ROUNDUP_LOGIN' in os.environ: |
| 6585 | 2645 login_env = os.environ['ROUNDUP_LOGIN'].split(':') |
| 2646 self.name = login_env[0] | |
| 2647 if len(login_env) > 1: | |
| 2648 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
|
2649 self.separator = None |
|
053065585406
added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents:
1563
diff
changeset
|
2650 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
|
2651 self.verbose = 0 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2652 for opt, arg in opts: |
|
7797
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
2653 if opt == '-h': |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2654 self.usage() |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2655 return 0 |
|
7797
8bdf0484215c
Summary: feat: roundup-admin history command has human interpretable output
John Rouillard <rouilj@ieee.org>
parents:
7796
diff
changeset
|
2656 elif opt == '-v': # noqa: RET505 - allow elif after returns |
| 6180 | 2657 print('%s (python %s)' % (roundup_version, |
| 2658 sys.version.split()[0])) | |
|
2186
3f89c8ffe4f1
version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents:
2184
diff
changeset
|
2659 return 0 |
|
3602
064515f658e8
verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents:
3544
diff
changeset
|
2660 elif opt == '-V': |
|
064515f658e8
verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents:
3544
diff
changeset
|
2661 self.verbose = 1 |
|
064515f658e8
verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents:
3544
diff
changeset
|
2662 elif opt == '-i': |
| 1098 | 2663 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
|
2664 elif opt == '-c': |
| 6180 | 2665 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
|
2666 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
|
2667 return 1 |
|
1566
053065585406
added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents:
1563
diff
changeset
|
2668 self.separator = ',' |
|
3602
064515f658e8
verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents:
3544
diff
changeset
|
2669 elif opt == '-S': |
| 6180 | 2670 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
|
2671 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
|
2672 return 1 |
|
1566
053065585406
added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents:
1563
diff
changeset
|
2673 self.separator = arg |
|
3602
064515f658e8
verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents:
3544
diff
changeset
|
2674 elif opt == '-s': |
| 6180 | 2675 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
|
2676 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
|
2677 return 1 |
|
1566
053065585406
added command-line functionality for roundup-adming (feature [SF#687664])
Richard Jones <richard@users.sourceforge.net>
parents:
1563
diff
changeset
|
2678 self.separator = ' ' |
|
3602
064515f658e8
verbose output during import is optional now [SF#1475624]
Richard Jones <richard@users.sourceforge.net>
parents:
3544
diff
changeset
|
2679 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
|
2680 self.print_designator = 1 |
|
7546
534f8bdb8f94
Add -P pragma=value command line option to roundup-admin.
John Rouillard <rouilj@ieee.org>
parents:
7545
diff
changeset
|
2681 elif opt == '-P': |
|
7802
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2682 try: |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2683 self.do_pragma([arg]) |
|
7c0a8088b053
feat: add support for controlling readline history features
John Rouillard <rouilj@ieee.org>
parents:
7800
diff
changeset
|
2684 except UsageError as e: |
|
7832
b530069f3120
chore(lint): formatting whitespace consolidate nested if ...
John Rouillard <rouilj@ieee.org>
parents:
7821
diff
changeset
|
2685 print('\n%s\n' % e) |
|
5979
33a7b10618a6
Add support for -u to roundup-admin
John Rouillard <rouilj@ieee.org>
parents:
5897
diff
changeset
|
2686 elif opt == '-u': |
| 6585 | 2687 login_opt = arg.split(':') |
| 2688 self.name = login_opt[0] | |
| 2689 if len(login_opt) > 1: | |
| 2690 self.password = login_opt[1] | |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2691 |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2692 # if no command - go interactive |
|
1133
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1108
diff
changeset
|
2693 # 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
|
2694 ret = 0 |
|
1133
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1108
diff
changeset
|
2695 try: |
|
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1108
diff
changeset
|
2696 if not args: |
|
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1108
diff
changeset
|
2697 self.interactive() |
|
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1108
diff
changeset
|
2698 else: |
|
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1108
diff
changeset
|
2699 ret = self.run_command(args) |
|
8446
14c7c07b32d8
feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents:
8440
diff
changeset
|
2700 if self.db: self.run_command(["commit"]) # noqa: E701 |
|
1133
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1108
diff
changeset
|
2701 return ret |
|
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1108
diff
changeset
|
2702 finally: |
|
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1108
diff
changeset
|
2703 if self.db: |
|
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1108
diff
changeset
|
2704 self.db.close() |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2705 |
| 6180 | 2706 |
|
484
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2707 if __name__ == '__main__': |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2708 tool = AdminTool() |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2709 sys.exit(tool.main()) |
|
b35f229dd049
I18N'ed roundup admin...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2710 |
|
2767
f6072f395f87
do_install: consider both old- and new-style layouts in reinstall check;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2736
diff
changeset
|
2711 # vim: set filetype=python sts=4 sw=4 et si : |
