diff --git a/src/commands/parents.py b/src/commands/parents.py index d03007ba6d..ad086eb0da 100644 --- a/src/commands/parents.py +++ b/src/commands/parents.py @@ -3,22 +3,10 @@ Contains commands for managing script parents. """ from src import scripthandler from src.cmdtable import GLOBAL_CMD_TABLE - -def clear_cached_scripts(command): + +def cmd_scriptcache(command): """ - Show the currently cached scripts. - """ - cache_dict = scripthandler.CACHED_SCRIPTS - cache_size = len(cache_dict) - cache_dict.clear() - command.source_object.emit_to( - "Script parent cached cleared (%d previously in cache)." % cache_size) - -def show_cached_scripts(command): - """ - Clears the cached scripts by deleting their keys from the script cache - dictionary. The next time an object needs the previously loaded scripts, - they are loaded again. + Shows the contents of the script cache. """ cache_dict = scripthandler.CACHED_SCRIPTS @@ -29,21 +17,6 @@ def show_cached_scripts(command): retval += "\n" + "-" * 78 + "\n" retval += "%d cached parents" % len(cache_dict) command.source_object.emit_to(retval) - -def cmd_scriptcache(command): - """ - Figure out what form of the command the user is using and branch off - accordingly. - """ - if "show" in command.command_switches: - show_cached_scripts(command) - return - - if "clear" in command.command_switches: - clear_cached_scripts(command) - return - - command.source_object.emit_to("Must be specified with one of the following switches: show, clear") GLOBAL_CMD_TABLE.add_command("@scriptcache", cmd_scriptcache, priv_tuple=("genperms.builder")) diff --git a/src/commands/privileged.py b/src/commands/privileged.py index 55fdc244aa..1c86422ce2 100644 --- a/src/commands/privileged.py +++ b/src/commands/privileged.py @@ -2,10 +2,12 @@ This file contains commands that require special permissions to use. These are generally @-prefixed commands, but there are exceptions. """ +from django.conf import settings from src.objects.models import Object from src import defines_global from src import ansi from src import session_mgr +from src.scripthandler import rebuild_cache from src.util import functions_general from src.cmdtable import GLOBAL_CMD_TABLE @@ -13,15 +15,33 @@ def cmd_reload(command): """ Reloads all modules. """ - if "aliases" in command.command_switches or "alias" in command.command_switches: + if "all" in command.command_switches: + reload_all = True + else: + reload_all = False + + # Set this to True if a switch match is found. + switch_match_found = False + + if reload_all or "aliases" in command.command_switches or "alias" in command.command_switches: command.session.server.reload_aliases(source_object=command.source_object) command.source_object.emit_to("Aliases reloaded.") - return + switch_match_found = True + + if reload_all or "scripts" in command.command_switches: + rebuild_cache() + command.source_object.emit_to("Script parents reloaded.") + switch_match_found = True - # By default, just reload command objects. - command.source_object.emit_to("Reloading command modules...") - command.session.server.reload(source_object=command.source_object) - command.source_object.emit_to("Modules reloaded.") + if reload_all or "commands" in command.command_switches: + # By default, just reload command objects. + command.source_object.emit_to("Reloading command modules...") + command.session.server.reload(source_object=command.source_object) + command.source_object.emit_to("Modules 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, priv_tuple=("genperms.process_control")), GLOBAL_CMD_TABLE.add_command("@restart", cmd_reload, diff --git a/src/scripthandler.py b/src/scripthandler.py index 30f5a29227..028b4981c2 100644 --- a/src/scripthandler.py +++ b/src/scripthandler.py @@ -6,6 +6,7 @@ interaction with actual script methods should happen via calls to Objects. """ import os from traceback import format_exc +from twisted.python.rebuild import rebuild from django.conf import settings from src import logger @@ -13,6 +14,14 @@ from src import logger # contain references to the associated module for each key. CACHED_SCRIPTS = {} +def rebuild_cache(): + """ + Rebuild all cached scripts. + """ + cache_dict = CACHED_SCRIPTS.items() + for key, val in cache_dict: + rebuild(val) + def scriptlink(source_obj, scriptname): """ Each Object will refer to this function when trying to execute a function