Mercurial > p > roundup > code
comparison roundup/admin.py @ 7547:c8c4514f4c3e
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.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 14 Jul 2023 20:34:30 -0400 |
| parents | 534f8bdb8f94 |
| children | 73dfa9df9fb0 |
comparison
equal
deleted
inserted
replaced
| 7546:534f8bdb8f94 | 7547:c8c4514f4c3e |
|---|---|
| 105 self.force = None | 105 self.force = None |
| 106 self.settings = { | 106 self.settings = { |
| 107 'display_protected': False, | 107 'display_protected': False, |
| 108 'indexer_backend': "as set in config.ini", | 108 'indexer_backend': "as set in config.ini", |
| 109 '_reopen_tracker': False, | 109 '_reopen_tracker': False, |
| 110 'show_retired': False, | 110 'show_retired': "no", |
| 111 '_retired_val': False, | |
| 111 'verbose': False, | 112 'verbose': False, |
| 112 '_inttest': 3, | 113 '_inttest': 3, |
| 113 '_floattest': 3.5, | 114 '_floattest': 3.5, |
| 114 } | 115 } |
| 115 self.settings_help = { | 116 self.settings_help = { |
| 121 _("Set indexer to use when running 'reindex' NYI"), | 122 _("Set indexer to use when running 'reindex' NYI"), |
| 122 | 123 |
| 123 '_reopen_tracker': | 124 '_reopen_tracker': |
| 124 _("Force reopening of tracker when running each command."), | 125 _("Force reopening of tracker when running each command."), |
| 125 | 126 |
| 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."), | |
| 127 'verbose': _("Enable verbose output: tracing, descriptions..."), | 129 'verbose': _("Enable verbose output: tracing, descriptions..."), |
| 128 | 130 |
| 129 '_inttest': "Integer valued setting. For testing only.", | 131 '_inttest': "Integer valued setting. For testing only.", |
| 130 '_floattest': "Float valued setting. For testing only.", | 132 '_floattest': "Float valued setting. For testing only.", |
| 131 } | 133 } |
| 531 else: | 533 else: |
| 532 keys = normal_props | 534 keys = normal_props |
| 533 | 535 |
| 534 for key in keys: | 536 for key in keys: |
| 535 value = cl.get(nodeid, key) | 537 value = cl.get(nodeid, key) |
| 536 # prepend * for protected propeties else just indent | 538 # prepend * for protected properties else just indent |
| 537 # with space. | 539 # with space. |
| 538 protected = "*" if key not in normal_props else ' ' | 540 protected = "*" if key not in normal_props else ' ' |
| 539 print(_('%(protected)s%(key)s: %(value)s') % locals()) | 541 print(_('%(protected)s%(key)s: %(value)s') % locals()) |
| 540 | 542 |
| 541 def do_export(self, args, export_files=True): | 543 def do_export(self, args, export_files=True): |
| 1294 """ | 1296 """ |
| 1295 if len(args) > 2: | 1297 if len(args) > 2: |
| 1296 raise UsageError(_('Too many arguments supplied')) | 1298 raise UsageError(_('Too many arguments supplied')) |
| 1297 if len(args) < 1: | 1299 if len(args) < 1: |
| 1298 raise UsageError(_('Not enough arguments supplied')) | 1300 raise UsageError(_('Not enough arguments supplied')) |
| 1301 | |
| 1302 retired = self.settings['_retired_val'] | |
| 1303 | |
| 1299 classname = args[0] | 1304 classname = args[0] |
| 1300 | 1305 |
| 1301 # get the class | 1306 # get the class |
| 1302 cl = self.get_class(classname) | 1307 cl = self.get_class(classname) |
| 1303 | 1308 |
| 1309 | 1314 |
| 1310 if self.separator: | 1315 if self.separator: |
| 1311 if len(args) == 2: | 1316 if len(args) == 2: |
| 1312 # create a list of propnames since user specified propname | 1317 # create a list of propnames since user specified propname |
| 1313 proplist = [] | 1318 proplist = [] |
| 1314 for nodeid in cl.list(): | 1319 for nodeid in cl.getnodeids(retired=retired): |
| 1315 try: | 1320 try: |
| 1316 proplist.append(cl.get(nodeid, propname)) | 1321 proplist.append(cl.get(nodeid, propname)) |
| 1317 except KeyError: | 1322 except KeyError: |
| 1318 raise UsageError(_('%(classname)s has no property ' | 1323 raise UsageError(_('%(classname)s has no property ' |
| 1319 '"%(propname)s"') % locals()) | 1324 '"%(propname)s"') % locals()) |
| 1320 print(self.separator.join(proplist)) | 1325 print(self.separator.join(proplist)) |
| 1321 else: | 1326 else: |
| 1322 # create a list of index id's since user didn't specify | 1327 # create a list of index id's since user didn't specify |
| 1323 # otherwise | 1328 # otherwise |
| 1324 print(self.separator.join(cl.list())) | 1329 print(self.separator.join(cl.getnodeids(retired=retired))) |
| 1325 else: | 1330 else: |
| 1326 for nodeid in cl.list(): | 1331 for nodeid in cl.getnodeids(retired=retired): |
| 1327 try: | 1332 try: |
| 1328 value = cl.get(nodeid, propname) | 1333 value = cl.get(nodeid, propname) |
| 1329 except KeyError: | 1334 except KeyError: |
| 1330 raise UsageError(_('%(classname)s has no property ' | 1335 raise UsageError(_('%(classname)s has no property ' |
| 1331 '"%(propname)s"') % locals()) | 1336 '"%(propname)s"') % locals()) |
| 1542 raise UsageError(_( | 1547 raise UsageError(_( |
| 1543 'Incorrect value for integer setting %(setting)s: ' | 1548 'Incorrect value for integer setting %(setting)s: ' |
| 1544 '%(value)s.') % {"setting": setting, "value": value}) | 1549 '%(value)s.') % {"setting": setting, "value": value}) |
| 1545 value = _val | 1550 value = _val |
| 1546 elif type(self.settings[setting]) is str: | 1551 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 | |
| 1548 else: | 1564 else: |
| 1549 raise UsageError(_('Internal error: pragma can not handle ' | 1565 raise UsageError(_('Internal error: pragma can not handle ' |
| 1550 'values of type: %s') % | 1566 'values of type: %s') % |
| 1551 type(self.settings[setting]).__name__) | 1567 type(self.settings[setting]).__name__) |
| 1552 | 1568 |
| 1861 """ | 1877 """ |
| 1862 if len(args) < 1: | 1878 if len(args) < 1: |
| 1863 raise UsageError(_('Not enough arguments supplied')) | 1879 raise UsageError(_('Not enough arguments supplied')) |
| 1864 classname = args[0] | 1880 classname = args[0] |
| 1865 | 1881 |
| 1882 retired = self.settings['_retired_val'] | |
| 1883 | |
| 1866 # get the class | 1884 # get the class |
| 1867 cl = self.get_class(classname) | 1885 cl = self.get_class(classname) |
| 1868 | 1886 |
| 1869 # figure the property names to display | 1887 # figure the property names to display |
| 1870 if len(args) > 1: | 1888 if len(args) > 1: |
| 1901 'integer width: "%(width)s"') % | 1919 'integer width: "%(width)s"') % |
| 1902 locals()) | 1920 locals()) |
| 1903 else: | 1921 else: |
| 1904 # this is going to be slow | 1922 # this is going to be slow |
| 1905 maxlen = len(spec) | 1923 maxlen = len(spec) |
| 1906 for nodeid in cl.list(): | 1924 for nodeid in cl.getnodeids(retired=retired): |
| 1907 curlen = len(str(cl.get(nodeid, spec))) | 1925 curlen = len(str(cl.get(nodeid, spec))) |
| 1908 if curlen > maxlen: | 1926 if curlen > maxlen: |
| 1909 maxlen = curlen | 1927 maxlen = curlen |
| 1910 props.append((spec, maxlen)) | 1928 props.append((spec, maxlen)) |
| 1911 | 1929 |
| 1912 # now display the heading | 1930 # now display the heading |
| 1913 print(' '.join([name.capitalize().ljust(width) | 1931 print(' '.join([name.capitalize().ljust(width) |
| 1914 for name, width in props])) | 1932 for name, width in props])) |
| 1915 | 1933 |
| 1916 # and the table data | 1934 # and the table data |
| 1917 for nodeid in cl.list(): | 1935 for nodeid in cl.getnodeids(retired=retired): |
| 1918 table_columns = [] | 1936 table_columns = [] |
| 1919 for name, width in props: | 1937 for name, width in props: |
| 1920 if name != 'id': | 1938 if name != 'id': |
| 1921 try: | 1939 try: |
| 1922 value = str(cl.get(nodeid, name)) | 1940 value = str(cl.get(nodeid, name)) |
