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:
parent
4ca5a4a7bf
commit
5c5d2249bd
3 changed files with 32 additions and 22 deletions
|
|
@ -68,7 +68,9 @@ def cmd_list(command):
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
source_object.emit_to(msg_invalid)
|
source_object.emit_to(msg_invalid)
|
||||||
elif command.command_argument == "commands":
|
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":
|
elif command.command_argument == "process":
|
||||||
if not functions_general.host_os_is('nt'):
|
if not functions_general.host_os_is('nt'):
|
||||||
loadvg = os.getloadavg()
|
loadvg = os.getloadavg()
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,13 @@ def cmd_reload(command):
|
||||||
"""
|
"""
|
||||||
Reloads all modules.
|
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,
|
GLOBAL_CMD_TABLE.add_command("@reload", cmd_reload,
|
||||||
priv_tuple=("genperms.process_control")),
|
priv_tuple=("genperms.process_control")),
|
||||||
|
GLOBAL_CMD_TABLE.add_command("@restart", cmd_reload,
|
||||||
|
priv_tuple=("genperms.process_control")),
|
||||||
|
|
||||||
def cmd_boot(command):
|
def cmd_boot(command):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import time
|
||||||
import sys
|
import sys
|
||||||
from twisted.application import internet, service
|
from twisted.application import internet, service
|
||||||
from twisted.internet import protocol, reactor, defer
|
from twisted.internet import protocol, reactor, defer
|
||||||
|
from twisted.python import rebuild
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src.config.models import ConfigValue
|
from src.config.models import ConfigValue
|
||||||
|
|
@ -65,15 +66,22 @@ class EvenniaService(service.Service):
|
||||||
cursor.execute("PRAGMA count_changes=OFF")
|
cursor.execute("PRAGMA count_changes=OFF")
|
||||||
cursor.execute("PRAGMA temp_store=2")
|
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):
|
def load_command_table(self):
|
||||||
"""
|
"""
|
||||||
Imports command modules and loads them into the command tables.
|
Imports command modules and loads them into the command tables.
|
||||||
"""
|
"""
|
||||||
# Combine the tuples of command modules to load.
|
# Combine the tuples of command modules to load.
|
||||||
cmd_modules = settings.COMMAND_MODULES +\
|
cmd_modules = self.get_command_modules()
|
||||||
settings.CUSTOM_COMMAND_MODULES +\
|
|
||||||
settings.UNLOGGED_COMMAND_MODULES +\
|
|
||||||
settings.CUSTOM_UNLOGGED_COMMAND_MODULES
|
|
||||||
|
|
||||||
# Import the command modules, which populates the command tables.
|
# Import the command modules, which populates the command tables.
|
||||||
for cmd_mod in cmd_modules:
|
for cmd_mod in cmd_modules:
|
||||||
|
|
@ -87,31 +95,27 @@ class EvenniaService(service.Service):
|
||||||
BEGIN GENERAL METHODS
|
BEGIN GENERAL METHODS
|
||||||
"""
|
"""
|
||||||
def shutdown(self, message='The server has been shutdown. Please check back soon.'):
|
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.announce_all(message)
|
||||||
session_mgr.disconnect_all_sessions()
|
session_mgr.disconnect_all_sessions()
|
||||||
reactor.callLater(0, reactor.stop)
|
reactor.callLater(0, reactor.stop)
|
||||||
|
|
||||||
def command_list(self):
|
def reload(self, source_object=None):
|
||||||
"""
|
|
||||||
Return a string representing the server's command list.
|
|
||||||
"""
|
|
||||||
clist = cmdtable.GLOBAL_CMD_TABLE.ctable.keys()
|
|
||||||
clist.sort()
|
|
||||||
return clist
|
|
||||||
|
|
||||||
def reload(self, session):
|
|
||||||
"""
|
"""
|
||||||
Reload modules that don't have any variables that can be reset.
|
Reload modules that don't have any variables that can be reset.
|
||||||
For changes to the scheduler, server, or session_mgr modules, a cold
|
For changes to the scheduler, server, or session_mgr modules, a cold
|
||||||
restart is needed.
|
restart is needed.
|
||||||
"""
|
"""
|
||||||
reload_list = []
|
cmd_modules = self.get_command_modules()
|
||||||
|
|
||||||
for mod in reload_list:
|
for mod_str, mod in sys.modules.items():
|
||||||
reload(sys.modules[mod])
|
if mod_str in cmd_modules:
|
||||||
|
if source_object:
|
||||||
session.msg("Modules reloaded.")
|
source_object.emit_to(" Reloading %s" % mod_str)
|
||||||
logger.log_infomsg("Modules reloaded by %s." % (session,))
|
rebuild.rebuild(mod)
|
||||||
|
logger.log_infomsg("Modules reloaded by %s." % source_object)
|
||||||
|
|
||||||
def getEvenniaServiceFactory(self):
|
def getEvenniaServiceFactory(self):
|
||||||
f = protocol.ServerFactory()
|
f = protocol.ServerFactory()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue