From bafd069d970d481e8f4663955bad2d8ed5827ce8 Mon Sep 17 00:00:00 2001 From: Tehom Date: Fri, 28 Jul 2017 01:26:00 -0400 Subject: [PATCH 1/2] Create fallback for default cmdsets that fail to load --- evennia/commands/cmdsethandler.py | 8 ++++++++ evennia/settings_default.py | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/evennia/commands/cmdsethandler.py b/evennia/commands/cmdsethandler.py index 3f01dbcac2..2042588683 100644 --- a/evennia/commands/cmdsethandler.py +++ b/evennia/commands/cmdsethandler.py @@ -351,6 +351,14 @@ class CmdSetHandler(object): elif path: cmdset = self._import_cmdset(path) if cmdset: + if cmdset.key == '_CMDSET_ERROR': + # If a cmdset fails to load, check if we have a fallback path to use + fallback_path = settings.CMDSET_FALLBACKS.get(path, None) + if fallback_path: + cmdset = self._import_cmdset(fallback_path) + # If no cmdset is returned from the fallback, we can't go further + if not cmdset: + continue cmdset.permanent = cmdset.key != '_CMDSET_ERROR' self.cmdset_stack.append(cmdset) diff --git a/evennia/settings_default.py b/evennia/settings_default.py index f94bf5d3ef..cc90972f16 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -348,6 +348,12 @@ CMDSET_CHARACTER = "commands.default_cmdsets.CharacterCmdSet" CMDSET_PLAYER = "commands.default_cmdsets.PlayerCmdSet" # Location to search for cmdsets if full path not given CMDSET_PATHS = ["commands", "evennia", "contribs"] +# Fallbacks for cmdset paths that fail to load. Note that if you change the path for your default cmdsets, +# you will also need to copy CMDSET_FALLBACKS after your change in your settings file for it to detect the change. +CMDSET_FALLBACKS = {CMDSET_CHARACTER: 'evennia.commands.default.cmdset_character.CharacterCmdSet', + CMDSET_PLAYER: 'evennia.commands.default.cmdset_player.PlayerCmdSet', + CMDSET_SESSION: 'evennia.commands.default.cmdset_session.SessionCmdSet', + CMDSET_UNLOGGEDIN: 'evennia.commands.default.cmdset_unloggedin.UnloggedinCmdSet'} # Parent class for all default commands. Changing this class will # modify all default commands, so do so carefully. COMMAND_DEFAULT_CLASS = "evennia.commands.default.muxcommand.MuxCommand" From 72a91ebce6b947ab2ab83729a43a0d2640eac2b4 Mon Sep 17 00:00:00 2001 From: Tehom Date: Tue, 8 Aug 2017 20:46:48 -0400 Subject: [PATCH 2/2] Add logging for fallback. --- evennia/commands/cmdsethandler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/evennia/commands/cmdsethandler.py b/evennia/commands/cmdsethandler.py index 2042588683..3ecbd8bd36 100644 --- a/evennia/commands/cmdsethandler.py +++ b/evennia/commands/cmdsethandler.py @@ -355,9 +355,12 @@ class CmdSetHandler(object): # If a cmdset fails to load, check if we have a fallback path to use fallback_path = settings.CMDSET_FALLBACKS.get(path, None) if fallback_path: + logger.log_err("Error encountered for cmdset at path %s. Replacing with: %s" % ( + path, fallback_path)) cmdset = self._import_cmdset(fallback_path) # If no cmdset is returned from the fallback, we can't go further if not cmdset: + logger.log_err("Fallback path '%s' failed to generate a cmdset." % fallback_path) continue cmdset.permanent = cmdset.key != '_CMDSET_ERROR' self.cmdset_stack.append(cmdset)