--- /h/develop/roundup/roundup/admin.py 2003-02-07 20:44:46.000000000 -0500 +++ /tools/roundup/lib/python2.2/site-packages/roundup/admin.py 2003-02-16 18:09:16.000000000 -0500 @@ -110,13 +110,20 @@ ''' Display a simple usage message. ''' if message: - message = _('Problem: %(message)s)\n\n')%locals() - print _('''%(message)sUsage: roundup-admin [options] + message = _('Problem: %(message)s\n\n')%locals() + print _('''%(message)sUsage: roundup-admin [options] [ ] Options: -i instance home -- specify the issue tracker "home directory" to administer -u -- the user[:password] to use for commands - -c -- when outputting lists of data, just comma-separate them + -d -- print full designators not just class id numbers + -c -- when outputting lists of data, comma-separate them. + Same as '-S ","'. + -S -- when outputting lists of data, string-separate them + -s -- when outputting lists of data, space-separate them. + Same as '-S " "'. + + Only one of -s, -c or -S can be specified. Help: roundup-admin -h @@ -409,17 +416,55 @@ # get the class cl = self.get_class(classname) try: - if self.comma_sep: - l.append(cl.get(nodeid, propname)) + id=[] + if self.separator: + if self.print_designator: + # see if property is a link or multilink for + # which getting a desginator make sense. + # Algorithm: Get the properties of the + # current designator's class. (cl.getprops) + # get the property object for the property the + # user requested (properties[propname]) + # verify its type (isinstance...) + # raise error if not link/multilink + # get class name for link/multilink property + # do the get on the designators + # append the new designators + # print + properties = cl.getprops() + property = properties[propname] + if not (isinstance(property, hyperdb.Multilink) or + isinstance(property, hyperdb.Link)): + raise UsageError, _('property %s is not of type Multilink or Link so -d flag does not apply.')%propname + propclassname = self.db.getclass(property.classname).classname + id = cl.get(nodeid, propname) + for i in id: + l.append(propclassname + i) + else: + id = cl.get(nodeid, propname) + for i in id: + l.append(i) else: - print cl.get(nodeid, propname) + if self.print_designator: + properties = cl.getprops() + property = properties[propname] + if not (isinstance(property, hyperdb.Multilink) or + isinstance(property, hyperdb.Link)): + raise UsageError, _('property %s is not of type Multilink or Link so -d flag does not apply.')%propname + propclassname = self.db.getclass(property.classname).classname + id = cl.get(nodeid, propname) + for i in id: + print propclassname + i + else: + print cl.get(nodeid, propname) except IndexError: raise UsageError, _('no such %(classname)s node "%(nodeid)s"')%locals() except KeyError: raise UsageError, _('no such %(classname)s property ' '"%(propname)s"')%locals() - if self.comma_sep: - print ','.join(l) + if self.separator: + print self.separator.join(l) + return 0 @@ -427,7 +472,7 @@ '''Usage: set [items] property=value property=value ... Set the given properties of one or more items(s). - The items may be specified as a class or as a comma-separeted + The items may be specified as a class or as a comma-separated list of item designators (ie "designator[,designator,...]"). This command sets the properties to the values for all designators @@ -550,10 +595,25 @@ # now do the find try: - if self.comma_sep: - print ','.join(apply(cl.find, (), props)) + id = [] + designator = [] + if self.separator: + if self.print_designator: + id=apply(cl.find, (), props) + for i in id: + designator.append(classname + i) + print self.separator.join(designator) + else: + print self.separator.join(apply(cl.find, (), props)) + else: - print apply(cl.find, (), props) + if self.print_designator: + id=apply(cl.find, (), props) + for i in id: + designator.append(classname + i) + print designator + else: + print apply(cl.find, (), props) except KeyError: raise UsageError, _('%(classname)s has no property ' '"%(propname)s"')%locals() @@ -582,8 +642,8 @@ print _('%(key)s: %(value)s')%locals() def do_display(self, args): - '''Usage: display designator - Show the property values for the given node. + '''Usage: display designator[,designator]* + Show the property values for the given node(s). This lists the properties and their associated values for the given node. @@ -592,18 +652,19 @@ raise UsageError, _('Not enough arguments supplied') # decode the node designator - try: - classname, nodeid = hyperdb.splitDesignator(args[0]) - except hyperdb.DesignatorError, message: - raise UsageError, message + for designator in args[0].split(','): + try: + classname, nodeid = hyperdb.splitDesignator(designator) + except hyperdb.DesignatorError, message: + raise UsageError, message - # get the class - cl = self.get_class(classname) + # get the class + cl = self.get_class(classname) - # display the values - for key in cl.properties.keys(): - value = cl.get(nodeid, key) - print _('%(key)s: %(value)s')%locals() + # display the values + for key in cl.properties.keys(): + value = cl.get(nodeid, key) + print _('%(key)s: %(value)s')%locals() def do_create(self, args, pwre = re.compile(r'{(\w+)}(.+)')): '''Usage: create classname property=value ... @@ -705,7 +766,13 @@ specified, the "label" property is used. The label property is tried in order: the key, "name", "title" and then the first property, alphabetically. + + With -c, -S or -s print a list of item id's if no property specified. + If property specified, print list of that property for every class + instance. ''' + if len(args) > 2: + raise UsageError, _('Too many arguments supplied') if len(args) < 1: raise UsageError, _('Not enough arguments supplied') classname = args[0] @@ -719,8 +786,21 @@ else: propname = cl.labelprop() - if self.comma_sep: - print ','.join(cl.list()) + if self.separator: + if len(args) == 2: + # create a list of propnames since user specified propname + proplist=[] + for nodeid in cl.list(): + try: + proplist.append(cl.get(nodeid, propname)) + except KeyError: + raise UsageError, _('%(classname)s has no property ' + '"%(propname)s"')%locals() + print self.separator.join(proplist) + else: + # create a list of index id's since user didn't specify + # otherwise + print self.separator.join(cl.list()) else: for nodeid in cl.list(): try: @@ -1171,7 +1251,7 @@ def main(self): try: - opts, args = getopt.getopt(sys.argv[1:], 'i:u:hc') + opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdsS:') except getopt.GetoptError, e: self.usage(str(e)) return 1 @@ -1185,7 +1265,8 @@ name = l[0] if len(l) > 1: password = l[1] - self.comma_sep = 0 + self.separator = None + self.print_designator = 0 for opt, arg in opts: if opt == '-h': self.usage() @@ -1193,7 +1274,22 @@ if opt == '-i': self.tracker_home = arg if opt == '-c': - self.comma_sep = 1 + if self.separator != None: + self.usage('Only one of -c, -S and -s may be specified') + return 1 + self.separator = ',' + if opt == '-S': + if self.separator != None: + self.usage('Only one of -c, -S and -s may be specified') + return 1 + self.separator = arg + if opt == '-s': + if self.separator != None: + self.usage('Only one of -c, -S and -s may be specified') + return 1 + self.separator = ' ' + if opt == '-d': + self.print_designator = 1 # if no command - go interactive # wrap in a try/finally so we always close off the db