Skip to content

Commit 98798ba

Browse files
committed
- issue2551190 - Allow roundup-admin reindex to work in batches.
Running: roundup-admin -i ... reindex issue:1-1000 will reindex the first 1000 issues while reporting any missing issues in the range. Also completion progress is reported when indexing a specific class. Note this require a chnge that makes an invalid command like: reindex issue23f to error with no such class issue23f. It used to reindex issue23 which I consider a bug. Updates to man page admin_guide.py. Tests added.
1 parent 997865e commit 98798ba

File tree

5 files changed

+124
-13
lines changed

5 files changed

+124
-13
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ Features:
150150
Myers, config settings and docs by John Rouillard.)
151151
- roundup-admin genconfig does not need a tracker home to run. (John
152152
Rouillard)
153+
- issue2551190 - Allow roundup-admin reindex to work in
154+
batches. Running roundup-admin -i ... reindex issue:1-1000 will
155+
reindex the first 1000 issues while reporting any missing issues
156+
in the range. Also completion progress is reported when indexing a
157+
specific class.
153158

154159
2022-07-13 2.2.0
155160

doc/admin_guide.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,13 +1242,13 @@ The basic usage is::
12421242

12431243
Options:
12441244
-i instance home -- specify the issue tracker "home directory" to administer
1245-
-u -- the user[:password] to use for commands
1245+
-u -- the user[:password] to use for commands (default admin)
12461246
-d -- print full designators not just class id numbers
12471247
-c -- when outputting lists of data, comma-separate them.
1248-
Same as '-S ","'.
1248+
Same as '-S ","'.
12491249
-S <string> -- when outputting lists of data, string-separate them
12501250
-s -- when outputting lists of data, space-separate them.
1251-
Same as '-S " "'.
1251+
Same as '-S " "'.
12521252
-V -- be verbose when importing
12531253
-v -- report Roundup and Python versions (and quit)
12541254

