Mercurial > p > roundup > code
comparison roundup/admin.py @ 4229:4498f5252f8b gsoc-2009
Some preparations for 3.0 migration
| author | Pygi <pygi@users.sourceforge.net> |
|---|---|
| date | Fri, 24 Jul 2009 04:35:05 +0000 |
| parents | eddb82d0964c |
| children | f79670fe6fc9 |
comparison
equal
deleted
inserted
replaced
| 4223:c5228c29fa8e | 4229:4498f5252f8b |
|---|---|
| 533 l = [] | 533 l = [] |
| 534 for designator in designators: | 534 for designator in designators: |
| 535 # decode the node designator | 535 # decode the node designator |
| 536 try: | 536 try: |
| 537 classname, nodeid = hyperdb.splitDesignator(designator) | 537 classname, nodeid = hyperdb.splitDesignator(designator) |
| 538 except hyperdb.DesignatorError, message: | 538 except hyperdb.DesignatorError as message: |
| 539 raise UsageError, message | 539 raise UsageError, message |
| 540 | 540 |
| 541 # get the class | 541 # get the class |
| 542 cl = self.get_class(classname) | 542 cl = self.get_class(classname) |
| 543 try: | 543 try: |
| 619 cl = self.get_class(designator) | 619 cl = self.get_class(designator) |
| 620 designators = [(designator, x) for x in cl.list()] | 620 designators = [(designator, x) for x in cl.list()] |
| 621 else: | 621 else: |
| 622 try: | 622 try: |
| 623 designators = [hyperdb.splitDesignator(x) for x in designators] | 623 designators = [hyperdb.splitDesignator(x) for x in designators] |
| 624 except hyperdb.DesignatorError, message: | 624 except hyperdb.DesignatorError as message: |
| 625 raise UsageError, message | 625 raise UsageError, message |
| 626 | 626 |
| 627 # get the props from the args | 627 # get the props from the args |
| 628 props = self.props_from_args(args[1:]) | 628 props = self.props_from_args(args[1:]) |
| 629 | 629 |
| 634 properties = cl.getprops() | 634 properties = cl.getprops() |
| 635 for key, value in props.items(): | 635 for key, value in props.items(): |
| 636 try: | 636 try: |
| 637 props[key] = hyperdb.rawToHyperdb(self.db, cl, itemid, | 637 props[key] = hyperdb.rawToHyperdb(self.db, cl, itemid, |
| 638 key, value) | 638 key, value) |
| 639 except hyperdb.HyperdbValueError, message: | 639 except hyperdb.HyperdbValueError as message: |
| 640 raise UsageError, message | 640 raise UsageError, message |
| 641 | 641 |
| 642 # try the set | 642 # try the set |
| 643 try: | 643 try: |
| 644 apply(cl.set, (itemid, ), props) | 644 apply(cl.set, (itemid, ), props) |
| 645 except (TypeError, IndexError, ValueError), message: | 645 except (TypeError, IndexError, ValueError) as message: |
| 646 import traceback; traceback.print_exc() | 646 import traceback; traceback.print_exc() |
| 647 raise UsageError, message | 647 raise UsageError, message |
| 648 self.db_uncommitted = True | 648 self.db_uncommitted = True |
| 649 return 0 | 649 return 0 |
| 650 | 650 |
| 702 else: | 702 else: |
| 703 print apply(cl.find, (), props) | 703 print apply(cl.find, (), props) |
| 704 except KeyError: | 704 except KeyError: |
| 705 raise UsageError, _('%(classname)s has no property ' | 705 raise UsageError, _('%(classname)s has no property ' |
| 706 '"%(propname)s"')%locals() | 706 '"%(propname)s"')%locals() |
| 707 except (ValueError, TypeError), message: | 707 except (ValueError, TypeError) as message: |
| 708 raise UsageError, message | 708 raise UsageError, message |
| 709 return 0 | 709 return 0 |
| 710 | 710 |
| 711 def do_specification(self, args): | 711 def do_specification(self, args): |
| 712 ''"""Usage: specification classname | 712 ''"""Usage: specification classname |
| 740 | 740 |
| 741 # decode the node designator | 741 # decode the node designator |
| 742 for designator in args[0].split(','): | 742 for designator in args[0].split(','): |
| 743 try: | 743 try: |
| 744 classname, nodeid = hyperdb.splitDesignator(designator) | 744 classname, nodeid = hyperdb.splitDesignator(designator) |
| 745 except hyperdb.DesignatorError, message: | 745 except hyperdb.DesignatorError as message: |
| 746 raise UsageError, message | 746 raise UsageError, message |
| 747 | 747 |
| 748 # get the class | 748 # get the class |
| 749 cl = self.get_class(classname) | 749 cl = self.get_class(classname) |
| 750 | 750 |
| 801 # convert types | 801 # convert types |
| 802 for propname, value in props.items(): | 802 for propname, value in props.items(): |
| 803 try: | 803 try: |
| 804 props[propname] = hyperdb.rawToHyperdb(self.db, cl, None, | 804 props[propname] = hyperdb.rawToHyperdb(self.db, cl, None, |
| 805 propname, value) | 805 propname, value) |
| 806 except hyperdb.HyperdbValueError, message: | 806 except hyperdb.HyperdbValueError as message: |
| 807 raise UsageError, message | 807 raise UsageError, message |
| 808 | 808 |
| 809 # check for the key property | 809 # check for the key property |
| 810 propname = cl.getkey() | 810 propname = cl.getkey() |
| 811 if propname and not props.has_key(propname): | 811 if propname and not props.has_key(propname): |
| 813 'property.')%locals() | 813 'property.')%locals() |
| 814 | 814 |
| 815 # do the actual create | 815 # do the actual create |
| 816 try: | 816 try: |
| 817 print apply(cl.create, (), props) | 817 print apply(cl.create, (), props) |
| 818 except (TypeError, IndexError, ValueError), message: | 818 except (TypeError, IndexError, ValueError) as message: |
| 819 raise UsageError, message | 819 raise UsageError, message |
| 820 self.db_uncommitted = True | 820 self.db_uncommitted = True |
| 821 return 0 | 821 return 0 |
| 822 | 822 |
| 823 def do_list(self, args): | 823 def do_list(self, args): |
| 975 """ | 975 """ |
| 976 if len(args) < 1: | 976 if len(args) < 1: |
| 977 raise UsageError, _('Not enough arguments supplied') | 977 raise UsageError, _('Not enough arguments supplied') |
| 978 try: | 978 try: |
| 979 classname, nodeid = hyperdb.splitDesignator(args[0]) | 979 classname, nodeid = hyperdb.splitDesignator(args[0]) |
| 980 except hyperdb.DesignatorError, message: | 980 except hyperdb.DesignatorError as message: |
| 981 raise UsageError, message | 981 raise UsageError, message |
| 982 | 982 |
| 983 try: | 983 try: |
| 984 print self.db.getclass(classname).history(nodeid) | 984 print self.db.getclass(classname).history(nodeid) |
| 985 except KeyError: | 985 except KeyError: |
| 1027 raise UsageError, _('Not enough arguments supplied') | 1027 raise UsageError, _('Not enough arguments supplied') |
| 1028 designators = args[0].split(',') | 1028 designators = args[0].split(',') |
| 1029 for designator in designators: | 1029 for designator in designators: |
| 1030 try: | 1030 try: |
| 1031 classname, nodeid = hyperdb.splitDesignator(designator) | 1031 classname, nodeid = hyperdb.splitDesignator(designator) |
| 1032 except hyperdb.DesignatorError, message: | 1032 except hyperdb.DesignatorError as message: |
| 1033 raise UsageError, message | 1033 raise UsageError, message |
| 1034 try: | 1034 try: |
| 1035 self.db.getclass(classname).retire(nodeid) | 1035 self.db.getclass(classname).retire(nodeid) |
| 1036 except KeyError: | 1036 except KeyError: |
| 1037 raise UsageError, _('no such class "%(classname)s"')%locals() | 1037 raise UsageError as _('no such class "%(classname)s"')%locals() |
| 1038 except IndexError: | 1038 except IndexError: |
| 1039 raise UsageError, _('no such %(classname)s node "%(nodeid)s"')%locals() | 1039 raise UsageError as _('no such %(classname)s node "%(nodeid)s"')%locals() |
| 1040 self.db_uncommitted = True | 1040 self.db_uncommitted = True |
| 1041 return 0 | 1041 return 0 |
| 1042 | 1042 |
| 1043 def do_restore(self, args): | 1043 def do_restore(self, args): |
| 1044 ''"""Usage: restore designator[,designator]* | 1044 ''"""Usage: restore designator[,designator]* |
| 1050 raise UsageError, _('Not enough arguments supplied') | 1050 raise UsageError, _('Not enough arguments supplied') |
| 1051 designators = args[0].split(',') | 1051 designators = args[0].split(',') |
| 1052 for designator in designators: | 1052 for designator in designators: |
| 1053 try: | 1053 try: |
| 1054 classname, nodeid = hyperdb.splitDesignator(designator) | 1054 classname, nodeid = hyperdb.splitDesignator(designator) |
| 1055 except hyperdb.DesignatorError, message: | 1055 except hyperdb.DesignatorError as message: |
| 1056 raise UsageError, message | 1056 raise UsageError, message |
| 1057 try: | 1057 try: |
| 1058 self.db.getclass(classname).restore(nodeid) | 1058 self.db.getclass(classname).restore(nodeid) |
| 1059 except KeyError: | 1059 except KeyError: |
| 1060 raise UsageError, _('no such class "%(classname)s"')%locals() | 1060 raise UsageError as _('no such class "%(classname)s"')%locals() |
| 1061 except IndexError: | 1061 except IndexError: |
| 1062 raise UsageError, _('no such %(classname)s node "%(nodeid)s"')%locals() | 1062 raise UsageError as _('no such %(classname)s node "%(nodeid)s"')%locals() |
| 1063 self.db_uncommitted = True | 1063 self.db_uncommitted = True |
| 1064 return 0 | 1064 return 0 |
| 1065 | 1065 |
| 1066 def do_export(self, args, export_files=True): | 1066 def do_export(self, args, export_files=True): |
| 1067 ''"""Usage: export [[-]class[,class]] export_dir | 1067 ''"""Usage: export [[-]class[,class]] export_dir |
| 1400 | 1400 |
| 1401 # before we open the db, we may be doing an install or init | 1401 # before we open the db, we may be doing an install or init |
| 1402 if command == 'initialise': | 1402 if command == 'initialise': |
| 1403 try: | 1403 try: |
| 1404 return self.do_initialise(self.tracker_home, args) | 1404 return self.do_initialise(self.tracker_home, args) |
| 1405 except UsageError, message: | 1405 except UsageError as message: |
| 1406 print _('Error: %(message)s')%locals() | 1406 print _('Error: %(message)s')%locals() |
| 1407 return 1 | 1407 return 1 |
| 1408 elif command == 'install': | 1408 elif command == 'install': |
| 1409 try: | 1409 try: |
| 1410 return self.do_install(self.tracker_home, args) | 1410 return self.do_install(self.tracker_home, args) |
| 1411 except UsageError, message: | 1411 except UsageError as message: |
| 1412 print _('Error: %(message)s')%locals() | 1412 print _('Error: %(message)s')%locals() |
| 1413 return 1 | 1413 return 1 |
| 1414 | 1414 |
| 1415 # get the tracker | 1415 # get the tracker |
| 1416 try: | 1416 try: |
| 1417 tracker = roundup.instance.open(self.tracker_home) | 1417 tracker = roundup.instance.open(self.tracker_home) |
| 1418 except ValueError, message: | 1418 except ValueError as message: |
| 1419 self.tracker_home = '' | 1419 self.tracker_home = '' |
| 1420 print _("Error: Couldn't open tracker: %(message)s")%locals() | 1420 print _("Error: Couldn't open tracker: %(message)s")%locals() |
| 1421 return 1 | 1421 return 1 |
| 1422 | 1422 |
| 1423 # only open the database once! | 1423 # only open the database once! |
| 1426 | 1426 |
| 1427 # do the command | 1427 # do the command |
| 1428 ret = 0 | 1428 ret = 0 |
| 1429 try: | 1429 try: |
| 1430 ret = function(args[1:]) | 1430 ret = function(args[1:]) |
| 1431 except UsageError, message: | 1431 except UsageError as message: |
| 1432 print _('Error: %(message)s')%locals() | 1432 print _('Error: %(message)s')%locals() |
| 1433 print | 1433 print |
| 1434 print function.__doc__ | 1434 print function.__doc__ |
| 1435 ret = 1 | 1435 ret = 1 |
| 1436 except: | 1436 except: |
| 1469 return 0 | 1469 return 0 |
| 1470 | 1470 |
| 1471 def main(self): | 1471 def main(self): |
| 1472 try: | 1472 try: |
| 1473 opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdsS:vV') | 1473 opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdsS:vV') |
| 1474 except getopt.GetoptError, e: | 1474 except getopt.GetoptError as e: |
| 1475 self.usage(str(e)) | 1475 self.usage(str(e)) |
| 1476 return 1 | 1476 return 1 |
| 1477 | 1477 |
| 1478 # handle command-line args | 1478 # handle command-line args |
| 1479 self.tracker_home = os.environ.get('TRACKER_HOME', '') | 1479 self.tracker_home = os.environ.get('TRACKER_HOME', '') |
