Mercurial > p > roundup > code
comparison roundup/admin.py @ 5248:198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Many raise statements near these are also fixed.
So are two ivorrect file encoding marks ('utf8'->'utf-8').
| author | Eric S. Raymond <esr@thyrsus.com> |
|---|---|
| date | Thu, 24 Aug 2017 22:21:37 -0400 |
| parents | bc16d91b7a50 |
| children | ac7fe3483206 |
comparison
equal
deleted
inserted
replaced
| 5247:7f00a47b3559 | 5248:198b6e810c67 |
|---|---|
| 556 l = [] | 556 l = [] |
| 557 for designator in designators: | 557 for designator in designators: |
| 558 # decode the node designator | 558 # decode the node designator |
| 559 try: | 559 try: |
| 560 classname, nodeid = hyperdb.splitDesignator(designator) | 560 classname, nodeid = hyperdb.splitDesignator(designator) |
| 561 except hyperdb.DesignatorError, message: | 561 except hyperdb.DesignatorError as message: |
| 562 raise UsageError(message) | 562 raise UsageError(message) |
| 563 | 563 |
| 564 # get the class | 564 # get the class |
| 565 cl = self.get_class(classname) | 565 cl = self.get_class(classname) |
| 566 try: | 566 try: |
| 652 cl = self.get_class(designator) | 652 cl = self.get_class(designator) |
| 653 designators = [(designator, x) for x in cl.list()] | 653 designators = [(designator, x) for x in cl.list()] |
| 654 else: | 654 else: |
| 655 try: | 655 try: |
| 656 designators = [hyperdb.splitDesignator(x) for x in designators] | 656 designators = [hyperdb.splitDesignator(x) for x in designators] |
| 657 except hyperdb.DesignatorError, message: | 657 except hyperdb.DesignatorError as message: |
| 658 raise UsageError(message) | 658 raise UsageError(message) |
| 659 | 659 |
| 660 # get the props from the args | 660 # get the props from the args |
| 661 propset = self.props_from_args(args[1:]) # parse the cli once | 661 propset = self.props_from_args(args[1:]) # parse the cli once |
| 662 | 662 |
| 673 # in the db) after rawToHyperdb returns. | 673 # in the db) after rawToHyperdb returns. |
| 674 # This new value is used for all the rest of the | 674 # This new value is used for all the rest of the |
| 675 # designators if not reinitalized. | 675 # designators if not reinitalized. |
| 676 props[key] = hyperdb.rawToHyperdb(self.db, cl, itemid, | 676 props[key] = hyperdb.rawToHyperdb(self.db, cl, itemid, |
| 677 key, value) | 677 key, value) |
| 678 except hyperdb.HyperdbValueError, message: | 678 except hyperdb.HyperdbValueError as message: |
| 679 raise UsageError(message) | 679 raise UsageError(message) |
| 680 | 680 |
| 681 # try the set | 681 # try the set |
| 682 try: | 682 try: |
| 683 cl.set(itemid, **props) | 683 cl.set(itemid, **props) |
| 684 except (TypeError, IndexError, ValueError), message: | 684 except (TypeError, IndexError, ValueError) as message: |
| 685 import traceback; traceback.print_exc() | 685 import traceback; traceback.print_exc() |
| 686 raise UsageError(message) | 686 raise UsageError(message) |
| 687 self.db_uncommitted = True | 687 self.db_uncommitted = True |
| 688 return 0 | 688 return 0 |
| 689 | 689 |
| 741 else: | 741 else: |
| 742 print cl.find(**props) | 742 print cl.find(**props) |
| 743 except KeyError: | 743 except KeyError: |
| 744 raise UsageError(_('%(classname)s has no property ' | 744 raise UsageError(_('%(classname)s has no property ' |
| 745 '"%(propname)s"')%locals()) | 745 '"%(propname)s"')%locals()) |
| 746 except (ValueError, TypeError), message: | 746 except (ValueError, TypeError) as message: |
| 747 raise UsageError(message) | 747 raise UsageError(message) |
| 748 return 0 | 748 return 0 |
| 749 | 749 |
| 750 def do_specification(self, args): | 750 def do_specification(self, args): |
| 751 ''"""Usage: specification classname | 751 ''"""Usage: specification classname |
| 783 | 783 |
| 784 # decode the node designator | 784 # decode the node designator |
| 785 for designator in args[0].split(','): | 785 for designator in args[0].split(','): |
| 786 try: | 786 try: |
| 787 classname, nodeid = hyperdb.splitDesignator(designator) | 787 classname, nodeid = hyperdb.splitDesignator(designator) |
| 788 except hyperdb.DesignatorError, message: | 788 except hyperdb.DesignatorError as message: |
| 789 raise UsageError(message) | 789 raise UsageError(message) |
| 790 | 790 |
| 791 # get the class | 791 # get the class |
| 792 cl = self.get_class(classname) | 792 cl = self.get_class(classname) |
| 793 | 793 |
| 844 # convert types | 844 # convert types |
| 845 for propname in props: | 845 for propname in props: |
| 846 try: | 846 try: |
| 847 props[propname] = hyperdb.rawToHyperdb(self.db, cl, None, | 847 props[propname] = hyperdb.rawToHyperdb(self.db, cl, None, |
| 848 propname, props[propname]) | 848 propname, props[propname]) |
| 849 except hyperdb.HyperdbValueError, message: | 849 except hyperdb.HyperdbValueError as message: |
| 850 raise UsageError(message) | 850 raise UsageError(message) |
| 851 | 851 |
| 852 # check for the key property | 852 # check for the key property |
| 853 propname = cl.getkey() | 853 propname = cl.getkey() |
| 854 if propname and propname not in props: | 854 if propname and propname not in props: |
| 856 'property.')%locals()) | 856 'property.')%locals()) |
| 857 | 857 |
| 858 # do the actual create | 858 # do the actual create |
| 859 try: | 859 try: |
| 860 sys.stdout.write(cl.create(**props) + '\n') | 860 sys.stdout.write(cl.create(**props) + '\n') |
| 861 except (TypeError, IndexError, ValueError), message: | 861 except (TypeError, IndexError, ValueError) as message: |
| 862 raise UsageError(message) | 862 raise UsageError(message) |
| 863 self.db_uncommitted = True | 863 self.db_uncommitted = True |
| 864 return 0 | 864 return 0 |
| 865 | 865 |
| 866 def do_list(self, args): | 866 def do_list(self, args): |
| 1026 | 1026 |
| 1027 if len(args) < 1: | 1027 if len(args) < 1: |
| 1028 raise UsageError(_('Not enough arguments supplied')) | 1028 raise UsageError(_('Not enough arguments supplied')) |
| 1029 try: | 1029 try: |
| 1030 classname, nodeid = hyperdb.splitDesignator(args[0]) | 1030 classname, nodeid = hyperdb.splitDesignator(args[0]) |
| 1031 except hyperdb.DesignatorError, message: | 1031 except hyperdb.DesignatorError as message: |
| 1032 raise UsageError(message) | 1032 raise UsageError(message) |
| 1033 | 1033 |
| 1034 skipquiet = False | 1034 skipquiet = False |
| 1035 if len(args) == 2: | 1035 if len(args) == 2: |
| 1036 if args[1] != 'skipquiet': | 1036 if args[1] != 'skipquiet': |
| 1089 raise UsageError(_('Not enough arguments supplied')) | 1089 raise UsageError(_('Not enough arguments supplied')) |
| 1090 designators = args[0].split(',') | 1090 designators = args[0].split(',') |
| 1091 for designator in designators: | 1091 for designator in designators: |
| 1092 try: | 1092 try: |
| 1093 classname, nodeid = hyperdb.splitDesignator(designator) | 1093 classname, nodeid = hyperdb.splitDesignator(designator) |
| 1094 except hyperdb.DesignatorError, message: | 1094 except hyperdb.DesignatorError as message: |
| 1095 raise UsageError(message) | 1095 raise UsageError(message) |
| 1096 try: | 1096 try: |
| 1097 self.db.getclass(classname).retire(nodeid) | 1097 self.db.getclass(classname).retire(nodeid) |
| 1098 except KeyError: | 1098 except KeyError: |
| 1099 raise UsageError(_('no such class "%(classname)s"')%locals()) | 1099 raise UsageError(_('no such class "%(classname)s"')%locals()) |
| 1116 raise UsageError(_('Not enough arguments supplied')) | 1116 raise UsageError(_('Not enough arguments supplied')) |
| 1117 designators = args[0].split(',') | 1117 designators = args[0].split(',') |
| 1118 for designator in designators: | 1118 for designator in designators: |
| 1119 try: | 1119 try: |
| 1120 classname, nodeid = hyperdb.splitDesignator(designator) | 1120 classname, nodeid = hyperdb.splitDesignator(designator) |
| 1121 except hyperdb.DesignatorError, message: | 1121 except hyperdb.DesignatorError as message: |
| 1122 raise UsageError(message) | 1122 raise UsageError(message) |
| 1123 try: | 1123 try: |
| 1124 self.db.getclass(classname).restore(nodeid) | 1124 self.db.getclass(classname).restore(nodeid) |
| 1125 except KeyError: | 1125 except KeyError: |
| 1126 raise UsageError(_('no such class "%(classname)s"')%locals()) | 1126 raise UsageError(_('no such class "%(classname)s"')%locals()) |
| 1493 | 1493 |
| 1494 # before we open the db, we may be doing an install or init | 1494 # before we open the db, we may be doing an install or init |
| 1495 if command == 'initialise': | 1495 if command == 'initialise': |
| 1496 try: | 1496 try: |
| 1497 return self.do_initialise(self.tracker_home, args) | 1497 return self.do_initialise(self.tracker_home, args) |
| 1498 except UsageError, message: | 1498 except UsageError as message: |
| 1499 print _('Error: %(message)s')%locals() | 1499 print _('Error: %(message)s')%locals() |
| 1500 return 1 | 1500 return 1 |
| 1501 elif command == 'install': | 1501 elif command == 'install': |
| 1502 try: | 1502 try: |
| 1503 return self.do_install(self.tracker_home, args) | 1503 return self.do_install(self.tracker_home, args) |
| 1504 except UsageError, message: | 1504 except UsageError as message: |
| 1505 print _('Error: %(message)s')%locals() | 1505 print _('Error: %(message)s')%locals() |
| 1506 return 1 | 1506 return 1 |
| 1507 | 1507 |
| 1508 # get the tracker | 1508 # get the tracker |
| 1509 try: | 1509 try: |
| 1510 tracker = roundup.instance.open(self.tracker_home) | 1510 tracker = roundup.instance.open(self.tracker_home) |
| 1511 except ValueError, message: | 1511 except ValueError as message: |
| 1512 self.tracker_home = '' | 1512 self.tracker_home = '' |
| 1513 print _("Error: Couldn't open tracker: %(message)s")%locals() | 1513 print _("Error: Couldn't open tracker: %(message)s")%locals() |
| 1514 return 1 | 1514 return 1 |
| 1515 except NoConfigError, message: | 1515 except NoConfigError as message: |
| 1516 self.tracker_home = '' | 1516 self.tracker_home = '' |
| 1517 print _("Error: Couldn't open tracker: %(message)s")%locals() | 1517 print _("Error: Couldn't open tracker: %(message)s")%locals() |
| 1518 return 1 | 1518 return 1 |
| 1519 | 1519 |
| 1520 # only open the database once! | 1520 # only open the database once! |
| 1525 | 1525 |
| 1526 # do the command | 1526 # do the command |
| 1527 ret = 0 | 1527 ret = 0 |
| 1528 try: | 1528 try: |
| 1529 ret = function(args[1:]) | 1529 ret = function(args[1:]) |
| 1530 except UsageError, message: | 1530 except UsageError as message: |
| 1531 print _('Error: %(message)s')%locals() | 1531 print _('Error: %(message)s')%locals() |
| 1532 print | 1532 print |
| 1533 print function.__doc__ | 1533 print function.__doc__ |
| 1534 ret = 1 | 1534 ret = 1 |
| 1535 except: | 1535 except: |
| 1571 return 0 | 1571 return 0 |
| 1572 | 1572 |
| 1573 def main(self): | 1573 def main(self): |
| 1574 try: | 1574 try: |
| 1575 opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdsS:vV') | 1575 opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdsS:vV') |
| 1576 except getopt.GetoptError, e: | 1576 except getopt.GetoptError as e: |
| 1577 self.usage(str(e)) | 1577 self.usage(str(e)) |
| 1578 return 1 | 1578 return 1 |
| 1579 | 1579 |
| 1580 # handle command-line args | 1580 # handle command-line args |
| 1581 self.tracker_home = os.environ.get('TRACKER_HOME', '') | 1581 self.tracker_home = os.environ.get('TRACKER_HOME', '') |
