<s> """<STR_LIT>""" <EOL> from django . db . models import Q <EOL> from evennia . typeclasses . managers import TypedObjectManager , TypeclassManager <EOL> from evennia . typeclasses . managers import returns_typeclass_list <EOL> from evennia . utils . utils import make_iter <EOL> __all__ = ( "<STR_LIT>" , ) <EOL> _GA = object . __getattribute__ <EOL> VALIDATE_ITERATION = <NUM_LIT:0> <EOL> class ScriptDBManager ( TypedObjectManager ) : <EOL> """<STR_LIT>""" <EOL> @ returns_typeclass_list <EOL> def get_all_scripts_on_obj ( self , obj , key = None ) : <EOL> """<STR_LIT>""" <EOL> if not obj : <EOL> return [ ] <EOL> player = _GA ( _GA ( obj , "<STR_LIT>" ) , "<STR_LIT>" ) == "<STR_LIT>" <EOL> if key : <EOL> dbref = self . dbref ( key ) <EOL> if dbref or dbref == <NUM_LIT:0> : <EOL> if player : <EOL> return self . filter ( db_player = obj , id = dbref ) <EOL> else : <EOL> return self . filter ( db_obj = obj , id = dbref ) <EOL> elif player : <EOL> return self . filter ( db_player = obj , db_key = key ) <EOL> else : <EOL> return self . filter ( db_obj = obj , db_key = key ) <EOL> elif player : <EOL> return self . filter ( db_player = obj ) <EOL> else : <EOL> return self . filter ( db_obj = obj ) <EOL> @ returns_typeclass_list <EOL> def get_all_scripts ( self , key = None ) : <EOL> """<STR_LIT>""" <EOL> if key : <EOL> script = [ ] <EOL> dbref = self . dbref ( key ) <EOL> if dbref or dbref == <NUM_LIT:0> : <EOL> script = [ self . dbref_search ( dbref ) ] <EOL> if not script : <EOL> script = self . filter ( db_key = key ) <EOL> return script <EOL> return self . all ( ) <EOL> def delete_script ( self , dbref ) : <EOL> """<STR_LIT>""" <EOL> scripts = self . get_id ( dbref ) <EOL> for script in make_iter ( scripts ) : <EOL> script . stop ( ) <EOL> def remove_non_persistent ( self , obj = None ) : <EOL> """<STR_LIT>""" <EOL> if obj : <EOL> to_stop = self . filter ( db_obj = obj , db_persistent = False , db_is_active = True ) <EOL> to_delete = self . filter ( db_obj = obj , db_persistent = False , db_is_active = False ) <EOL> else : <EOL> to_stop = self . filter ( db_persistent = False , db_is_active = True ) <EOL> to_delete = self . filter ( db_persistent = False , db_is_active = False ) <EOL> nr_deleted = to_stop . count ( ) + to_delete . count ( ) <EOL> for script in to_stop : <EOL> script . stop ( ) <EOL> for script in to_delete : <EOL> script . delete ( ) <EOL> return nr_deleted <EOL> def validate ( self , scripts = None , obj = None , key = None , dbref = None , <EOL> init_mode = False ) : <EOL> """<STR_LIT>""" <EOL> global VALIDATE_ITERATION <EOL> if VALIDATE_ITERATION > <NUM_LIT:0> : <EOL> VALIDATE_ITERATION -= <NUM_LIT:1> <EOL> return None , None <EOL> VALIDATE_ITERATION += <NUM_LIT:1> <EOL> nr_started = <NUM_LIT:0> <EOL> nr_stopped = <NUM_LIT:0> <EOL> if init_mode : <EOL> if init_mode == '<STR_LIT>' : <EOL> nr_stopped += self . remove_non_persistent ( obj = obj ) <EOL> scripts = self . get_all_scripts ( ) <EOL> for script in scripts : <EOL> script . is_active = False <EOL> elif not scripts : <EOL> if dbref and self . dbref ( dbref , reqhash = False ) : <EOL> scripts = self . get_id ( dbref ) <EOL> elif obj : <EOL> scripts = self . get_all_scripts_on_obj ( obj , key = key ) <EOL> else : <EOL> scripts = self . get_all_scripts ( key = key ) <EOL> if not scripts : <EOL> VALIDATE_ITERATION -= <NUM_LIT:1> <EOL> return None , None <EOL> for script in scripts : <EOL> if script . is_valid ( ) : <EOL> nr_started += script . start ( force_restart = init_mode ) <EOL> else : <EOL> script . stop ( ) <EOL> nr_stopped += <NUM_LIT:1> <EOL> VALIDATE_ITERATION -= <NUM_LIT:1> <EOL> return nr_started , nr_stopped <EOL> @ returns_typeclass_list <EOL> def script_search ( self , ostring , obj = None , only_timed = False ) : <EOL> """<STR_LIT>""" <EOL> ostring = ostring . strip ( ) <EOL> dbref = self . dbref ( ostring ) <EOL> if dbref or dbref == <NUM_LIT:0> : <EOL> dbref_match = self . dbref_search ( dbref ) <EOL> if dbref_match and not ( ( obj and obj != dbref_match . obj ) <EOL> or ( only_timed and dbref_match . interval ) ) : <EOL> return [ dbref_match ] <EOL> obj_restriction = obj and Q ( db_obj = obj ) or Q ( ) <EOL> timed_restriction = only_timed and Q ( interval__gt = <NUM_LIT:0> ) or Q ( ) <EOL> scripts = self . filter ( timed_restriction & obj_restriction & Q ( db_key__iexact = ostring ) ) <EOL> return scripts <EOL> def copy_script ( self , original_script , new_key = None , new_obj = None , new_locks = None ) : <EOL> """<STR_LIT>""" <EOL> typeclass = original_script . typeclass_path <EOL> new_key = new_key if new_key is not None else original_script . key <EOL> new_obj = new_obj if new_obj is not None else original_script . obj <EOL> new_locks = new_locks if new_locks is not None else original_script . db_lock_storage <EOL> from evennia . utils import create <EOL> new_script = create . create_script ( typeclass , key = new_key , obj = new_obj , <EOL> locks = new_locks , autostart = True ) <EOL> return new_script <EOL> class ScriptManager ( ScriptDBManager , TypeclassManager ) : <EOL> pass </s>
