mirror of
https://github.com/evennia/evennia.git
synced 2026-04-02 14:07:16 +02:00
@scriptcache is now just for displaying the contents of the script cache. After changing a script parent, you may now @reload/script to apply any changes. @reload with no arguments will now show you all of the possible switches. Also added an 'all' switch that will reload everything in one fell swoop.
This commit is contained in:
parent
ffa03309fc
commit
2cc3d98810
3 changed files with 38 additions and 36 deletions
|
|
@ -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"))
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue