Trunk: Merged the Devel-branch (branches/griatch) into /trunk. This constitutes a major refactoring of Evennia. Development will now continue in trunk. See the wiki and the past posts to the mailing list for info. /Griatch
This commit is contained in:
parent
df29defbcd
commit
f83c2bddf8
222 changed files with 22304 additions and 14371 deletions
112
game/evennia.py
112
game/evennia.py
|
|
@ -5,49 +5,104 @@ EVENNIA SERVER STARTUP SCRIPT
|
|||
Sets the appropriate environmental variables and launches the server
|
||||
process. Run the script with the -h flag to see usage information.
|
||||
"""
|
||||
from optparse import OptionParser
|
||||
from subprocess import Popen, call
|
||||
import os
|
||||
import sys
|
||||
import signal
|
||||
from optparse import OptionParser
|
||||
from subprocess import Popen, call
|
||||
|
||||
# Set the Python path up so we can get to settings.py from here.
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'game.settings'
|
||||
from django.conf import settings
|
||||
SERVER_PY_FILE = os.path.join(settings.SRC_DIR, 'server.py')
|
||||
|
||||
# Determine what the twistd binary name is. Eventually may want to have a
|
||||
# setting in settings.py to specify the path to the containing directory.
|
||||
if not os.path.exists('settings.py'):
|
||||
# make sure we have a settings.py file.
|
||||
print " No settings.py file found. Launching manage.py ..."
|
||||
|
||||
import game.manage
|
||||
|
||||
print """
|
||||
Now configure Evennia by editing your new settings.py file.
|
||||
If you haven't already, you should also create/configure the
|
||||
database with 'python manage.py syncdb' before continuing.
|
||||
|
||||
When you are ready, run this program again to start the server."""
|
||||
sys.exit()
|
||||
|
||||
# Get the settings
|
||||
from django.conf import settings
|
||||
|
||||
# Setup the launch of twisted depending on which operating system we use
|
||||
if os.name == 'nt':
|
||||
TWISTED_BINARY = 'twistd.bat'
|
||||
|
||||
try:
|
||||
# Test for for win32api
|
||||
import win32api
|
||||
except ImportError:
|
||||
print "=" * 78
|
||||
print """ERROR: Unable to import win32api, which Twisted requires to run. You may
|
||||
download it from:
|
||||
print """
|
||||
ERROR: Unable to import win32api, which Twisted requires to run.
|
||||
You may download it from:
|
||||
|
||||
http://starship.python.net/crew/mhammond/win32/Downloads.html"""
|
||||
print "=" * 78
|
||||
http://sourceforge.net/projects/pywin32
|
||||
or
|
||||
http://starship.python.net/crew/mhammond/win32/Downloads.html"""
|
||||
sys.exit()
|
||||
|
||||
if not os.path.exists('twistd.bat'):
|
||||
# Test for executable twisted batch file. This calls the twistd.py
|
||||
# executable that is usually not found on the path in Windows.
|
||||
# It's not enough to locate scripts.twistd, what we want is the
|
||||
# executable script C:\PythonXX/Scripts/twistd.py. Alas we cannot
|
||||
# hardcode this location since we don't know if user has Python
|
||||
# in a non-standard location, so we try to figure it out.
|
||||
from twisted.scripts import twistd
|
||||
twistd_path = os.path.abspath(
|
||||
os.path.join(os.path.dirname(twistd.__file__),
|
||||
os.pardir, os.pardir, os.pardir, os.pardir,
|
||||
'scripts', 'twistd.py'))
|
||||
bat_file = open('twistd.bat','w')
|
||||
bat_file.write("@%s %%*" % twistd_path)
|
||||
bat_file.close()
|
||||
print """
|
||||
INFO: Since you are running Windows, a twistd.bat file was created for you.
|
||||
The twistd.bat is a simple batch file that tries to call the twisted
|
||||
executable. The system has determined this to be:
|
||||
|
||||
%s
|
||||
|
||||
If you should run into errors you might need to edit twistd.bat to point to
|
||||
the correct location of the Twisted executable (usually called twistd.py).
|
||||
|
||||
When you are ready, run this program again to retry the server restart.""" % twistd_path
|
||||
sys.exit()
|
||||
|
||||
TWISTED_BINARY = 'twistd.bat'
|
||||
else:
|
||||
TWISTED_BINARY = 'twistd'
|
||||
|
||||
# Setup access of the evennia server itself
|
||||
SERVER_PY_FILE = os.path.join(settings.SRC_DIR, 'server/server.py')
|
||||
|
||||
# Add this to the environmental variable for the 'twistd' command.
|
||||
tmppath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
thispath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
if 'PYTHONPATH' in os.environ:
|
||||
os.environ['PYTHONPATH'] += (":%s" % tmppath)
|
||||
os.environ['PYTHONPATH'] += (":%s" % thispath)
|
||||
else:
|
||||
os.environ['PYTHONPATH'] = tmppath
|
||||
os.environ['PYTHONPATH'] = thispath
|
||||
|
||||
def cycle_logfile():
|
||||
"""
|
||||
Move the old log file to evennia.log (by default).
|
||||
"""
|
||||
if os.path.exists(settings.DEFAULT_LOG_FILE):
|
||||
os.rename(settings.DEFAULT_LOG_FILE,
|
||||
settings.DEFAULT_LOG_FILE+'.old')
|
||||
Move the old log file to evennia.log.old (by default).
|
||||
|
||||
"""
|
||||
logfile = settings.DEFAULT_LOG_FILE.strip()
|
||||
logfile_old = logfile + '.old'
|
||||
if os.path.exists(logfile):
|
||||
# Cycle the old logfiles to *.old
|
||||
if os.path.exists(logfile_old):
|
||||
# E.g. Windows don't support rename-replace
|
||||
os.remove(logfile_old)
|
||||
os.rename(logfile, logfile_old)
|
||||
|
||||
def start_daemon(parser, options, args):
|
||||
"""
|
||||
|
|
@ -59,7 +114,8 @@ def start_daemon(parser, options, args):
|
|||
print "A twistd.pid file exists in the current directory, which suggests that the server is already running."
|
||||
sys.exit()
|
||||
|
||||
print 'Starting in daemon mode...'
|
||||
print '\nStarting Evennia server in daemon mode ...'
|
||||
print 'Logging to: %s.' % settings.DEFAULT_LOG_FILE
|
||||
|
||||
# Move the old evennia.log file out of the way.
|
||||
cycle_logfile()
|
||||
|
|
@ -74,7 +130,9 @@ def start_interactive(parser, options, args):
|
|||
Start in interactive mode, which means the process is foregrounded and
|
||||
all logging output is directed to stdout.
|
||||
"""
|
||||
print 'Starting in interactive mode...'
|
||||
print '\nStarting Evennia server in interactive mode (stop with keyboard interrupt) ...'
|
||||
print 'Logging to: Standard output.'
|
||||
|
||||
try:
|
||||
call([TWISTED_BINARY,
|
||||
'-n',
|
||||
|
|
@ -88,7 +146,7 @@ def stop_server(parser, options, args):
|
|||
"""
|
||||
if os.name == 'posix':
|
||||
if os.path.exists('twistd.pid'):
|
||||
print 'Stoping the server...'
|
||||
print 'Stopping the Evennia server...'
|
||||
f = open('twistd.pid', 'r')
|
||||
pid = f.read()
|
||||
os.kill(int(pid), signal.SIGINT)
|
||||
|
|
@ -96,16 +154,18 @@ def stop_server(parser, options, args):
|
|||
else:
|
||||
print "No twistd.pid file exists, the server doesn't appear to be running."
|
||||
elif os.name == 'nt':
|
||||
print 'TODO not implented'
|
||||
print '\n\rStopping cannot be done safely under this operating system.'
|
||||
print 'Kill server using the task manager or shut it down from inside the game.'
|
||||
else:
|
||||
print 'Unknown OS delected, can not kill'
|
||||
print '\n\rUnknown OS detected, can not stop. '
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Beginning of the program logic.
|
||||
"""
|
||||
parser = OptionParser(usage="%prog [options] <start|stop>",
|
||||
description="This command starts or stops the Evennia game server.")
|
||||
description="This command starts or stops the Evennia game server. Note that you have to setup the database by running 'manage.py syncdb' before starting the server for the first time.")
|
||||
parser.add_option('-i', '--interactive', action='store_true',
|
||||
dest='interactive', default=False,
|
||||
help='Start in interactive mode')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue