Made scripts and typeclassed objects remember db_typeclass_path at all times - a temporarily faulty typeclass will no longer mess up things forever after. Refined and optimized the way typeclasses are cached and loaded, minimizing db hits. The default result when trying to create an object or script with a typeclass that is faulty/not found is now to fail. The previous way, to create an entity anyway using defaults was hard to debug and caused confusion. Resolves issue 175.

This commit is contained in:
Griatch 2011-08-06 18:15:04 +00:00
parent 6cb2b8b745
commit ddfd8120bb
10 changed files with 208 additions and 173 deletions

View file

@ -253,3 +253,15 @@ class ScriptDB(TypedObject):
default_typeclass_path = settings.DEFAULT_SCRIPT_TYPECLASS
except:
default_typeclass_path = "src.scripts.scripts.DoNothing"
def at_typeclass_error(self):
"""
If this is called, it means the typeclass has a critical
error and cannot even be loaded. We don't allow a script
to be created under those circumstances. Already created,
permanent scripts are set to already be active so they
won't get activated now (next reboot the bug might be fixed)
"""
# By setting is_active=True, we trick the script not to run "again".
self.is_active = True
return super(ScriptDB, self).at_typeclass_error()

View file

@ -54,10 +54,10 @@ class ScriptHandler(object):
or a python path to such a class object.
key - optional identifier for the script (often set in script definition)
autostart - start the script upon adding it
"""
"""
script = create.create_script(scriptclass, key=key, obj=self.obj, autostart=autostart)
if not script:
logger.log_errmsg("Script %s failed to be created/start." % scriptclass)
logger.log_errmsg("Script %s could not be created and/or started." % scriptclass)
return False
return True

View file

@ -378,11 +378,11 @@ class Script(ScriptClass):
# Some useful default Script types used by Evennia.
class DoNothing(Script):
"An script that does nothing. Used as default."
"An script that does nothing. Used as default fallback."
def at_script_creation(self):
"Setup the script"
self.key = "sys_do_nothing"
self.desc = "This does nothing."
self.desc = "This is a placeholder script."
class CheckSessions(Script):
"Check sessions regularly."