Mercurial > p > roundup > code
comparison roundup/admin.py @ 1676:4856faf558a2
Get rid of TABs, use spaces instead.
| author | Jean Jordaan <neaj@users.sourceforge.net> |
|---|---|
| date | Mon, 23 Jun 2003 08:05:30 +0000 |
| parents | 7fb3bf18babb |
| children | ab7760caf6ff d81d215167fd |
comparison
equal
deleted
inserted
replaced
| 1675:eb3c348676ed | 1676:4856faf558a2 |
|---|---|
| 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 18 # | 18 # |
| 19 # $Id: admin.py,v 1.54 2003-05-29 00:42:34 richard Exp $ | 19 # $Id: admin.py,v 1.55 2003-06-23 08:05:30 neaj Exp $ |
| 20 | 20 |
| 21 '''Administration commands for maintaining Roundup trackers. | 21 '''Administration commands for maintaining Roundup trackers. |
| 22 ''' | 22 ''' |
| 23 | 23 |
| 24 import sys, os, getpass, getopt, re, UserDict, shutil, rfc822 | 24 import sys, os, getpass, getopt, re, UserDict, shutil, rfc822 |
| 116 Options: | 116 Options: |
| 117 -i instance home -- specify the issue tracker "home directory" to administer | 117 -i instance home -- specify the issue tracker "home directory" to administer |
| 118 -u -- the user[:password] to use for commands | 118 -u -- the user[:password] to use for commands |
| 119 -d -- print full designators not just class id numbers | 119 -d -- print full designators not just class id numbers |
| 120 -c -- when outputting lists of data, comma-separate them. | 120 -c -- when outputting lists of data, comma-separate them. |
| 121 Same as '-S ","'. | 121 Same as '-S ","'. |
| 122 -S <string> -- when outputting lists of data, string-separate them | 122 -S <string> -- when outputting lists of data, string-separate them |
| 123 -s -- when outputting lists of data, space-separate them. | 123 -s -- when outputting lists of data, space-separate them. |
| 124 Same as '-S " "'. | 124 Same as '-S " "'. |
| 125 | 125 |
| 126 Only one of -s, -c or -S can be specified. | 126 Only one of -s, -c or -S can be specified. |
| 127 | 127 |
| 128 Help: | 128 Help: |
| 129 roundup-admin -h | 129 roundup-admin -h |
| 472 raise UsageError, message | 472 raise UsageError, message |
| 473 | 473 |
| 474 # get the class | 474 # get the class |
| 475 cl = self.get_class(classname) | 475 cl = self.get_class(classname) |
| 476 try: | 476 try: |
| 477 id=[] | 477 id=[] |
| 478 if self.separator: | 478 if self.separator: |
| 479 if self.print_designator: | 479 if self.print_designator: |
| 480 # see if property is a link or multilink for | 480 # see if property is a link or multilink for |
| 481 # which getting a desginator make sense. | 481 # which getting a desginator make sense. |
| 482 # Algorithm: Get the properties of the | 482 # Algorithm: Get the properties of the |
| 483 # current designator's class. (cl.getprops) | 483 # current designator's class. (cl.getprops) |
| 484 # get the property object for the property the | 484 # get the property object for the property the |
| 485 # user requested (properties[propname]) | 485 # user requested (properties[propname]) |
| 486 # verify its type (isinstance...) | 486 # verify its type (isinstance...) |
| 487 # raise error if not link/multilink | 487 # raise error if not link/multilink |
| 488 # get class name for link/multilink property | 488 # get class name for link/multilink property |
| 489 # do the get on the designators | 489 # do the get on the designators |
| 490 # append the new designators | 490 # append the new designators |
| 491 # print | 491 # print |
| 492 properties = cl.getprops() | 492 properties = cl.getprops() |
| 493 property = properties[propname] | 493 property = properties[propname] |
| 494 if not (isinstance(property, hyperdb.Multilink) or | 494 if not (isinstance(property, hyperdb.Multilink) or |
| 495 isinstance(property, hyperdb.Link)): | 495 isinstance(property, hyperdb.Link)): |
| 496 raise UsageError, _('property %s is not of type Multilink or Link so -d flag does not apply.')%propname | 496 raise UsageError, _('property %s is not of type Multilink or Link so -d flag does not apply.')%propname |
| 497 propclassname = self.db.getclass(property.classname).classname | 497 propclassname = self.db.getclass(property.classname).classname |
| 498 id = cl.get(nodeid, propname) | 498 id = cl.get(nodeid, propname) |
| 499 for i in id: | |
| 500 l.append(propclassname + i) | |
| 501 else: | |
| 502 id = cl.get(nodeid, propname) | |
| 503 for i in id: | 499 for i in id: |
| 504 l.append(i) | 500 l.append(propclassname + i) |
| 501 else: | |
| 502 id = cl.get(nodeid, propname) | |
| 503 for i in id: | |
| 504 l.append(i) | |
| 505 else: | 505 else: |
| 506 if self.print_designator: | 506 if self.print_designator: |
| 507 properties = cl.getprops() | 507 properties = cl.getprops() |
| 508 property = properties[propname] | 508 property = properties[propname] |
| 509 if not (isinstance(property, hyperdb.Multilink) or | 509 if not (isinstance(property, hyperdb.Multilink) or |
| 510 isinstance(property, hyperdb.Link)): | 510 isinstance(property, hyperdb.Link)): |
| 511 raise UsageError, _('property %s is not of type Multilink or Link so -d flag does not apply.')%propname | 511 raise UsageError, _('property %s is not of type Multilink or Link so -d flag does not apply.')%propname |
| 512 propclassname = self.db.getclass(property.classname).classname | 512 propclassname = self.db.getclass(property.classname).classname |
| 513 id = cl.get(nodeid, propname) | 513 id = cl.get(nodeid, propname) |
| 514 for i in id: | 514 for i in id: |
| 515 print propclassname + i | 515 print propclassname + i |
| 516 else: | 516 else: |
| 517 print cl.get(nodeid, propname) | 517 print cl.get(nodeid, propname) |
| 518 except IndexError: | 518 except IndexError: |
| 519 raise UsageError, _('no such %(classname)s node "%(nodeid)s"')%locals() | 519 raise UsageError, _('no such %(classname)s node "%(nodeid)s"')%locals() |
| 658 try: | 658 try: |
| 659 id = [] | 659 id = [] |
| 660 designator = [] | 660 designator = [] |
| 661 if self.separator: | 661 if self.separator: |
| 662 if self.print_designator: | 662 if self.print_designator: |
| 663 id=apply(cl.find, (), props) | 663 id=apply(cl.find, (), props) |
| 664 for i in id: | 664 for i in id: |
| 665 designator.append(classname + i) | 665 designator.append(classname + i) |
| 666 print self.separator.join(designator) | 666 print self.separator.join(designator) |
| 667 else: | 667 else: |
| 668 print self.separator.join(apply(cl.find, (), props)) | 668 print self.separator.join(apply(cl.find, (), props)) |
| 669 | 669 |
| 670 else: | 670 else: |
| 671 if self.print_designator: | 671 if self.print_designator: |
| 672 id=apply(cl.find, (), props) | 672 id=apply(cl.find, (), props) |
| 673 for i in id: | 673 for i in id: |
| 674 designator.append(classname + i) | 674 designator.append(classname + i) |
| 675 print designator | 675 print designator |
| 676 else: | 676 else: |
| 677 print apply(cl.find, (), props) | 677 print apply(cl.find, (), props) |
| 678 except KeyError: | 678 except KeyError: |
| 679 raise UsageError, _('%(classname)s has no property ' | 679 raise UsageError, _('%(classname)s has no property ' |
| 680 '"%(propname)s"')%locals() | 680 '"%(propname)s"')%locals() |
| 681 except (ValueError, TypeError), message: | 681 except (ValueError, TypeError), message: |
| 682 raise UsageError, message | 682 raise UsageError, message |
| 711 ''' | 711 ''' |
| 712 if len(args) < 1: | 712 if len(args) < 1: |
| 713 raise UsageError, _('Not enough arguments supplied') | 713 raise UsageError, _('Not enough arguments supplied') |
| 714 | 714 |
| 715 # decode the node designator | 715 # decode the node designator |
| 716 for designator in args[0].split(','): | 716 for designator in args[0].split(','): |
| 717 try: | 717 try: |
| 718 classname, nodeid = hyperdb.splitDesignator(designator) | 718 classname, nodeid = hyperdb.splitDesignator(designator) |
| 719 except hyperdb.DesignatorError, message: | 719 except hyperdb.DesignatorError, message: |
| 720 raise UsageError, message | 720 raise UsageError, message |
| 721 | 721 |
| 722 # get the class | 722 # get the class |
| 723 cl = self.get_class(classname) | 723 cl = self.get_class(classname) |
| 724 | 724 |
| 725 # display the values | 725 # display the values |
| 726 for key in cl.properties.keys(): | 726 for key in cl.properties.keys(): |
| 727 value = cl.get(nodeid, key) | 727 value = cl.get(nodeid, key) |
| 728 print _('%(key)s: %(value)s')%locals() | 728 print _('%(key)s: %(value)s')%locals() |
| 729 | 729 |
| 730 def do_create(self, args, pwre = re.compile(r'{(\w+)}(.+)')): | 730 def do_create(self, args, pwre = re.compile(r'{(\w+)}(.+)')): |
| 731 '''Usage: create classname property=value ... | 731 '''Usage: create classname property=value ... |
| 732 Create a new entry of a given class. | 732 Create a new entry of a given class. |
| 733 | 733 |
| 826 Lists all instances of the given class. If the property is not | 826 Lists all instances of the given class. If the property is not |
| 827 specified, the "label" property is used. The label property is tried | 827 specified, the "label" property is used. The label property is tried |
| 828 in order: the key, "name", "title" and then the first property, | 828 in order: the key, "name", "title" and then the first property, |
| 829 alphabetically. | 829 alphabetically. |
| 830 | 830 |
| 831 With -c, -S or -s print a list of item id's if no property specified. | 831 With -c, -S or -s print a list of item id's if no property specified. |
| 832 If property specified, print list of that property for every class | 832 If property specified, print list of that property for every class |
| 833 instance. | 833 instance. |
| 834 ''' | 834 ''' |
| 835 if len(args) > 2: | 835 if len(args) > 2: |
| 836 raise UsageError, _('Too many arguments supplied') | 836 raise UsageError, _('Too many arguments supplied') |
| 837 if len(args) < 1: | 837 if len(args) < 1: |
| 838 raise UsageError, _('Not enough arguments supplied') | 838 raise UsageError, _('Not enough arguments supplied') |
| 839 classname = args[0] | 839 classname = args[0] |
| 840 | 840 |
| 841 # get the class | 841 # get the class |
| 846 propname = args[1] | 846 propname = args[1] |
| 847 else: | 847 else: |
| 848 propname = cl.labelprop() | 848 propname = cl.labelprop() |
| 849 | 849 |
| 850 if self.separator: | 850 if self.separator: |
| 851 if len(args) == 2: | 851 if len(args) == 2: |
| 852 # create a list of propnames since user specified propname | 852 # create a list of propnames since user specified propname |
| 853 proplist=[] | 853 proplist=[] |
| 854 for nodeid in cl.list(): | 854 for nodeid in cl.list(): |
| 855 try: | 855 try: |
| 856 proplist.append(cl.get(nodeid, propname)) | 856 proplist.append(cl.get(nodeid, propname)) |
| 857 except KeyError: | 857 except KeyError: |
| 858 raise UsageError, _('%(classname)s has no property ' | 858 raise UsageError, _('%(classname)s has no property ' |
| 859 '"%(propname)s"')%locals() | 859 '"%(propname)s"')%locals() |
| 860 print self.separator.join(proplist) | 860 print self.separator.join(proplist) |
| 861 else: | 861 else: |
| 862 # create a list of index id's since user didn't specify | 862 # create a list of index id's since user didn't specify |
| 863 # otherwise | 863 # otherwise |
| 864 print self.separator.join(cl.list()) | 864 print self.separator.join(cl.list()) |
| 865 else: | 865 else: |
| 866 for nodeid in cl.list(): | 866 for nodeid in cl.list(): |
| 867 try: | 867 try: |
| 868 value = cl.get(nodeid, propname) | 868 value = cl.get(nodeid, propname) |
| 1389 self.usage() | 1389 self.usage() |
| 1390 return 0 | 1390 return 0 |
| 1391 if opt == '-i': | 1391 if opt == '-i': |
| 1392 self.tracker_home = arg | 1392 self.tracker_home = arg |
| 1393 if opt == '-c': | 1393 if opt == '-c': |
| 1394 if self.separator != None: | 1394 if self.separator != None: |
| 1395 self.usage('Only one of -c, -S and -s may be specified') | 1395 self.usage('Only one of -c, -S and -s may be specified') |
| 1396 return 1 | 1396 return 1 |
| 1397 self.separator = ',' | 1397 self.separator = ',' |
| 1398 if opt == '-S': | 1398 if opt == '-S': |
| 1399 if self.separator != None: | 1399 if self.separator != None: |
| 1400 self.usage('Only one of -c, -S and -s may be specified') | 1400 self.usage('Only one of -c, -S and -s may be specified') |
| 1401 return 1 | 1401 return 1 |
| 1402 self.separator = arg | 1402 self.separator = arg |
| 1403 if opt == '-s': | 1403 if opt == '-s': |
| 1404 if self.separator != None: | 1404 if self.separator != None: |
| 1405 self.usage('Only one of -c, -S and -s may be specified') | 1405 self.usage('Only one of -c, -S and -s may be specified') |
| 1406 return 1 | 1406 return 1 |
| 1407 self.separator = ' ' | 1407 self.separator = ' ' |
| 1408 if opt == '-d': | 1408 if opt == '-d': |
| 1409 self.print_designator = 1 | 1409 self.print_designator = 1 |
| 1410 | 1410 |
| 1411 # if no command - go interactive | 1411 # if no command - go interactive |
