Command reloading ended up being really super easy. @reload now rebuilds and re-imports all of the command modules. This should make development a lot easier.

This commit is contained in:
Greg Taylor 2009-01-27 16:16:43 +00:00
parent 4ca5a4a7bf
commit 5c5d2249bd
3 changed files with 32 additions and 22 deletions

View file

@ -68,7 +68,9 @@ def cmd_list(command):
if not command.command_argument:
source_object.emit_to(msg_invalid)
elif command.command_argument == "commands":
source_object.emit_to('Commands: '+ ' '.join(server.command_list()))
clist = GLOBAL_CMD_TABLE.ctable.keys()
clist.sort()
source_object.emit_to('Commands: '+ ' '.join(clist))
elif command.command_argument == "process":
if not functions_general.host_os_is('nt'):
loadvg = os.getloadavg()

View file

@ -13,9 +13,13 @@ def cmd_reload(command):
"""
Reloads all modules.
"""
command.source_object.emit_to("To be implemented...")
command.source_object.emit_to("Reloading command modules...")
command.session.server.reload(command.source_object)
command.source_object.emit_to("Modules reloaded.")
GLOBAL_CMD_TABLE.add_command("@reload", cmd_reload,
priv_tuple=("genperms.process_control")),
GLOBAL_CMD_TABLE.add_command("@restart", cmd_reload,
priv_tuple=("genperms.process_control")),
def cmd_boot(command):
"""

View file

@ -2,6 +2,7 @@ import time
import sys
from twisted.application import internet, service
from twisted.internet import protocol, reactor, defer
from twisted.python import rebuild
from django.db import connection
from django.conf import settings
from src.config.models import ConfigValue
@ -65,15 +66,22 @@ class EvenniaService(service.Service):
cursor.execute("PRAGMA count_changes=OFF")
cursor.execute("PRAGMA temp_store=2")
def get_command_modules(self):
"""
Combines all of the command modules and returns a tuple. Order is
preserved.
"""
return settings.COMMAND_MODULES +\
settings.CUSTOM_COMMAND_MODULES +\
settings.UNLOGGED_COMMAND_MODULES +\
settings.CUSTOM_UNLOGGED_COMMAND_MODULES
def load_command_table(self):
"""
Imports command modules and loads them into the command tables.
"""
# Combine the tuples of command modules to load.
cmd_modules = settings.COMMAND_MODULES +\
settings.CUSTOM_COMMAND_MODULES +\
settings.UNLOGGED_COMMAND_MODULES +\
settings.CUSTOM_UNLOGGED_COMMAND_MODULES
cmd_modules = self.get_command_modules()
# Import the command modules, which populates the command tables.
for cmd_mod in cmd_modules:
@ -87,31 +95,27 @@ class EvenniaService(service.Service):
BEGIN GENERAL METHODS
"""
def shutdown(self, message='The server has been shutdown. Please check back soon.'):
"""
Gracefully disconnect everyone and kill the reactor.
"""
session_mgr.announce_all(message)
session_mgr.disconnect_all_sessions()
reactor.callLater(0, reactor.stop)
def command_list(self):
"""
Return a string representing the server's command list.
"""
clist = cmdtable.GLOBAL_CMD_TABLE.ctable.keys()
clist.sort()
return clist
def reload(self, session):
def reload(self, source_object=None):
"""
Reload modules that don't have any variables that can be reset.
For changes to the scheduler, server, or session_mgr modules, a cold
restart is needed.
"""
reload_list = []
for mod in reload_list:
reload(sys.modules[mod])
session.msg("Modules reloaded.")
logger.log_infomsg("Modules reloaded by %s." % (session,))
cmd_modules = self.get_command_modules()
for mod_str, mod in sys.modules.items():
if mod_str in cmd_modules:
if source_object:
source_object.emit_to(" Reloading %s" % mod_str)
rebuild.rebuild(mod)
logger.log_infomsg("Modules reloaded by %s." % source_object)
def getEvenniaServiceFactory(self):
f = protocol.ServerFactory()