comparison roundup/admin.py @ 8095:5aed4911836b

docs: normalize all help strings and make html output look better.
author John Rouillard <rouilj@ieee.org>
date Tue, 16 Jul 2024 21:45:10 -0400
parents 586f76eb33e8
children e579aef218aa
comparison
equal deleted inserted replaced
8094:8e310a7b5e09 8095:5aed4911836b
244 def help_commands_html(self, indent_re=indent_re): 244 def help_commands_html(self, indent_re=indent_re):
245 """ Produce an HTML command list. 245 """ Produce an HTML command list.
246 """ 246 """
247 commands = sorted(iter(self.commands.values()), 247 commands = sorted(iter(self.commands.values()),
248 key=operator.attrgetter('__name__')) 248 key=operator.attrgetter('__name__'))
249 print("<table>")
249 for command in commands: 250 for command in commands:
250 h = _(command.__doc__).split('\n') 251 h = _(command.__doc__).split('\n')
251 name = command.__name__[3:] 252 name = command.__name__[3:]
252 usage = h[0] 253 usage = h[0].replace('<','&lt;').replace('>','&gt;')[7:]
253 print(""" 254 print("""
254 <tr><td valign=top><strong>%(name)s</strong></td> 255 <tr><td valign=top><strong>%(name)s</strong></td>
255 <td><tt>%(usage)s</tt><p> 256 <td><tt>- %(usage)s</tt>
256 <pre>""" % locals()) 257 <pre>""" % locals())
257 indent = indent_re.match(h[3]) 258 indent = indent_re.match(h[1])
258 if indent: indent = len(indent.group(1)) # noqa: E701 259 if indent: indent = len(indent.group(1)) # noqa: E701
259 for line in h[3:]: 260 for line in h[1:]:
261 line = line.replace('<','&lt;').replace('>','&gt;')
260 if indent: 262 if indent:
261 print(line[indent:]) 263 print(line[indent:])
262 else: 264 else:
263 print(line) 265 print(line)
264 print('</pre></td></tr>\n') 266 print('</pre></td></tr>\n')
267 print("</table>")
265 268
266 def help_all(self): 269 def help_all(self):
267 print(_(""" 270 print(_("""
268 All commands (except help) require a tracker specifier. This is just 271 All commands (except help) require a tracker specifier. This is just
269 the path to the roundup tracker you're working with. A roundup tracker 272 the path to the roundup tracker you're working with. A roundup tracker
538 self.db_uncommitted = True 541 self.db_uncommitted = True
539 return 0 542 return 0
540 543
541 def do_display(self, args): 544 def do_display(self, args):
542 ''"""Usage: display designator[,designator]* 545 ''"""Usage: display designator[,designator]*
543
544 Show the property values for the given node(s). 546 Show the property values for the given node(s).
545 547
546 A designator is a classname and a nodeid concatenated, 548 A designator is a classname and a nodeid concatenated,
547 eg. bug1, user10, ... 549 eg. bug1, user10, ...
548 550
583 protected = "" 585 protected = ""
584 print(_('%(protected)s%(key)s: %(value)s') % locals()) 586 print(_('%(protected)s%(key)s: %(value)s') % locals())
585 587
586 def do_export(self, args, export_files=True): 588 def do_export(self, args, export_files=True):
587 ''"""Usage: export [[-]class[,class]] export_dir 589 ''"""Usage: export [[-]class[,class]] export_dir
588 Export the database to colon-separated-value files. 590 Export the database and file content.
591
592 Database content is exported to colon separated files.
589 To exclude the files (e.g. for the msg or file class), 593 To exclude the files (e.g. for the msg or file class),
590 use the exporttables command. 594 use the exporttables command.
591 595
592 Optionally limit the export to just the named classes 596 Optionally limit the export to just the named classes
593 or exclude the named classes, if the 1st argument starts with '-'. 597 or exclude the named classes, if the 1st argument
598 starts with '-'.
594 599
595 This action exports the current data from the database into 600 This action exports the current data from the database into
596 colon-separated-value files that are placed in the nominated 601 colon-separated-value files that are placed in the nominated
597 destination directory. 602 export_dir directory.
598 """ 603 """
599 # grab the directory to export to 604 # grab the directory to export to
600 if len(args) < 1: 605 if len(args) < 1:
601 raise UsageError(_('Not enough arguments supplied')) 606 raise UsageError(_('Not enough arguments supplied'))
602 607
695 max_len, file=sys.stderr) 700 max_len, file=sys.stderr)
696 return 0 701 return 0
697 702
698 def do_exporttables(self, args): 703 def do_exporttables(self, args):
699 ''"""Usage: exporttables [[-]class[,class]] export_dir 704 ''"""Usage: exporttables [[-]class[,class]] export_dir
700 Export the database to colon-separated-value files, excluding the 705 Export only the database to files, no file content.
701 files below $TRACKER_HOME/db/files/ (which can be archived separately). 706
707 Database content is exported to colon separated files.
708 The files below $TRACKER_HOME/db/files/ (which can be
709 archived separately) are not part of the export.
702 To include the files, use the export command. 710 To include the files, use the export command.
703 711
704 Optionally limit the export to just the named classes 712 Optionally limit the export to just the named classes
705 or exclude the named classes, if the 1st argument starts with '-'. 713 or exclude the named classes, if the 1st argument
714 starts with '-'.
706 715
707 This action exports the current data from the database into 716 This action exports the current data from the database into
708 colon-separated-value files that are placed in the nominated 717 colon-separated-value files that are placed in the export_dir
709 destination directory. 718 destination directory.
710 """ 719 """
711 return self.do_export(args, export_files=False) 720 return self.do_export(args, export_files=False)
712 721
713 def do_filter(self, args): 722 def do_filter(self, args):
833 except (ValueError, TypeError) as message: 842 except (ValueError, TypeError) as message:
834 raise UsageError(message) 843 raise UsageError(message)
835 return 0 844 return 0
836 845
837 def do_genconfig(self, args, update=False): 846 def do_genconfig(self, args, update=False):
838 ''"""Usage: genconfig <filename> 847 ''"""Usage: genconfig filename
839 Generate a new tracker config file (ini style) with default 848 Create a new tracker config file with default values in filename.
840 values in <filename>.
841 """ 849 """
842 if len(args) < 1: 850 if len(args) < 1:
843 raise UsageError(_('Not enough arguments supplied')) 851 raise UsageError(_('Not enough arguments supplied'))
844 852
845 if update: 853 if update:
1183 '"%(nodeid)s"') % locals()) 1191 '"%(nodeid)s"') % locals())
1184 return 0 1192 return 0
1185 1193
1186 def do_import(self, args, import_files=True): 1194 def do_import(self, args, import_files=True):
1187 ''"""Usage: import import_dir 1195 ''"""Usage: import import_dir
1188 Import a database from the directory containing CSV files, 1196 Import a database and file contents from the directory.
1189 two per class to import. 1197
1190 1198 The directory should have the same format as one containing
1199 the output of export. There are two files imported per class.
1191 The files used in the import are: 1200 The files used in the import are:
1192 1201
1193 <class>.csv 1202 <class>.csv
1194 This must define the same properties as the class (including 1203 This must define the same properties as the class (including
1195 having a "header" line with those property names.) 1204 having a "header" line with those property names.)
1274 self.db_uncommitted = True 1283 self.db_uncommitted = True
1275 return 0 1284 return 0
1276 1285
1277 def do_importtables(self, args): 1286 def do_importtables(self, args):
1278 ''"""Usage: importtables export_dir 1287 ''"""Usage: importtables export_dir
1279
1280 This imports the database tables exported using exporttables. 1288 This imports the database tables exported using exporttables.
1289
1290 It does not import the content of files like msgs and files.
1281 """ 1291 """
1282 return self.do_import(args, import_files=False) 1292 return self.do_import(args, import_files=False)
1283 1293
1284 def do_initialise(self, tracker_home, args): 1294 def do_initialise(self, tracker_home, args):
1285 ''"""Usage: initialise [adminpw] 1295 ''"""Usage: initialise [adminpw]
1521 '"%(propname)s"') % locals()) 1531 '"%(propname)s"') % locals())
1522 return 0 1532 return 0
1523 1533
1524 def do_migrate(self, args): # noqa: ARG002 - args unused 1534 def do_migrate(self, args): # noqa: ARG002 - args unused
1525 ''"""Usage: migrate 1535 ''"""Usage: migrate
1526
1527 Update a tracker's database to be compatible with the Roundup 1536 Update a tracker's database to be compatible with the Roundup
1528 codebase. 1537 codebase.
1529 1538
1530 You should run the "migrate" command for your tracker once 1539 You should run the "migrate" command for your tracker once
1531 you've installed the latest codebase. 1540 you've installed the latest codebase.
1551 self.db.database_schema['version']) 1560 self.db.database_schema['version'])
1552 return 0 1561 return 0
1553 1562
1554 def do_pack(self, args): 1563 def do_pack(self, args):
1555 ''"""Usage: pack period | date 1564 ''"""Usage: pack period | date
1556 1565 Remove journal entries older than the date/period.
1557 Remove journal entries older than a period of time specified or
1558 before a certain date.
1559 1566
1560 A period is specified using the suffixes "y", "m", and "d". The 1567 A period is specified using the suffixes "y", "m", and "d". The
1561 suffix "w" (for "week") means 7 days. 1568 suffix "w" (for "week") means 7 days.
1562 1569
1563 "3y" means three years 1570 "3y" means three years
1590 self.db_uncommitted = True 1597 self.db_uncommitted = True
1591 return 0 1598 return 0
1592 1599
1593 def do_perftest(self, args): 1600 def do_perftest(self, args):
1594 ''"""Usage: perftest [mode] [arguments]* 1601 ''"""Usage: perftest [mode] [arguments]*
1595 1602 Time operations in Roundup.
1596 Time operations in Roundup. Supported arguments: 1603
1604 Supported arguments:
1597 1605
1598 [password] [rounds=<integer>] [scheme=<scheme>] 1606 [password] [rounds=<integer>] [scheme=<scheme>]
1599 1607
1600 'password' is the default mode. The tracker's config.ini 1608 'password' is the default mode. The tracker's config.ini
1601 setting for 'password_pbkdf2_default_rounds' is the default 1609 setting for 'password_pbkdf2_default_rounds' is the default
1663 {"time": toc - tic, "scheme": props['scheme'], 1671 {"time": toc - tic, "scheme": props['scheme'],
1664 "rounds": rounds}) 1672 "rounds": rounds})
1665 1673
1666 def do_pragma(self, args): 1674 def do_pragma(self, args):
1667 ''"""Usage: pragma setting=value | 'list' 1675 ''"""Usage: pragma setting=value | 'list'
1668 Set internal admin settings to a value. E.G. 1676 Set internal admin settings to a value.
1677
1678 For example:
1669 1679
1670 pragma verbose=True 1680 pragma verbose=True
1671 pragma verbose=yes 1681 pragma verbose=yes
1672 pragma verbose=on 1682 pragma verbose=on
1673 pragma verbose=1 1683 pragma verbose=1
1875 self.db_uncommitted = False 1885 self.db_uncommitted = False
1876 return 0 1886 return 0
1877 1887
1878 def do_security(self, args): 1888 def do_security(self, args):
1879 ''"""Usage: security [Role name] 1889 ''"""Usage: security [Role name]
1880 1890 Display the Permissions available to one or all Roles.
1881 Display the Permissions available to one or all Roles. 1891
1882 Also validates that any properties defined in a 1892 Also validates that any properties defined in a
1883 permission are valid. 1893 permission are valid.
1884 1894
1885 Run this after changing your permissions to catch 1895 Run this after changing your permissions to catch
1886 typos. 1896 typos.
1887 """ 1897 """
1888 if len(args) == 1: 1898 if len(args) == 1:
1889 role = args[0] 1899 role = args[0]
1890 try: 1900 try:
1891 roles = [(args[0].lower(), 1901 roles = [(args[0].lower(),
2165 Desc: %(description)s 2175 Desc: %(description)s
2166 """ % templates[name]) 2176 """ % templates[name])
2167 2177
2168 def do_updateconfig(self, args): 2178 def do_updateconfig(self, args):
2169 ''"""Usage: updateconfig <filename> 2179 ''"""Usage: updateconfig <filename>
2170 Generate an updated tracker config file (ini style) in 2180 Merge existing tracker config with new settings.
2171 <filename>. Use current settings from existing roundup 2181
2172 tracker in tracker home. 2182 Output the updated config file to <filename>. Use current
2183 settings from existing roundup tracker in tracker home.
2173 """ 2184 """
2174 self.do_genconfig(args, update=True) 2185 self.do_genconfig(args, update=True)
2175 2186
2176 def usageError_feedback(self, message, function): 2187 def usageError_feedback(self, message, function):
2177 print(_('Error: %s') % message) 2188 print(_('Error: %s') % message)

Roundup Issue Tracker: http://roundup-tracker.org/