OBS: You need to resync your database! Moved cmdsets into the database rather than being dependent on scripts. Moved the creation of the cmdset- and cmdset-handlers into ObjectDB.__init__ rather than bootstrapping it from the typeclass. Added some more script functionality for testing, includong the @script command for assigning a script to an object.

This commit is contained in:
Griatch 2011-03-20 19:45:56 +00:00
parent e965830735
commit 126e2ea61f
17 changed files with 370 additions and 216 deletions

View file

@ -170,13 +170,13 @@ def create_script(typeclass, key=None, obj=None, locks=None, autostart=True):
new_script = typeclass(new_db_object)
# store variables on the typeclass (which means
# it's actually transparently stored on the db object)
if key:
new_db_object.name = key
else:
if not key:
if typeclass and hasattr(typeclass, '__name__'):
new_db_object.name = "%s" % typeclass.__name__
new_script.key = "%s" % typeclass.__name__
else:
new_db_object.name = "#%i" % new_db_object.id
new_script.key = "#%i" % new_db_object.id
# call the hook method. This is where all at_creation
# customization happens as the typeclass stores custom
@ -184,6 +184,9 @@ def create_script(typeclass, key=None, obj=None, locks=None, autostart=True):
new_script.at_script_creation()
# custom-given variables override the hook
if key:
new_script.key = key
if locks:
new_script.locks.add(locks)
@ -191,12 +194,9 @@ def create_script(typeclass, key=None, obj=None, locks=None, autostart=True):
try:
new_script.obj = obj
except ValueError:
new_script.obj = obj.dbobj
new_script.save()
new_script.obj = obj.dbobj
# a new created script should always be started, so
# we do this now.
# a new created script should usually be started.
if autostart:
new_script.start()

View file

@ -33,11 +33,11 @@ def start_reload_loop():
def run_loop():
""
cemit_info('-'*50)
cemit_info(" Starting asynchronous server reload ...")
cemit_info(" Starting asynchronous server reload.")
reload_modules() # this must be given time to finish
wait_time = 5
cemit_info(" Wait for %ss to give modules time to fully re-cache ..." % wait_time)
cemit_info(" Waiting %ss to give modules time to fully re-cache ..." % wait_time)
time.sleep(wait_time)
reload_scripts()
@ -90,7 +90,7 @@ def reload_modules():
"Check so modpath is not in an unsafe module"
return not any(mpath.startswith(modpath) for mpath in unsafe_modules)
cemit_info("\n Cleaning module caches ...")
cemit_info(" Cleaning module caches ...")
# clean as much of the caches as we can
cache = AppCache()
@ -149,15 +149,15 @@ def reload_scripts(scripts=None, obj=None, key=None,
cleaned out. All persistent scripts are force-started.
"""
cemit_info(" Validating scripts ...")
nr_started, nr_stopped = ScriptDB.objects.validate(scripts=scripts,
obj=obj, key=key,
dbref=dbref,
init_mode=init_mode)
string = " Started %s script(s). Stopped %s invalid script(s)." % \
(nr_started, nr_stopped)
cemit_info(string)
if nr_started or nr_stopped:
string = " Started %s script(s). Stopped %s invalid script(s)." % \
(nr_started, nr_stopped)
cemit_info(string)
def reload_commands():
from src.commands import cmdsethandler
@ -170,12 +170,13 @@ def reset_loop():
cemit_info(" Running resets on database entities ...")
t1 = time.time()
[s.locks.reset() for s in ScriptDB.objects.all()]
[p.locks.reset() for p in PlayerDB.objects.all()]
[h.locks.reset() for h in HelpEntry.objects.all()]
[m.locks.reset() for m in Msg.objects.all()]
[c.locks.reset() for c in Channel.objects.all()]
[s.locks.reset() for s in ScriptDB.objects.all()]
[p.locks.reset() for p in PlayerDB.objects.all()]
[(o.typeclass(o), o.cmdset.reset(), o.locks.reset()) for o in ObjectDB.get_all_cached_instances()]
t2 = time.time()
cemit_info(" ... Loop finished in %g seconds." % (t2-t1))