Skip to content

Commit e70c785

Browse files
committed
- issue2551103 - add pragma 'display_protected' to roundup-admin.
If setting is true, print protected attributes like id, activity, actor... when using display or specification subcommands.
1 parent bb1b59a commit e70c785

File tree

3 files changed

+84
-5
lines changed

3 files changed

+84
-5
lines changed

CHANGES.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ v2.7.2 or later are required to run newer releases of Roundup.
1212
Roundup 2.0 supports Python 3.4 and later. Roundup 2.1.0 supports
1313
python 3.6 or newer (3.4/3.5 might work, but they are not tested).
1414

15+
2024-XX-YY 2.4.0
16+
17+
Fixed:
18+
19+
Features:
20+
21+
- issue2551103 - add pragma 'display_protected' to roundup-admin. If
22+
true, print protected attributes like id, activity, actor...
23+
when using display or specification subcommands. (John Rouillard)
24+
1525
2023-07-13 2.3.0
1626

1727
Fixed:

roundup/admin.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def __init__(self):
114114
}
115115
self.settings_help = {
116116
'display_protected':
117-
_("Have 'display designator' show protected fields: creator. NYI"),
117+
_("Have 'display designator' show protected fields: "
118+
"creator, id etc."),
118119

119120
'indexer_backend':
120121
_("Set indexer to use when running 'reindex' NYI"),
@@ -522,10 +523,18 @@ def do_display(self, args):
522523
cl = self.get_class(classname)
523524

524525
# display the values
525-
keys = sorted(cl.properties)
526+
normal_props = sorted(cl.properties)
527+
if self.settings['display_protected']:
528+
keys = sorted(cl.getprops())
529+
else:
530+
keys = normal_props
531+
526532
for key in keys:
527533
value = cl.get(nodeid, key)
528-
print(_('%(key)s: %(value)s') % locals())
534+
# prepend * for protected propeties else just indent
535+
# with space.
536+
protected = "*" if key not in normal_props else ' '
537+
print(_('%(protected)s%(key)s: %(value)s') % locals())
529538

530539
def do_export(self, args, export_files=True):
531540
''"""Usage: export [[-]class[,class]] export_dir
@@ -1479,6 +1488,19 @@ def do_pragma(self, args):
14791488
will show all settings and their current values. If verbose
14801489
is enabled hidden settings and descriptions will be shown.
14811490
"""
1491+
"""
1492+
The following are to be implemented:
1493+
1494+
indexer - Not Implemented - set indexer to use for
1495+
reindex. Use when changing indexer backends.
1496+
1497+
exportfiles={true|false} - Not Implemented - If true
1498+
(default) export/import db tables and files. If
1499+
False, export/import just database tables, not
1500+
files. Use for faster database migration.
1501+
Replaces exporttables/importtables with
1502+
exportfiles=false then export/import
1503+
"""
14821504

14831505
if len(args) < 1:
14841506
raise UsageError(_('Not enough arguments supplied'))
@@ -1798,8 +1820,12 @@ def do_specification(self, args):
17981820

17991821
# get the key property
18001822
keyprop = cl.getkey()
1801-
for key in cl.properties:
1802-
value = cl.properties[key]
1823+
if self.settings['display_protected']:
1824+
properties = cl.getprops()
1825+
else:
1826+
properties = cl.properties
1827+
for key in properties:
1828+
value = properties[key]
18031829
if keyprop == key:
18041830
sys.stdout.write(_('%(key)s: %(value)s (key property)\n') %
18051831
locals())

test/test_admin.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,26 @@ def testPragma(self):
10321032
expected = 'Error: Internal error: pragma can not handle values of type: float'
10331033
self.assertIn(expected, out)
10341034

1035+
1036+
# -----
1037+
inputs = iter(["pragma display_protected=yes",
1038+
"display user1",
1039+
"quit"])
1040+
AdminTool.my_input = lambda _self, _prompt: next(inputs)
1041+
1042+
self.install_init()
1043+
self.admin=AdminTool()
1044+
sys.argv=['main', '-i', self.dirname]
1045+
1046+
with captured_output() as (out, err):
1047+
ret = self.admin.main()
1048+
1049+
out = out.getvalue().strip()
1050+
1051+
print(ret)
1052+
expected = '\n*creation: '
1053+
self.assertIn(expected, out)
1054+
10351055
# -----
10361056
AdminTool.my_input = orig_input
10371057

@@ -1479,6 +1499,7 @@ def testSpecification(self):
14791499
'timezone: <roundup.hyperdb.String>',
14801500
'password: <roundup.hyperdb.Password>',
14811501
]
1502+
14821503

14831504
with captured_output() as (out, err):
14841505
sys.argv=['main', '-i', self.dirname, 'specification', 'user']
@@ -1488,6 +1509,28 @@ def testSpecification(self):
14881509
print(outlist)
14891510
self.assertEqual(sorted(outlist), sorted(spec))
14901511

1512+
# -----
1513+
inputs = iter(["pragma display_protected=1", "spec user", "quit"])
1514+
AdminTool.my_input = lambda _self, _prompt: next(inputs)
1515+
1516+
self.install_init()
1517+
self.admin=AdminTool()
1518+
sys.argv=['main', '-i', self.dirname]
1519+
1520+
with captured_output() as (out, err):
1521+
ret = self.admin.main()
1522+
1523+
# strip greeting and help text lines
1524+
outlist = out.getvalue().strip().split('\n')[2:]
1525+
1526+
protected = [ 'id: <roundup.hyperdb.String>',
1527+
'creation: <roundup.hyperdb.Date>',
1528+
'activity: <roundup.hyperdb.Date>',
1529+
'creator: <roundup.hyperdb.Link to "user">',
1530+
'actor: <roundup.hyperdb.Link to "user">']
1531+
print(outlist)
1532+
self.assertEqual(sorted(outlist), sorted(spec + protected))
1533+
14911534
def testRetireRestore(self):
14921535
''' Note the tests will fail if you run this under pdb.
14931536
the context managers capture the pdb prompts and this screws

0 commit comments

Comments
 (0)