comparison roundup/admin.py @ 7832:b530069f3120

chore(lint): formatting whitespace consolidate nested if ...
author John Rouillard <rouilj@ieee.org>
date Sun, 24 Mar 2024 15:22:50 -0400
parents aa1fd8704469
children d523d5c648e9
comparison
equal deleted inserted replaced
7831:9c58f5940c20 7832:b530069f3120
228 """ 228 """
229 sys.stdout.write(_('Commands: ')) 229 sys.stdout.write(_('Commands: '))
230 commands = [''] 230 commands = ['']
231 for command in self.commands.values(): 231 for command in self.commands.values():
232 h = _(command.__doc__).split('\n')[0] 232 h = _(command.__doc__).split('\n')[0]
233 commands.append(' '+h[7:]) 233 commands.append(' ' + h[7:])
234 commands.sort() 234 commands.sort()
235 commands.append(_( 235 commands.append(_(
236 """Commands may be abbreviated as long as the abbreviation 236 """Commands may be abbreviated as long as the abbreviation
237 matches only one command, e.g. l == li == lis == list.""")) 237 matches only one command, e.g. l == li == lis == list."""))
238 sys.stdout.write('\n'.join(commands) + '\n\n') 238 sys.stdout.write('\n'.join(commands) + '\n\n')
548 """ 548 """
549 if len(args) < 1: 549 if len(args) < 1:
550 raise UsageError(_('Not enough arguments supplied')) 550 raise UsageError(_('Not enough arguments supplied'))
551 551
552 display_protected = self.settings['display_protected'] 552 display_protected = self.settings['display_protected']
553 display_header = self.settings['display_header'] 553 display_header = self.settings['display_header']
554 554
555 # decode the node designator 555 # decode the node designator
556 for designator in args[0].split(','): 556 for designator in args[0].split(','):
557 try: 557 try:
558 classname, nodeid = hyperdb.splitDesignator(designator) 558 classname, nodeid = hyperdb.splitDesignator(designator)
625 625
626 if not export_files and hasattr(cl, 'export_files'): 626 if not export_files and hasattr(cl, 'export_files'):
627 sys.stdout.write('Exporting %s WITHOUT the files\r\n' % 627 sys.stdout.write('Exporting %s WITHOUT the files\r\n' %
628 classname) 628 classname)
629 629
630 with open(os.path.join(export_dir, classname+'.csv'), 'w') as f: 630 with open(os.path.join(export_dir, classname + '.csv'), 'w') as f:
631 writer = csv.writer(f, colon_separated) 631 writer = csv.writer(f, colon_separated)
632 632
633 propnames = cl.export_propnames() 633 propnames = cl.export_propnames()
634 fields = propnames[:] 634 fields = propnames[:]
635 fields.append('is retired') 635 fields.append('is retired')
674 writer.writerow(exp) 674 writer.writerow(exp)
675 if export_files and hasattr(cl, 'export_files'): 675 if export_files and hasattr(cl, 'export_files'):
676 cl.export_files(export_dir, nodeid) 676 cl.export_files(export_dir, nodeid)
677 677
678 # export the journals 678 # export the journals
679 with open(os.path.join(export_dir, classname+'-journals.csv'), 'w') as jf: 679 with open(os.path.join(export_dir,
680 classname + '-journals.csv'), 'w') as jf:
680 if self.verbose: 681 if self.verbose:
681 sys.stdout.write("\nExporting Journal for %s\n" % 682 sys.stdout.write("\nExporting Journal for %s\n" %
682 classname) 683 classname)
683 sys.stdout.flush() 684 sys.stdout.flush()
684 journals = csv.writer(jf, colon_separated) 685 journals = csv.writer(jf, colon_separated)
764 # now do the filter 765 # now do the filter
765 props = {"filterspec": props} 766 props = {"filterspec": props}
766 try: 767 try:
767 output_items = cl.filter(None, **props) 768 output_items = cl.filter(None, **props)
768 if self.print_designator: 769 if self.print_designator:
769 output_items = [ classname + i for i in output_items ] 770 output_items = [classname + i for i in output_items]
770 771
771 if self.separator: 772 if self.separator:
772 print(self.separator.join(output_items)) 773 print(self.separator.join(output_items))
773 else: 774 else:
774 print(output_items) 775 print(output_items)
813 814
814 # now do the find 815 # now do the find
815 try: 816 try:
816 output_items = cl.find(**props) 817 output_items = cl.find(**props)
817 if self.print_designator: 818 if self.print_designator:
818 output_items = [ classname + i for i in output_items ] 819 output_items = [classname + i for i in output_items]
819 820
820 if self.separator: 821 if self.separator:
821 print(self.separator.join(output_items)) 822 print(self.separator.join(output_items))
822 else: 823 else:
823 print(output_items) 824 print(output_items)
993 994
994 skipquiet = 'skipquiet' in args[1:] 995 skipquiet = 'skipquiet' in args[1:]
995 raw = 'raw' in args[1:] 996 raw = 'raw' in args[1:]
996 997
997 getclass = self.db.getclass 998 getclass = self.db.getclass
999
998 def get_prop_name(key, prop_name): 1000 def get_prop_name(key, prop_name):
999 # getclass and classname from enclosing method 1001 # getclass and classname from enclosing method
1000 klass = getclass(classname) 1002 klass = getclass(classname)
1001 try: 1003 try:
1002 property_obj = klass.properties[prop_name] 1004 property_obj = klass.properties[prop_name]
1062 1064
1063 def format_report_class(_data): 1065 def format_report_class(_data):
1064 """Eat the empty data dictionary or None""" 1066 """Eat the empty data dictionary or None"""
1065 return classname 1067 return classname
1066 1068
1067 def format_link (data): 1069 def format_link(data):
1068 '''data = ('issue', '157', 'dependson')''' 1070 '''data = ('issue', '157', 'dependson')'''
1069 # .Hint added issue23 to superseder 1071 # .Hint added issue23 to superseder
1070 f = _("added %(class)s%(item_id)s to %(propname)s") 1072 f = _("added %(class)s%(item_id)s to %(propname)s")
1071 return f % { 1073 return f % {
1072 'class': data[0], 'item_id': data[1], 'propname': data[2]} 1074 'class': data[0], 'item_id': data[1], 'propname': data[2]}
1087 result.append( 1089 result.append(
1088 # .Hint read as: assignedto was admin(1) 1090 # .Hint read as: assignedto was admin(1)
1089 # where assignedto is the property 1091 # where assignedto is the property
1090 # admin is the key name for value 1 1092 # admin is the key name for value 1
1091 _("%(prop)s was %(name)s(%(value)s)") % { 1093 _("%(prop)s was %(name)s(%(value)s)") % {
1092 "prop": prop, "name": name, "value": value }) 1094 "prop": prop, "name": name, "value": value})
1093 else: 1095 else:
1094 # use repr so strings with embedded \n etc. don't 1096 # use repr so strings with embedded \n etc. don't
1095 # generate newlines in output. Try to keep each 1097 # generate newlines in output. Try to keep each
1096 # journal entry on 1 line. 1098 # journal entry on 1 line.
1097 result.append(_("%(prop)s was %(value)s") % { 1099 result.append(_("%(prop)s was %(value)s") % {
1106 (get_prop_name(v, prop), v) 1108 (get_prop_name(v, prop), v)
1107 for v in value] 1109 for v in value]
1108 else: 1110 else:
1109 prop_class = get_prop_class(prop) 1111 prop_class = get_prop_class(prop)
1110 if prop_class: # noqa: SIM108 1112 if prop_class: # noqa: SIM108
1111 list_items = [ "%s%s" % (prop_class, v) 1113 list_items = ["%s%s" % (prop_class, v)
1112 for v in value ] 1114 for v in value]
1113 else: 1115 else:
1114 list_items = value 1116 list_items = value
1115 1117
1116 result.append(_("%(prop)s was [%(value_list)s]") % { 1118 result.append(_("%(prop)s was [%(value_list)s]") % {
1117 "prop": prop, "value_list": ", ".join(list_items)}) 1119 "prop": prop, "value_list": ", ".join(list_items)})
1126 result.append(_("%(prop)s was %(value)s") % { 1128 result.append(_("%(prop)s was %(value)s") % {
1127 "prop": prop, "value": value}) 1129 "prop": prop, "value": value})
1128 1130
1129 return '; '.join(result) 1131 return '; '.join(result)
1130 1132
1131 def format_unlink (data): 1133 def format_unlink(data):
1132 '''data = ('issue', '157', 'dependson')''' 1134 '''data = ('issue', '157', 'dependson')'''
1133 return "removed %s%s from %s" % (data[0], data[1], data[2]) 1135 return "removed %s%s from %s" % (data[0], data[1], data[2])
1134 1136
1135 formatters = { 1137 formatters = {
1136 "create": format_report_class, 1138 "create": format_report_class,
1250 with open(os.path.join(import_dir, classname + '-journals.csv'), 'r') as f: 1252 with open(os.path.join(import_dir, classname + '-journals.csv'), 'r') as f:
1251 reader = csv.reader(f, colon_separated) 1253 reader = csv.reader(f, colon_separated)
1252 cl.import_journals(reader) 1254 cl.import_journals(reader)
1253 1255
1254 # (print to sys.stdout here to allow tests to squash it .. ugh) 1256 # (print to sys.stdout here to allow tests to squash it .. ugh)
1255 print('setting', classname, maxid+1, file=sys.stdout) 1257 print('setting', classname, maxid + 1, file=sys.stdout)
1256 1258
1257 # set the id counter 1259 # set the id counter
1258 self.db.setid(classname, str(maxid+1)) 1260 self.db.setid(classname, str(maxid + 1))
1259 1261
1260 self.db_uncommitted = True 1262 self.db_uncommitted = True
1261 return 0 1263 return 0
1262 1264
1263 def do_importtables(self, args): 1265 def do_importtables(self, args):
1485 if self.separator: 1487 if self.separator:
1486 if len(args) == 2: 1488 if len(args) == 2:
1487 # create a list of propnames since user specified propname 1489 # create a list of propnames since user specified propname
1488 proplist = [] 1490 proplist = []
1489 try: 1491 try:
1490 proplist = [ cl.get(nodeid, propname) for nodeid in 1492 proplist = [cl.get(nodeid, propname) for nodeid in
1491 cl.getnodeids(retired=retired)] 1493 cl.getnodeids(retired=retired)]
1492 except KeyError: 1494 except KeyError:
1493 raise UsageError(_('%(classname)s has no property ' 1495 raise UsageError(_('%(classname)s has no property '
1494 '"%(propname)s"') % locals()) 1496 '"%(propname)s"') % locals())
1495 print(self.separator.join(proplist)) 1497 print(self.separator.join(proplist))
1636 print(e) 1638 print(e)
1637 print_supported_schemes() 1639 print_supported_schemes()
1638 return 1640 return
1639 1641
1640 if props['scheme'].startswith('PBKDF2'): 1642 if props['scheme'].startswith('PBKDF2'):
1641 (rounds, salt, _raw_salt, digest) = password.pbkdf2_unpack( 1643 (rounds, _salt, _raw_salt, _digest) = password.pbkdf2_unpack(
1642 pw_hash) 1644 pw_hash)
1643 else: 1645 else:
1644 rounds = _("scheme does not support rounds.") 1646 rounds = _("scheme does not support rounds.")
1645 1647
1646 print(_( 1648 print(_(
1647 "Hash time: %(time)0.9f seconds, scheme: %(scheme)s, " 1649 "Hash time: %(time)0.9f seconds, scheme: %(scheme)s, "
1648 "rounds: %(rounds)s") % 1650 "rounds: %(rounds)s") %
1649 {"time": toc-tic, "scheme": props['scheme'], 1651 {"time": toc - tic, "scheme": props['scheme'],
1650 "rounds": rounds}) 1652 "rounds": rounds})
1651 1653
1652 def do_pragma(self, args): 1654 def do_pragma(self, args):
1653 ''"""Usage: pragma setting=value | 'list' 1655 ''"""Usage: pragma setting=value | 'list'
1654 Set internal admin settings to a value. E.G. 1656 Set internal admin settings to a value. E.G.
2346 commit = self.my_input(_('There are unsaved changes. Commit them (y/N)? ')) 2348 commit = self.my_input(_('There are unsaved changes. Commit them (y/N)? '))
2347 if commit and commit[0].lower() == 'y': 2349 if commit and commit[0].lower() == 'y':
2348 self.db.commit() 2350 self.db.commit()
2349 2351
2350 # looks like histfile is saved with mode 600 2352 # looks like histfile is saved with mode 600
2351 if readline: 2353 if readline and self.history_features('save_history'):
2352 if self.history_features('save_history'):
2353 readline.write_history_file(histfile) 2354 readline.write_history_file(histfile)
2354 return 0 2355 return 0
2355 2356
2356 def main(self): # noqa: PLR0912, PLR0911 2357 def main(self): # noqa: PLR0912, PLR0911
2357 try: 2358 try:
2403 self.print_designator = 1 2404 self.print_designator = 1
2404 elif opt == '-P': 2405 elif opt == '-P':
2405 try: 2406 try:
2406 self.do_pragma([arg]) 2407 self.do_pragma([arg])
2407 except UsageError as e: 2408 except UsageError as e:
2408 print('\n%s\n' % e) 2409 print('\n%s\n' % e)
2409 elif opt == '-u': 2410 elif opt == '-u':
2410 login_opt = arg.split(':') 2411 login_opt = arg.split(':')
2411 self.name = login_opt[0] 2412 self.name = login_opt[0]
2412 if len(login_opt) > 1: 2413 if len(login_opt) > 1:
2413 self.password = login_opt[1] 2414 self.password = login_opt[1]

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