Cleaned up the evennia.py program, removing some i18n strings in order to handle missing settings files.

This commit is contained in:
Griatch 2012-02-15 18:53:15 +01:00
parent e170505878
commit 7675673010

View file

@ -20,11 +20,11 @@ os.environ['DJANGO_SETTINGS_MODULE'] = 'game.settings'
if not os.path.exists('settings.py'): if not os.path.exists('settings.py'):
# make sure we have a settings.py file. # make sure we have a settings.py file.
print _(" No settings.py file found. launching manage.py ...") print " No settings.py file found. launching manage.py ..."
import game.manage import game.manage
print _(""" print """
... A new settings file was created. Edit this file to configure ... A new settings file was created. Edit this file to configure
Evennia as desired by copy&pasting options from Evennia as desired by copy&pasting options from
src/settings_default.py. src/settings_default.py.
@ -44,16 +44,14 @@ if not os.path.exists('settings.py'):
and repeat the above manage.py steps to start with a fresh and repeat the above manage.py steps to start with a fresh
database. database.
When you are set up, run evennia.py again to start the server.""") When you are set up, run evennia.py again to start the server."""
sys.exit() sys.exit()
# i18n
from django.utils.translation import ugettext as _
# signal processing # signal processing
SIG = signal.SIGINT SIG = signal.SIGINT
HELPENTRY = \ HELPENTRY = \
_(""" """
(version %s) (version %s)
This program launches Evennia with various options. You can access all This program launches Evennia with various options. You can access all
@ -86,10 +84,10 @@ server (option 5) to make it available to users.
Reload and stop is not well supported in Windows. If you have issues, log Reload and stop is not well supported in Windows. If you have issues, log
into the game to stop or restart the server instead. into the game to stop or restart the server instead.
""") """
MENU = \ MENU = \
_(""" """
+---------------------------------------------------------------------------+ +---------------------------------------------------------------------------+
| | | |
| Welcome to the Evennia launcher! | | Welcome to the Evennia launcher! |
@ -123,7 +121,7 @@ _("""
| h) Help | | h) Help |
| q) Quit | | q) Quit |
+---------------------------------------------------------------------------+ +---------------------------------------------------------------------------+
""") """
# #
@ -158,7 +156,7 @@ try:
except ObjectDB.DoesNotExist: except ObjectDB.DoesNotExist:
pass # this is fine at this point pass # this is fine at this point
except DatabaseError: except DatabaseError:
print _(""" print """
Your database does not seem to be set up correctly. Your database does not seem to be set up correctly.
Please run: Please run:
@ -172,7 +170,7 @@ except DatabaseError:
python manage.py migrate python manage.py migrate
When you have a database set up, rerun evennia.py. When you have a database set up, rerun evennia.py.
""") """
sys.exit() sys.exit()
# Add this to the environmental variable for the 'twistd' command. # Add this to the environmental variable for the 'twistd' command.
@ -189,13 +187,13 @@ if os.name == 'nt':
# Test for for win32api # Test for for win32api
import win32api import win32api
except ImportError: except ImportError:
print _(""" print """
ERROR: Unable to import win32api, which Twisted requires to run. ERROR: Unable to import win32api, which Twisted requires to run.
You may download it from: You may download it from:
http://sourceforge.net/projects/pywin32 http://sourceforge.net/projects/pywin32
or or
http://starship.python.net/crew/mhammond/win32/Downloads.html""") http://starship.python.net/crew/mhammond/win32/Downloads.html"""
sys.exit() sys.exit()
if not os.path.exists('twistd.bat'): if not os.path.exists('twistd.bat'):
@ -213,7 +211,7 @@ if os.name == 'nt':
bat_file = open('twistd.bat','w') bat_file = open('twistd.bat','w')
bat_file.write("@\"%s\" \"%s\" %%*" % (sys.executable, twistd_path)) bat_file.write("@\"%s\" \"%s\" %%*" % (sys.executable, twistd_path))
bat_file.close() bat_file.close()
print _(""" print """
INFO: Since you are running Windows, a file 'twistd.bat' was INFO: Since you are running Windows, a file 'twistd.bat' was
created for you. This is a simple batch file that tries to call created for you. This is a simple batch file that tries to call
the twisted executable. Evennia determined this to be: the twisted executable. Evennia determined this to be:
@ -226,7 +224,7 @@ if os.name == 'nt':
This procedure is only done once. Run evennia.py again when you This procedure is only done once. Run evennia.py again when you
are ready to start the server. are ready to start the server.
""") % {'twistd_path': twistd_path} """ % {'twistd_path': twistd_path}
sys.exit() sys.exit()
TWISTED_BINARY = 'twistd.bat' TWISTED_BINARY = 'twistd.bat'
@ -263,7 +261,7 @@ def kill(pidfile, signal=SIG, succmsg="", errmsg="", restart_file=SERVER_RESTART
if pid: if pid:
if os.name == 'nt': if os.name == 'nt':
if sys.version < "2.7": if sys.version < "2.7":
print _("Windows requires Python 2.7 or higher for this operation.") print "Windows requires Python 2.7 or higher for this operation."
return return
os.remove(pidfile) os.remove(pidfile)
# set restart/norestart flag # set restart/norestart flag
@ -273,7 +271,7 @@ def kill(pidfile, signal=SIG, succmsg="", errmsg="", restart_file=SERVER_RESTART
try: try:
os.kill(int(pid), signal) os.kill(int(pid), signal)
except OSError: except OSError:
print _("Process %(pid)s could not be signalled. The PID file '%(pidfile)s' seems stale. Try removing it.") % {'pid': pid, 'pidfile': pidfile} print "Process %(pid)s could not be signalled. The PID file '%(pidfile)s' seems stale. Try removing it." % {'pid': pid, 'pidfile': pidfile}
return return
print "Evennia:", succmsg print "Evennia:", succmsg
return return
@ -290,23 +288,23 @@ def run_menu():
# menu loop # menu loop
print MENU print MENU
inp = raw_input(_(" option > ")) inp = raw_input(" option > ")
# quitting and help # quitting and help
if inp.lower() == 'q': if inp.lower() == 'q':
sys.exit() sys.exit()
elif inp.lower() == 'h': elif inp.lower() == 'h':
print HELPENTRY % EVENNIA_VERSION print HELPENTRY % EVENNIA_VERSION
raw_input(_("press <return> to continue ...")) raw_input("press <return> to continue ...")
continue continue
# options # options
try: try:
inp = int(inp) inp = int(inp)
except ValueError: except ValueError:
print _("Not a valid option.") print "Not a valid option."
continue continue
errmsg = _("The %s does not seem to be running.") errmsg = "The %s does not seem to be running."
if inp < 5: if inp < 5:
if inp == 1: if inp == 1:
pass # default operation pass # default operation
@ -320,24 +318,24 @@ def run_menu():
elif inp < 10: elif inp < 10:
if inp == 5: if inp == 5:
if os.name == 'nt': if os.name == 'nt':
print _("This operation is not supported under Windows. Log into the game to restart/reload the server.") print "This operation is not supported under Windows. Log into the game to restart/reload the server."
return return
kill(SERVER_PIDFILE, SIG, _("Server reloaded."), errmsg % "Server") kill(SERVER_PIDFILE, SIG, "Server reloaded.", errmsg % "Server")
elif inp == 6: elif inp == 6:
if os.name == 'nt': if os.name == 'nt':
print _("This operation is not supported under Windows.") print "This operation is not supported under Windows."
return return
kill(PORTAL_PIDFILE, SIG, _("Portal reloaded (or stopped if in daemon mode)."), errmsg % "Portal") kill(PORTAL_PIDFILE, SIG, "Portal reloaded (or stopped if in daemon mode).", errmsg % "Portal")
elif inp == 7: elif inp == 7:
kill(SERVER_PIDFILE, SIG, _("Stopped Portal."), errmsg % "Portal", PORTAL_RESTART, restart=False) kill(SERVER_PIDFILE, SIG, "Stopped Portal.", errmsg % "Portal", PORTAL_RESTART, restart=False)
kill(PORTAL_PIDFILE, SIG, _("Stopped Server."), errmsg % "Server", restart=False) kill(PORTAL_PIDFILE, SIG, "Stopped Server.", errmsg % "Server", restart=False)
elif inp == 8: elif inp == 8:
kill(PORTAL_PIDFILE, SIG, _("Stopped Server."), errmsg % "Server", restart=False) kill(PORTAL_PIDFILE, SIG, "Stopped Server.", errmsg % "Server", restart=False)
elif inp == 9: elif inp == 9:
kill(SERVER_PIDFILE, SIG, _("Stopped Portal."), errmsg % "Portal", PORTAL_RESTART, restart=False) kill(SERVER_PIDFILE, SIG, "Stopped Portal.", errmsg % "Portal", PORTAL_RESTART, restart=False)
return return
else: else:
print _("Not a valid option.") print "Not a valid option."
return None return None
@ -352,7 +350,7 @@ def handle_args(options, mode, service):
inter = options.interactive inter = options.interactive
cmdstr = ["python", "runner.py"] cmdstr = ["python", "runner.py"]
errmsg = _("The %s does not seem to be running.") errmsg = "The %s does not seem to be running."
if mode == 'start': if mode == 'start':
@ -377,28 +375,30 @@ def handle_args(options, mode, service):
elif mode == 'reload': elif mode == 'reload':
# restarting services # restarting services
if os.name == 'nt': if os.name == 'nt':
print _("Restarting from command line is not supported under Windows. Log into the game to restart.") print "Restarting from command line is not supported under Windows. Log into the game to restart."
return return
if service == 'server': if service == 'server':
kill(SERVER_PIDFILE, SIG, _("Server reloaded."), errmsg % 'Server') kill(SERVER_PIDFILE, SIG, "Server reloaded.", errmsg % 'Server')
elif service == 'portal': elif service == 'portal':
print _("Note: Portal usually don't need to be reloaded unless you are debugging in interactive mode.") print """
print _("If Portal was running in default Daemon mode, it cannot be restarted. In that case you have ") Note: Portal usually don't need to be reloaded unless you are debugging in interactive mode.
print _("to restart it manually with 'evennia.py start portal'") If Portal was running in default Daemon mode, it cannot be restarted. In that case you have
kill(PORTAL_PIDFILE, SIG, _("Portal reloaded (or stopped, if it was in daemon mode)."), errmsg % 'Portal', PORTAL_RESTART) to restart it manually with 'evennia.py start portal'
"""
kill(PORTAL_PIDFILE, SIG, "Portal reloaded (or stopped, if it was in daemon mode).", errmsg % 'Portal', PORTAL_RESTART)
else: # all else: # all
# default mode, only restart server # default mode, only restart server
kill(SERVER_PIDFILE, SIG, _("Server reload."), errmsg % 'Server') kill(SERVER_PIDFILE, SIG, "Server reload.", errmsg % 'Server')
elif mode == 'stop': elif mode == 'stop':
# stop processes, avoiding reload # stop processes, avoiding reload
if service == 'server': if service == 'server':
kill(SERVER_PIDFILE, SIG, _("Server stopped."), errmsg % 'Server', restart=False) kill(SERVER_PIDFILE, SIG, "Server stopped.", errmsg % 'Server', restart=False)
elif service == 'portal': elif service == 'portal':
kill(PORTAL_PIDFILE, SIG, _("Portal stopped."), errmsg % 'Portal', PORTAL_RESTART, restart=False) kill(PORTAL_PIDFILE, SIG, "Portal stopped.", errmsg % 'Portal', PORTAL_RESTART, restart=False)
else: else:
kill(PORTAL_PIDFILE, SIG, _("Portal stopped."), errmsg % 'Portal', PORTAL_RESTART, restart=False) kill(PORTAL_PIDFILE, SIG, "Portal stopped.", errmsg % 'Portal', PORTAL_RESTART, restart=False)
kill(SERVER_PIDFILE, SIG, _("Server stopped."), errmsg % 'Server', restart=False) kill(SERVER_PIDFILE, SIG, "Server stopped.", errmsg % 'Server', restart=False)
return None return None
def error_check_python_modules(): def error_check_python_modules():
@ -443,9 +443,9 @@ def main():
""" """
parser = OptionParser(usage="%prog [-i] [menu|start|reload|stop [server|portal|all]]", parser = OptionParser(usage="%prog [-i] [menu|start|reload|stop [server|portal|all]]",
description=_("""This is the main Evennia launcher. It handles the Portal and Server, the two services making up Evennia. Default is to operate on both services. Use --interactive together with start to launch services as 'interactive'. Note that when launching 'all' services with the --interactive flag, both services will be started, but only Server will actually be started in interactive mode. This is simply because this is the most commonly useful state. To activate interactive mode also for Portal, launch the two services explicitly as two separate calls to this program. You can also use the menu.""")) description="""This is the main Evennia launcher. It handles the Portal and Server, the two services making up Evennia. Default is to operate on both services. Use --interactive together with start to launch services as 'interactive'. Note that when launching 'all' services with the --interactive flag, both services will be started, but only Server will actually be started in interactive mode. This is simply because this is the most commonly useful state. To activate interactive mode also for Portal, launch the two services explicitly as two separate calls to this program. You can also use the menu.""")
parser.add_option('-i', '--interactive', action='store_true', dest='interactive', default=False, help=_("Start given processes in interactive mode (log to stdout, don't start as a daemon).")) parser.add_option('-i', '--interactive', action='store_true', dest='interactive', default=False, help="Start given processes in interactive mode (log to stdout, don't start as a daemon).")
options, args = parser.parse_args() options, args = parser.parse_args()
inter = options.interactive inter = options.interactive
@ -460,10 +460,10 @@ def main():
service = args[1] service = args[1]
if mode not in ['menu', 'start', 'reload', 'stop']: if mode not in ['menu', 'start', 'reload', 'stop']:
print _("mode should be none or one of 'menu', 'start', 'reload' or 'stop'.") print "mode should be none or one of 'menu', 'start', 'reload' or 'stop'."
sys.exit() sys.exit()
if service not in ['server', 'portal', 'all']: if service not in ['server', 'portal', 'all']:
print _("service should be none or 'server', 'portal' or 'all'.") print "service should be none or 'server', 'portal' or 'all'."
sys.exit() sys.exit()
if mode == 'menu': if mode == 'menu':
@ -478,7 +478,7 @@ def main():
Popen(cmdstr) Popen(cmdstr)
if __name__ == '__main__': if __name__ == '__main__':
# start Evennia
from src.utils.utils import check_evennia_dependencies from src.utils.utils import check_evennia_dependencies
if check_evennia_dependencies(): if check_evennia_dependencies():
main() main()