@@ -1280,13 +1280,13 @@ The basic usage is::
12801280
migrate
12811281
pack period | date
12821282
perftest [mode] [arguments]*
1283-
pragma setting=value
1284-
reindex [classname|designator]*
1283+
pragma setting=value | 'list'
1284+
reindex [classname|classname:#-#|designator]*
12851285
restore designator[,designator]*
12861286
retire designator[,designator]*
12871287
rollback
12881288
security [Role name]
1289-
set items property=value property=value ...
1289+
set items property=value [property=value ...]
12901290
specification classname
12911291
table classname [property[,property]*]
12921292
templates [trace_search]

roundup/admin.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ def do_genconfig(self, args, update=False):
803803
Generate a new tracker config file (ini style) with default
804804
values in <filename>.
805805
"""
806+
import pdb; pdb.set_trace()
806807
if len(args) < 1:
807808
raise UsageError(_('Not enough arguments supplied'))
808809

@@ -1530,28 +1531,50 @@ def do_pragma(self, args):
15301531

15311532
self.settings[setting] = value
15321533

1533-
designator_re = re.compile('([A-Za-z]+)([0-9]+)')
1534+
designator_re = re.compile('([A-Za-z]+)([0-9]+)$')
1535+
designator_rng = re.compile('([A-Za-z]+):([0-9]+)-([0-9]+)$')
15341536

1535-
def do_reindex(self, args, desre=designator_re):
1536-
''"""Usage: reindex [classname|designator]*
1537+
def do_reindex(self, args, desre=designator_re, desrng=designator_rng):
1538+
''"""Usage: reindex [classname|classname:#-#|designator]*
15371539
Re-generate a tracker's search indexes.
15381540
15391541
This will re-generate the search indexes for a tracker.
15401542
This will typically happen automatically.
1543+
1544+
You can incrementally reindex using an argument like:
1545+
1546+
reindex issue:23-1000
1547+
1548+
to reindex issue class items 23-1000. Missing items
1549+
are reported but do not stop indexing of the range.
15411550
"""
1551+
from roundup import support
15421552
if args:
15431553
for arg in args:
15441554
m = desre.match(arg)
1555+
r = desrng.match(arg)
15451556
if m:
15461557
cl = self.get_class(m.group(1))
15471558
try:
15481559
cl.index(m.group(2))
15491560
except IndexError:
15501561
raise UsageError(_('no such item "%(designator)s"') % {
15511562
'designator': arg})
1563+
elif r:
1564+
cl = self.get_class(r.group(1))
1565+
for item in support.Progress(
1566+
'Reindexing %s' % r.group(1),
1567+
range(int(r.group(2)), int(r.group(3)))):
1568+
try:
1569+
cl.index(str(item))
1570+
except IndexError:
1571+
print(_('no such item "%(class)s%(id)s"') % {
1572+
'class': r.group(1),
1573+
'id': item})
1574+
15521575
else:
1553-
cl = self.get_class(arg)
1554-
self.db.reindex(arg)
1576+
cl = self.get_class(arg) # Bad class raises UsageError
1577+
self.db.reindex(arg, show_progress=True)
15551578
else:
15561579
self.db.reindex(show_progress=True)
15571580
return 0

share/man/man1/roundup-admin.1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,11 @@ will turn on verbose mode for roundup-admin.
220220
will show all settings and their current values. If verbose
221221
is enabled hidden settings and descriptions will be shown.
222222
.TP
223-
\fBreindex\fP \fI[classname|designator]*\fP
224-
This will re-generate the search indexes for a tracker.
223+
\fBreindex\fP \fI[classname|classname:#-#|designator]*\fP This will
224+
re-generate the search indexes for a tracker. You can specify a
225+
specific item (or items) (e.g. issue23), range(s) of items
226+
(e.g. issue:1-1000), class(es) (e.g. issue) or reindex all items in
227+
the database if no arguments are supplied.
225228
.TP
226229
\fBrestore\fP \fIdesignator[,designator]*\fP
227230
Restore the retired node specified by designator.

test/test_admin.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,86 @@ def testPragma(self):
10351035
# -----
10361036
AdminTool.my_input = orig_input
10371037

1038+
def testReindex(self):
1039+
''' Note the tests will fail if you run this under pdb.
1040+
the context managers capture the pdb prompts and this screws
1041+
up the stdout strings with (pdb) prefixed to the line.
1042+
'''
1043+
self.install_init()
1044+
1045+
# create an issue
1046+
self.admin=AdminTool()
1047+
sys.argv=['main', '-i', self.dirname, 'create', 'issue',
1048+
'title="foo bar"', 'assignedto=admin' ]
1049+
ret = self.admin.main()
1050+
1051+
# reindex everything
1052+
self.admin=AdminTool()
1053+
with captured_output() as (out, err):
1054+
sys.argv=['main', '-i', self.dirname, 'reindex']
1055+
ret = self.admin.main()
1056+
out = out.getvalue().strip()
1057+
print(len(out))
1058+
print(repr(out))
1059+
# make sure priority is being reindexed
1060+
self.assertIn('Reindex priority 40%', out)
1061+
1062+
1063+
# reindex whole class
1064+
self.admin=AdminTool()
1065+
with captured_output() as (out, err):
1066+
sys.argv=['main', '-i', self.dirname, 'reindex', 'issue']
1067+
ret = self.admin.main()
1068+
1069+
out = out.getvalue().strip()
1070+
print(len(out))
1071+
print(repr(out))
1072+
self.assertEqual(out,
1073+
'Reindex issue 0% \rReindex issue 100% \rReindex issue done')
1074+
self.assertEqual(len(out), 170)
1075+
1076+
# reindex one item
1077+
self.admin=AdminTool()
1078+
with captured_output() as (out, err):
1079+
sys.argv=['main', '-i', self.dirname, 'reindex', 'issue1']
1080+
ret = self.admin.main()
1081+
1082+
out = out.getvalue().strip()
1083+
print(len(out))
1084+
print(repr(out))
1085+
# no output when reindexing just one item
1086+
self.assertEqual(out, '')
1087+
1088+
# reindex range
1089+
self.admin=AdminTool()
1090+
with captured_output() as (out, err):
1091+
sys.argv=['main', '-i', self.dirname, 'reindex', 'issue:1-4']
1092+
ret = self.admin.main()
1093+
1094+
out = out.getvalue().strip()
1095+
print(repr(out))
1096+
self.assertIn('no such item "issue3"', out)
1097+
1098+
# reindex bad class
1099+
self.admin=AdminTool()
1100+
with captured_output() as (out, err):
1101+
sys.argv=['main', '-i', self.dirname, 'reindex', 'issue1-4']
1102+
ret = self.admin.main()
1103+
1104+
out = out.getvalue().strip()
1105+
print(repr(out))
1106+
self.assertIn('Error: no such class "issue1-4"', out)
1107+
1108+
# reindex bad item
1109+
self.admin=AdminTool()
1110+
with captured_output() as (out, err):
1111+
sys.argv=['main', '-i', self.dirname, 'reindex', 'issue14']
1112+
ret = self.admin.main()
1113+
1114+
out = out.getvalue().strip()
1115+
print(repr(out))
1116+
self.assertIn('Error: no such item "issue14"', out)
1117+
10381118
def disabletestHelpInitopts(self):
10391119

10401120
''' Note the tests will fail if you run this under pdb.

0 commit comments

Comments
 (0)