Skip to content

Commit 30bdd31

Browse files
committed
issue685275 - show retired/unretire commands
For roundup-admin, add pragma show_retired [no, only, both] to control showing retired items in list and table commands: no - do not show retired only - only show retired both - show retired and unretired (active) items Also sort results of Class::getnodeids() in back_anydbm.py. Anydbm Class::list() expicitly sorts the returned values and a test depends on the order of the returned items. I can't find any docs that say Class::list() sorts and there is no explicit sort in the rdbms_common.py implementation. It looks like the natural order returned in the rdbms case for these methods is sorted. However the test fails for the anydbm case if I don't sort the results of back_anydbm.py:Class::getnodeids() to match back_anydbm.py:Class::list(). This also fixes a spelling error in comment.
1 parent b36fda8 commit 30bdd31

File tree

3 files changed

+67
-9
lines changed

3 files changed

+67
-9
lines changed

roundup/admin.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def __init__(self):
107107
'display_protected': False,
108108
'indexer_backend': "as set in config.ini",
109109
'_reopen_tracker': False,
110-
'show_retired': False,
110+
'show_retired': "no",
111+
'_retired_val': False,
111112
'verbose': False,
112113
'_inttest': 3,
113114
'_floattest': 3.5,
@@ -123,7 +124,8 @@ def __init__(self):
123124
'_reopen_tracker':
124125
_("Force reopening of tracker when running each command."),
125126

126-
'show_retired': _("Show retired items in table, list etc. NYI"),
127+
'show_retired': _("Show retired items in table, list etc. One of 'no', 'only', 'both'"),
128+
'_retired_val': _("internal mapping for show_retired."),
127129
'verbose': _("Enable verbose output: tracing, descriptions..."),
128130

129131
'_inttest': "Integer valued setting. For testing only.",
@@ -533,7 +535,7 @@ def do_display(self, args):
533535

534536
for key in keys:
535537
value = cl.get(nodeid, key)
536-
# prepend * for protected propeties else just indent
538+
# prepend * for protected properties else just indent
537539
# with space.
538540
protected = "*" if key not in normal_props else ' '
539541
print(_('%(protected)s%(key)s: %(value)s') % locals())
@@ -1296,6 +1298,9 @@ def do_list(self, args):
12961298
raise UsageError(_('Too many arguments supplied'))
12971299
if len(args) < 1:
12981300
raise UsageError(_('Not enough arguments supplied'))
1301+
1302+
retired = self.settings['_retired_val']
1303+
12991304
classname = args[0]
13001305

13011306
# get the class
@@ -1311,7 +1316,7 @@ def do_list(self, args):
13111316
if len(args) == 2:
13121317
# create a list of propnames since user specified propname
13131318
proplist = []
1314-
for nodeid in cl.list():
1319+
for nodeid in cl.getnodeids(retired=retired):
13151320
try:
13161321
proplist.append(cl.get(nodeid, propname))
13171322
except KeyError:
@@ -1321,9 +1326,9 @@ def do_list(self, args):
13211326
else:
13221327
# create a list of index id's since user didn't specify
13231328
# otherwise
1324-
print(self.separator.join(cl.list()))
1329+
print(self.separator.join(cl.getnodeids(retired=retired)))
13251330
else:
1326-
for nodeid in cl.list():
1331+
for nodeid in cl.getnodeids(retired=retired):
13271332
try:
13281333
value = cl.get(nodeid, propname)
13291334
except KeyError:
@@ -1544,7 +1549,18 @@ def do_pragma(self, args):
15441549
'%(value)s.') % {"setting": setting, "value": value})
15451550
value = _val
15461551
elif type(self.settings[setting]) is str:
1547-
pass
1552+
if setting == "show_retired":
1553+
if value not in ["no", "only", "both"]:
1554+
raise UsageError(_(
1555+
'Incorrect value for setting %(setting)s: '
1556+
'%(value)s. Should be no, both, or only.') % {
1557+
"setting": setting, "value": value})
1558+
if value == "both":
1559+
self.settings['_retired_val'] = None
1560+
elif value == "only": # numerical value not boolean
1561+
self.settings['_retired_val'] = True
1562+
else: # numerical value not boolean
1563+
self.settings['_retired_val'] = False
15481564
else:
15491565
raise UsageError(_('Internal error: pragma can not handle '
15501566
'values of type: %s') %
@@ -1863,6 +1879,8 @@ def do_table(self, args):
18631879
raise UsageError(_('Not enough arguments supplied'))
18641880
classname = args[0]
18651881

1882+
retired = self.settings['_retired_val']
1883+
18661884
# get the class
18671885
cl = self.get_class(classname)
18681886

@@ -1903,7 +1921,7 @@ def do_table(self, args):
19031921
else:
19041922
# this is going to be slow
19051923
maxlen = len(spec)
1906-
for nodeid in cl.list():
1924+
for nodeid in cl.getnodeids(retired=retired):
19071925
curlen = len(str(cl.get(nodeid, spec)))
19081926
if curlen > maxlen:
19091927
maxlen = curlen
@@ -1914,7 +1932,7 @@ def do_table(self, args):
19141932
for name, width in props]))
19151933

19161934
# and the table data
1917-
for nodeid in cl.list():
1935+
for nodeid in cl.getnodeids(retired=retired):
19181936
table_columns = []
19191937
for name, width in props:
19201938
if name != 'id':

roundup/backends/back_anydbm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,8 @@ def getnodeids(self, db=None, retired=None):
17071707
finally:
17081708
if must_close:
17091709
db.close()
1710+
1711+
res.sort()
17101712
return res
17111713

17121714
num_re = re.compile(r'^\d+$')

test/test_admin.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,44 @@ def testRetireRestore(self):
16121612
expected="1: admin\n 2: anonymous\n 3: user1"
16131613
self.assertEqual(out, expected)
16141614

1615+
# test show_retired pragma three cases:
1616+
# no - no retired items
1617+
# only - only retired items
1618+
# both - all items
1619+
1620+
# verify that user4 only is listed
1621+
self.admin=AdminTool()
1622+
with captured_output() as (out, err):
1623+
sys.argv=['main', '-i', self.dirname, '-P',
1624+
'show_retired=only', 'list', 'user']
1625+
ret = self.admin.main()
1626+
out = out.getvalue().strip()
1627+
print(out)
1628+
expected="4: user1"
1629+
self.assertEqual(out, expected)
1630+
1631+
# verify that all users are shown
1632+
self.admin=AdminTool()
1633+
with captured_output() as (out, err):
1634+
sys.argv=['main', '-i', self.dirname, '-P',
1635+
'show_retired=both', 'list', 'user']
1636+
ret = self.admin.main()
1637+
out = out.getvalue().strip()
1638+
print(out)
1639+
expected="1: admin\n 2: anonymous\n 3: user1\n 4: user1"
1640+
self.assertEqual(out, expected)
1641+
1642+
1643+
# verify that active users
1644+
self.admin=AdminTool()
1645+
with captured_output() as (out, err):
1646+
sys.argv=['main', '-i', self.dirname, '-P',
1647+
'show_retired=no', 'list', 'user']
1648+
ret = self.admin.main()
1649+
out = out.getvalue().strip()
1650+
print(out)
1651+
expected="1: admin\n 2: anonymous\n 3: user1"
1652+
self.assertEqual(out, expected)
16151653

16161654

16171655
def testTable(self):

0 commit comments

Comments
 (0)