comparison roundup/admin.py @ 6176:d25638d1826c

Add roundup-admin filter command; fix bad doc example; add tests admin_guide.txt had an example using find with username prop. This is wrong. Find only works with links not string. Fix it to use filter. Add filter command to roundup-admin. Add tests for filter, specification and find.
author John Rouillard <rouilj@ieee.org>
date Mon, 18 May 2020 23:28:03 -0400
parents 3719b01cbe9e
children 41907e1f9c3f
comparison
equal deleted inserted replaced
6175:72a69753f49a 6176:d25638d1826c
716 import traceback; traceback.print_exc() 716 import traceback; traceback.print_exc()
717 raise UsageError(message) 717 raise UsageError(message)
718 self.db_uncommitted = True 718 self.db_uncommitted = True
719 return 0 719 return 0
720 720
721 def do_filter(self, args):
722 ''"""Usage: filter classname propname=value ...
723 Find the nodes of the given class with a given property value.
724
725 Find the nodes of the given class with a given property value.
726 Multiple values can be specified by separating them with commas.
727 If property is a string, all values must match. I.E. it's an
728 'and' operation. If the property is a link/multilink any value
729 matches. I.E. an 'or' operation.
730 """
731 if len(args) < 1:
732 raise UsageError(_('Not enough arguments supplied'))
733 classname = args[0]
734 # get the class
735 cl = self.get_class(classname)
736
737 # handle the propname=value argument
738 props = self.props_from_args(args[1:])
739
740 # convert the user-input value to a value used for filter
741 # multiple , separated values become a list
742 for propname, value in props.items():
743 if ',' in value:
744 values = value.split(',')
745 else:
746 values = value
747
748 props[propname] = values
749
750 # now do the filter
751 try:
752 id = []
753 designator = []
754 props = { "filterspec": props }
755
756 if self.separator:
757 if self.print_designator:
758 id = cl.filter(None, **props)
759 for i in id:
760 designator.append(classname + i)
761 print(self.separator.join(designator), file=sys.stdout)
762 else:
763 print(self.separator.join(cl.find(**props)),
764 file=sys.stdout)
765 else:
766 if self.print_designator:
767 id = cl.filter(None, **props)
768 for i in id:
769 designator.append(classname + i)
770 print(designator,file=sys.stdout)
771 else:
772 print(cl.filter(None, **props), file=sys.stdout)
773 except KeyError:
774 raise UsageError(_('%(classname)s has no property '
775 '"%(propname)s"') % locals())
776 except (ValueError, TypeError) as message:
777 raise UsageError(message)
778 return 0
779
721 def do_find(self, args): 780 def do_find(self, args):
722 ''"""Usage: find classname propname=value ... 781 ''"""Usage: find classname propname=value ...
723 Find the nodes of the given class with a given link property value. 782 Find the nodes of the given class with a given link property value.
724 783
725 Find the nodes of the given class with a given link property value. 784 Find the nodes of the given class with a given link property value.

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