Added info from @reload (Issue 70) and @service (Issue 71) to MUDInfo channel.

@reload only adds full info to the logger; normally just brief info to game unless
there is a traceback.
This commit is contained in:
Griatch 2009-08-30 15:35:29 +00:00
parent 811bdc623f
commit cb7ee081f5
3 changed files with 69 additions and 58 deletions

View file

@ -7,6 +7,7 @@ from src.objects.models import Object
from src import defines_global from src import defines_global
from src import ansi from src import ansi
from src import session_mgr from src import session_mgr
from src import comsys
from src.scripthandler import rebuild_cache from src.scripthandler import rebuild_cache
from src.util import functions_general from src.util import functions_general
from src.cmdtable import GLOBAL_CMD_TABLE from src.cmdtable import GLOBAL_CMD_TABLE
@ -15,33 +16,30 @@ def cmd_reload(command):
""" """
Reloads all modules. Reloads all modules.
""" """
if "all" in command.command_switches: source_object = command.source_object
reload_all = True switches = command.command_switches
else: if not switches or switches[0] not in ['all','aliases','alias',
reload_all = False 'commands','command',
'scripts','parents']:
# Set this to True if a switch match is found. source_object.emit_to("Usage: @reload/<aliases|scripts|commands|all>")
switch_match_found = False return
switch = switches[0]
if reload_all or "aliases" in command.command_switches or "alias" in command.command_switches: sname = source_object.get_name(show_dbref=False)
command.session.server.reload_aliases(source_object=command.source_object)
command.source_object.emit_to("Aliases reloaded.")
switch_match_found = True
if reload_all or "scripts" in command.command_switches: if switch in ["all","aliases","alias"]:
#reload Aliases
command.session.server.reload_aliases(source_object=source_object)
comsys.cemit_mudinfo("%s reloaded Aliases." % sname)
if switch in ["all","scripts","parents"]:
#reload Script parents
rebuild_cache() rebuild_cache()
command.source_object.emit_to("Script parents reloaded.") comsys.cemit_mudinfo("%s reloaded Script parents." % sname)
switch_match_found = True if switch in ["all","commands","command"]:
#reload command objects.
if reload_all or "commands" in command.command_switches: comsys.cemit_mudinfo("%s is reloading Command modules ..." % sname)
# By default, just reload command objects.
command.source_object.emit_to("Reloading command modules...")
command.session.server.reload(source_object=command.source_object) command.session.server.reload(source_object=command.source_object)
command.source_object.emit_to("Modules reloaded.") comsys.cemit_mudinfo("... all Command modules were reloaded.")
switch_match_found = True
if not switch_match_found:
command.source_object.emit_to("@reload must be accompanied by one or more of the following switches: aliases, scripts, commands, all")
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, GLOBAL_CMD_TABLE.add_command("@restart", cmd_reload,
@ -176,63 +174,70 @@ def cmd_service(command):
Service management system. Allows for the listing, starting, and stopping Service management system. Allows for the listing, starting, and stopping
of services. of services.
""" """
pobject = command.source_object source_object = command.source_object
if "list" in command.command_switches: switches = command.command_switches
""" if not switches or switches[0] not in ["list","start","stop"]:
Just display the list of installed services and their status and die. source_object.emit_to("Usage @servive/<start|stop|list> [service]")
""" return
pobject.emit_to('-' * 40) switch = switches[0].strip()
pobject.emit_to('Service Listing') sname = source_object.get_name(show_dbref=False)
if switch == "list":
#Just display the list of installed services and their status, then exit.
s = "-" * 40
s += "\nService Listing"
for service in command.session.server.service_collection.services: for service in command.session.server.service_collection.services:
# running is either 1 or 0, 1 meaning the service is running. # running is either 1 or 0, 1 meaning the service is running.
if service.running == 1: if service.running == 1:
status = 'Running' status = 'Running'
else: else:
status = 'Inactive' status = 'Inactive'
pobject.emit_to(' * %s (%s)' % (service.name, status)) s += '\n * %s (%s)' % (service.name, status)
pobject.emit_to('-' * 40) s += "\n" + "-" * 40
source_object.emit_to(s)
return return
# This stuff is common to both start and stop switches. if switch in ["stop", "start"]:
if "stop" in command.command_switches or "start" in command.command_switches: # This stuff is common to both start and stop switches.
collection = command.session.server.service_collection collection = command.session.server.service_collection
try: try:
service = collection.getServiceNamed(command.command_argument) service = collection.getServiceNamed(command.command_argument)
except: except:
pobject.emit_to('Invalid service name. This command is case-sensitive. See @service/list.') source_object.emit_to('Invalid service name. This command is case-sensitive. See @service/list.')
return return
if "stop" in command.command_switches: if switch == "stop":
""" """
Stopping a service gracefully closes it and disconnects any connections Stopping a service gracefully closes it and disconnects any connections
(if applicable). (if applicable).
""" """
if service.running == 0: if service.running == 0:
pobject.emit_to('That service is not currently running.') source_object.emit_to('That service is not currently running.')
return return
# We don't want them killing main Evennia TCPServer services here. If # We don't want killing main Evennia TCPServer services here. If
# they'd like to nix a listening port, they need to do it through # wanting to kill a listening port, one needs to do it through
# settings.py and a restart. # settings.py and a restart.
if service.name[:7] == 'Evennia': if service.name[:7] == 'Evennia':
pobject.emit_to('You can not Evennia TCPServer services this way.') s = "You can not stop Evennia TCPServer services this way."
return s += "\nTo e.g. remove a listening port, change settings file and restart."
pobject.emit_to('Stopping the %s service.' % service.name) source_object.emit_to(s)
return
comsys.cemit_mudinfo("%s is *Stopping* the service '%s'." % (sname, service.name))
service.stopService() service.stopService()
return return
if "start" in command.command_switches: if switch == "start":
""" """
Starts a service. Starts a service.
""" """
if service.running == 1: if service.running == 1:
pobject.emit_to('That service is already running.') source_object.emit_to('That service is already running.')
return return
pobject.emit_to('Starting the %s service.' % service.name) comsys.cemit_mudinfo("%s is *Starting* the service '%s'." % (sname,service.name))
service.startService() service.startService()
return return
# If they don't provide any switches, let them know to do so.
pobject.emit_to("You must specify a switch with @service. May be one of: list, start, stop")
GLOBAL_CMD_TABLE.add_command("@service", cmd_service, GLOBAL_CMD_TABLE.add_command("@service", cmd_service,
priv_tuple=("genperms.process_control")) priv_tuple=("genperms.process_control"))
@ -244,4 +249,4 @@ def cmd_shutdown(command):
print 'Server shutdown by %s' % (command.source_object.get_name(show_dbref=False),) print 'Server shutdown by %s' % (command.source_object.get_name(show_dbref=False),)
command.session.server.shutdown() command.session.server.shutdown()
GLOBAL_CMD_TABLE.add_command("@shutdown", cmd_shutdown, GLOBAL_CMD_TABLE.add_command("@shutdown", cmd_shutdown,
priv_tuple=("genperms.process_control")) priv_tuple=("genperms.process_control"))

View file

@ -310,8 +310,10 @@ def cname_search(search_text, exact=False):
else: else:
return CommChannel.objects.filter(name__istartswith=search_text) return CommChannel.objects.filter(name__istartswith=search_text)
def cemit_mudinfo(message):
"Send to mud info channel This is "
send_cmessage(settings.COMMCHAN_MUD_INFO,
'Info: %s' % message)
def send_cexternal(cname, cmessage, from_external=None): def send_cexternal(cname, cmessage, from_external=None):
""" """

View file

@ -9,6 +9,7 @@ from src.config.models import ConfigValue
from src.session import SessionProtocol from src.session import SessionProtocol
from src import events from src import events
from src import logger from src import logger
from src import comsys
from src import session_mgr from src import session_mgr
from src import alias_mgr from src import alias_mgr
from src import cmdtable from src import cmdtable
@ -111,14 +112,17 @@ class EvenniaService(service.Service):
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.
""" """
cmd_modules = self.get_command_modules() cmd_modules = self.get_command_modules()
s = []
for mod_str, mod in sys.modules.items(): for mod_str, mod in sys.modules.items():
if mod_str in cmd_modules: if mod_str in cmd_modules:
if source_object: s.append(mod_str)
source_object.emit_to(" Reloading %s" % mod_str) try:
rebuild.rebuild(mod) rebuild.rebuild(mod)
logger.log_infomsg("Modules reloaded by %s." % source_object) except:
comsys.cemit_mudinfo("... Error reloading %s!" % mod_str)
raise
logger.log_infomsg("%s reloaded %i modules: %s" % (source_object, len(s), s))
def reload_aliases(self, source_object=None): def reload_aliases(self, source_object=None):
""" """