Пример #1
0
    def update_defaults(self):
        """
        We make sure to store the most important object defaults here, so
        we can catch if they change and update them on-objects automatically.
        This allows for changing default cmdset locations and default
        typeclasses in the settings file and have them auto-update all
        already existing objects.
        """
        # setting names
        settings_names = (
            "CMDSET_CHARACTER",
            "CMDSET_PLAYER",
            "BASE_PLAYER_TYPECLASS",
            "BASE_OBJECT_TYPECLASS",
            "BASE_CHARACTER_TYPECLASS",
            "BASE_ROOM_TYPECLASS",
            "BASE_EXIT_TYPECLASS",
            "BASE_SCRIPT_TYPECLASS",
            "BASE_CHANNEL_TYPECLASS",
        )
        # get previous and current settings so they can be compared
        settings_compare = zip(
            [ServerConfig.objects.conf(name) for name in settings_names],
            [settings.__getattr__(name) for name in settings_names],
        )
        mismatches = [i for i, tup in enumerate(settings_compare) if tup[0] and tup[1] and tup[0] != tup[1]]
        if len(mismatches):  # can't use any() since mismatches may be [0] which reads as False for any()
            # we have a changed default. Import relevant objects and
            # run the update
            from evennia.objects.models import ObjectDB
            from evennia.comms.models import ChannelDB

            # from evennia.players.models import PlayerDB
            for i, prev, curr in ((i, tup[0], tup[1]) for i, tup in enumerate(settings_compare) if i in mismatches):
                # update the database
                print(
                    " %s:\n '%s' changed to '%s'. Updating unchanged entries in database ..."
                    % (settings_names[i], prev, curr)
                )
                if i == 0:
                    ObjectDB.objects.filter(db_cmdset_storage__exact=prev).update(db_cmdset_storage=curr)
                if i == 1:
                    PlayerDB.objects.filter(db_cmdset_storage__exact=prev).update(db_cmdset_storage=curr)
                if i == 2:
                    PlayerDB.objects.filter(db_typeclass_path__exact=prev).update(db_typeclass_path=curr)
                if i in (3, 4, 5, 6):
                    ObjectDB.objects.filter(db_typeclass_path__exact=prev).update(db_typeclass_path=curr)
                if i == 7:
                    ScriptDB.objects.filter(db_typeclass_path__exact=prev).update(db_typeclass_path=curr)
                if i == 8:
                    ChannelDB.objects.filter(db_typeclass_path__exact=prev).update(db_typeclass_path=curr)
                # store the new default and clean caches
                ServerConfig.objects.conf(settings_names[i], curr)
                ObjectDB.flush_instance_cache()
                PlayerDB.flush_instance_cache()
                ScriptDB.flush_instance_cache()
                ChannelDB.flush_instance_cache()
        # if this is the first start we might not have a "previous"
        # setup saved. Store it now.
        [ServerConfig.objects.conf(settings_names[i], tup[1]) for i, tup in enumerate(settings_compare) if not tup[0]]
Пример #2
0
 def update_defaults(self):
     """
     We make sure to store the most important object defaults here, so
     we can catch if they change and update them on-objects automatically.
     This allows for changing default cmdset locations and default
     typeclasses in the settings file and have them auto-update all
     already existing objects.
     """
     # setting names
     settings_names = ("CMDSET_CHARACTER", "CMDSET_PLAYER",
                       "BASE_PLAYER_TYPECLASS", "BASE_OBJECT_TYPECLASS",
                       "BASE_CHARACTER_TYPECLASS", "BASE_ROOM_TYPECLASS",
                       "BASE_EXIT_TYPECLASS", "BASE_SCRIPT_TYPECLASS",
                       "BASE_CHANNEL_TYPECLASS")
     # get previous and current settings so they can be compared
     settings_compare = zip([ServerConfig.objects.conf(name) for name in settings_names],
                            [settings.__getattr__(name) for name in settings_names])
     mismatches = [i for i, tup in enumerate(settings_compare) if tup[0] and tup[1] and tup[0] != tup[1]]
     if len(mismatches):  # can't use any() since mismatches may be [0] which reads as False for any()
         # we have a changed default. Import relevant objects and
         # run the update
         from evennia.objects.models import ObjectDB
         from evennia.comms.models import ChannelDB
         #from evennia.players.models import PlayerDB
         for i, prev, curr in ((i, tup[0], tup[1]) for i, tup in enumerate(settings_compare) if i in mismatches):
             # update the database
             print(" %s:\n '%s' changed to '%s'. Updating unchanged entries in database ..." % (settings_names[i], prev, curr))
             if i == 0:
                 ObjectDB.objects.filter(db_cmdset_storage__exact=prev).update(db_cmdset_storage=curr)
             if i == 1:
                 PlayerDB.objects.filter(db_cmdset_storage__exact=prev).update(db_cmdset_storage=curr)
             if i == 2:
                 PlayerDB.objects.filter(db_typeclass_path__exact=prev).update(db_typeclass_path=curr)
             if i in (3, 4, 5, 6):
                 ObjectDB.objects.filter(db_typeclass_path__exact=prev).update(db_typeclass_path=curr)
             if i == 7:
                 ScriptDB.objects.filter(db_typeclass_path__exact=prev).update(db_typeclass_path=curr)
             if i == 8:
                 ChannelDB.objects.filter(db_typeclass_path__exact=prev).update(db_typeclass_path=curr)
             # store the new default and clean caches
             ServerConfig.objects.conf(settings_names[i], curr)
             ObjectDB.flush_instance_cache()
             PlayerDB.flush_instance_cache()
             ScriptDB.flush_instance_cache()
             ChannelDB.flush_instance_cache()
     # if this is the first start we might not have a "previous"
     # setup saved. Store it now.
     [ServerConfig.objects.conf(settings_names[i], tup[1])
                     for i, tup in enumerate(settings_compare) if not tup[0]]