mirror of
https://github.com/evennia/evennia.git
synced 2026-03-29 03:57:17 +02:00
Added settings.CMDSET_PATHS to allow to give cmdsets without the full path.
This commit is contained in:
parent
63c099c22f
commit
3be02c8f03
1 changed files with 14 additions and 12 deletions
|
|
@ -63,6 +63,7 @@ can then implement separate sets for different situations. For
|
|||
example, you can have a 'On a boat' set, onto which you then tack on
|
||||
the 'Fishing' set. Fishing from a boat? No problem!
|
||||
"""
|
||||
from django.conf import settings
|
||||
from src.utils import logger, utils
|
||||
from src.commands.cmdset import CmdSet
|
||||
from src.server.models import ServerConfig
|
||||
|
|
@ -71,7 +72,7 @@ from django.utils.translation import ugettext as _
|
|||
__all__ = ("import_cmdset", "CmdSetHandler")
|
||||
|
||||
_CACHED_CMDSETS = {}
|
||||
|
||||
_CMDSET_PATHS = utils.make_iter(settings.CMDSET_PATHS)
|
||||
|
||||
class _ErrorCmdSet(CmdSet):
|
||||
"This is a special cmdset used to report errors"
|
||||
|
|
@ -84,12 +85,12 @@ class _EmptyCmdSet(CmdSet):
|
|||
priority = -101
|
||||
mergetype = "Union"
|
||||
|
||||
def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
||||
def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
||||
"""
|
||||
This helper function is used by the cmdsethandler to load a cmdset
|
||||
instance from a python module, given a python_path. It's usually accessed
|
||||
through the cmdsethandler's add() and add_default() methods.
|
||||
python_path - This is the full path to the cmdset object.
|
||||
path - This is the full path to the cmdset object on python dot-form
|
||||
cmdsetobj - the database object/typeclass on which this cmdset is to be
|
||||
assigned (this can be also channels and exits, as well as players
|
||||
but there will always be such an object)
|
||||
|
|
@ -101,7 +102,10 @@ def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
|||
function returns None if an error was encountered or path not found.
|
||||
"""
|
||||
|
||||
try:
|
||||
python_paths = [path] + ["%s.%s" % (prefix, path)
|
||||
for prefix in _CMDSET_PATHS]
|
||||
errstring = ""
|
||||
for python_path in python_paths:
|
||||
try:
|
||||
#print "importing %s: _CACHED_CMDSETS=%s" % (python_path, _CACHED_CMDSETS)
|
||||
wanted_cache_key = python_path
|
||||
|
|
@ -120,22 +124,20 @@ def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
|||
return cmdsetclass
|
||||
|
||||
except ImportError:
|
||||
errstring = _("Error loading cmdset: Couldn't import module '%s'.")
|
||||
errstring += _("Error loading cmdset: Couldn't import module '%s'.")
|
||||
errstring = errstring % modulepath
|
||||
raise
|
||||
except KeyError:
|
||||
errstring = _("Error in loading cmdset: No cmdset class '%(classname)s' in %(modulepath)s.")
|
||||
errstring += _("Error in loading cmdset: No cmdset class '%(classname)s' in %(modulepath)s.")
|
||||
errstring = errstring % {"classname": classname,
|
||||
"modulepath": modulepath}
|
||||
raise
|
||||
except Exception:
|
||||
errstring = _("Compile/Run error when loading cmdset '%s'. Error was logged.")
|
||||
errstring += _("Compile/Run error when loading cmdset '%s'. Error was logged.")
|
||||
errstring = errstring % (python_path)
|
||||
raise
|
||||
except Exception:
|
||||
|
||||
if errstring:
|
||||
# returning an empty error cmdset
|
||||
if not no_logging:
|
||||
logger.log_trace(errstring)
|
||||
logger.log_errmsg(errstring)
|
||||
if emit_to_obj and not ServerConfig.objects.conf("server_starting_mode"):
|
||||
emit_to_obj.msg(errstring)
|
||||
err_cmdset = _ErrorCmdSet()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue