Mercurial > p > roundup > code
comparison roundup/scripts/roundup_server.py @ 5378:35ea9b1efc14
Python 3 preparation: "raise" syntax.
Changing "raise Exception, value" to "raise Exception(value)".
Tool-assisted patch. Particular cases to check carefully are the one
place in frontends/ZRoundup/ZRoundup.py where a string exception
needed to be fixed, and the one in roundup/cgi/client.py involving
raising an exception with a traceback (requires three-argument form of
raise in Python 2, which as I understand it requires exec() to avoid a
Python 3 syntax error).
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Tue, 24 Jul 2018 21:39:58 +0000 |
| parents | 64b05e24dbd8 |
| children | 0942fe89e82e |
comparison
equal
deleted
inserted
replaced
| 5377:12fe83f90f0d | 5378:35ea9b1efc14 |
|---|---|
| 477 return | 477 return |
| 478 | 478 |
| 479 try: | 479 try: |
| 480 import grp | 480 import grp |
| 481 except ImportError: | 481 except ImportError: |
| 482 raise ValueError, _("Can't change groups - no grp module") | 482 raise ValueError(_("Can't change groups - no grp module")) |
| 483 try: | 483 try: |
| 484 try: | 484 try: |
| 485 gid = int(group) | 485 gid = int(group) |
| 486 except ValueError: | 486 except ValueError: |
| 487 gid = grp.getgrnam(group)[2] | 487 gid = grp.getgrnam(group)[2] |
| 488 else: | 488 else: |
| 489 grp.getgrgid(gid) | 489 grp.getgrgid(gid) |
| 490 except KeyError: | 490 except KeyError: |
| 491 raise ValueError,_("Group %(group)s doesn't exist")%locals() | 491 raise ValueError(_("Group %(group)s doesn't exist")%locals()) |
| 492 os.setgid(gid) | 492 os.setgid(gid) |
| 493 | 493 |
| 494 def setuid(user): | 494 def setuid(user): |
| 495 if not hasattr(os, 'getuid'): | 495 if not hasattr(os, 'getuid'): |
| 496 return | 496 return |
| 497 | 497 |
| 498 # People can remove this check if they're really determined | 498 # People can remove this check if they're really determined |
| 499 if user is None: | 499 if user is None: |
| 500 if os.getuid(): | 500 if os.getuid(): |
| 501 return | 501 return |
| 502 raise ValueError, _("Can't run as root!") | 502 raise ValueError(_("Can't run as root!")) |
| 503 | 503 |
| 504 if os.getuid(): | 504 if os.getuid(): |
| 505 print(_('WARNING: ignoring "-u" argument, not root')) | 505 print(_('WARNING: ignoring "-u" argument, not root')) |
| 506 return | 506 return |
| 507 | 507 |
| 508 try: | 508 try: |
| 509 import pwd | 509 import pwd |
| 510 except ImportError: | 510 except ImportError: |
| 511 raise ValueError, _("Can't change users - no pwd module") | 511 raise ValueError(_("Can't change users - no pwd module")) |
| 512 try: | 512 try: |
| 513 try: | 513 try: |
| 514 uid = int(user) | 514 uid = int(user) |
| 515 except ValueError: | 515 except ValueError: |
| 516 uid = pwd.getpwnam(user)[2] | 516 uid = pwd.getpwnam(user)[2] |
| 517 else: | 517 else: |
| 518 pwd.getpwuid(uid) | 518 pwd.getpwuid(uid) |
| 519 except KeyError: | 519 except KeyError: |
| 520 raise ValueError, _("User %(user)s doesn't exist")%locals() | 520 raise ValueError(_("User %(user)s doesn't exist")%locals()) |
| 521 os.setuid(uid) | 521 os.setuid(uid) |
| 522 | 522 |
| 523 class TrackerHomeOption(configuration.FilePathOption): | 523 class TrackerHomeOption(configuration.FilePathOption): |
| 524 | 524 |
| 525 # Tracker homes do not need any description strings | 525 # Tracker homes do not need any description strings |
| 723 if self["SSL"]: | 723 if self["SSL"]: |
| 724 kwargs['ssl_pem'] = self["PEM"] | 724 kwargs['ssl_pem'] = self["PEM"] |
| 725 httpd = server_class(*args, **kwargs) | 725 httpd = server_class(*args, **kwargs) |
| 726 except socket.error as e: | 726 except socket.error as e: |
| 727 if e[0] == errno.EADDRINUSE: | 727 if e[0] == errno.EADDRINUSE: |
| 728 raise socket.error, \ | 728 raise socket.error(_("Unable to bind to port %s, port already in use.") \ |
| 729 _("Unable to bind to port %s, port already in use.") \ | 729 % self["PORT"]) |
| 730 % self["PORT"] | |
| 731 raise | 730 raise |
| 732 # change user and/or group | 731 # change user and/or group |
| 733 setgid(self["GROUP"]) | 732 setgid(self["GROUP"]) |
| 734 setuid(self["USER"]) | 733 setuid(self["USER"]) |
| 735 # return the server | 734 # return the server |
| 964 if args: | 963 if args: |
| 965 for arg in args: | 964 for arg in args: |
| 966 try: | 965 try: |
| 967 name, home = arg.split('=') | 966 name, home = arg.split('=') |
| 968 except ValueError: | 967 except ValueError: |
| 969 raise ValueError, _("Instances must be name=home") | 968 raise ValueError(_("Instances must be name=home")) |
| 970 config.add_option(TrackerHomeOption(config, "trackers", name)) | 969 config.add_option(TrackerHomeOption(config, "trackers", name)) |
| 971 config["TRACKERS_" + name.upper()] = home | 970 config["TRACKERS_" + name.upper()] = home |
| 972 | 971 |
| 973 # handle remaining options | 972 # handle remaining options |
| 974 if optlist: | 973 if optlist: |
