示例#1
0
                object_record = object_model.objects.get(key=record.key)
                typeclass_path = TYPECLASS_SET.get_module(
                    object_record.typeclass)
                obj = create.create_object(typeclass_path, object_record.name)
                count_create += 1
            except Exception, e:
                ostring = "Can not create obj %s: %s" % (record.key, e)
                print(ostring)
                print(traceback.print_exc())
                if caller:
                    caller.msg(ostring)
                continue

            try:
                obj.set_data_key(record.key, getattr(record, "level", 0))
                utils.set_obj_unique_type(obj, type_name)
            except Exception, e:
                ostring = "Can not set data info to obj %s: %s" % (record.key,
                                                                   e)
                print(ostring)
                print(traceback.print_exc())
                if caller:
                    caller.msg(ostring)
                continue

    ostring = "Removed %d object(s). Created %d object(s). Updated %d object(s). Total %d objects.\n"\
              % (count_remove, count_create, count_update, len(objects_data))
    print(ostring)
    if caller:
        caller.msg(ostring)
示例#2
0
文件: builder.py 项目: cn591/muddery
            try:
                typeclass = model_typeclass.objects.get(key=record.typeclass)
                obj = create.create_object(typeclass.path, record.name)
                count_create += 1
            except Exception, e:
                ostring = "Can not create obj %s: %s" % (record.key, e)
                print(ostring)
                print(traceback.print_exc())
                if caller:
                    caller.msg(ostring)
                continue

            try:
                obj.set_data_key(record.key)
                utils.set_obj_unique_type(obj, model_name)
            except Exception, e:
                ostring = "Can not set data info to obj %s: %s" % (record.key,
                                                                   e)
                print(ostring)
                print(traceback.print_exc())
                if caller:
                    caller.msg(ostring)
                continue

    ostring = "Removed %d object(s). Created %d object(s). Updated %d object(s). Total %d objects.\n"\
              % (count_remove, count_create, count_update, len(model_obj.objects.all()))
    print(ostring)
    if caller:
        caller.msg(ostring)
示例#3
0
def build_unique_objects(objects_data, type_name, caller=None):
    """
    Build all objects in a model.

    Args:
        model_name: (string) The name of the data model.
        caller: (command caller) If provide, running messages will send to the caller.
    """
    # new objects
    new_obj_keys = set(record.key for record in objects_data)

    # current objects
    current_objs = utils.search_obj_unique_type(type_name)

    # remove objects
    count_remove = 0
    count_update = 0
    count_create = 0
    current_obj_keys = set()

    for obj in current_objs:
        obj_key = obj.get_data_key()

        if obj_key in current_obj_keys:
            # This object is duplcated.
            ostring = "Deleting %s" % obj_key
            print(ostring)
            if caller:
                caller.msg(ostring)

            # If default home will be removed, set default home to the Limbo.
            if obj.dbref == settings.DEFAULT_HOME:
                settings.DEFAULT_HOME = "#2"
            obj.delete()
            count_remove += 1
            continue

        if not obj_key in new_obj_keys:
            # This object should be removed
            ostring = "Deleting %s" % obj_key
            print(ostring)
            if caller:
                caller.msg(ostring)

            # If default home will be removed, set default home to the Limbo.
            if obj.dbref == settings.DEFAULT_HOME:
                settings.DEFAULT_HOME = "#2"
            obj.delete()
            count_remove += 1
            continue

        try:
            # set data
            obj.load_data()
            # put obj to its default location
            obj.reset_location()
        except Exception as e:
            ostring = "%s can not load data:%s" % (obj.dbref, e)
            print(ostring)
            print(traceback.print_exc())
            if caller:
                caller.msg(ostring)

        current_obj_keys.add(obj_key)

    # Create new objects.
    object_model_name = TYPECLASS("OBJECT").model_name
    object_model = apps.get_model(settings.WORLD_DATA_APP, object_model_name)
    for record in objects_data:
        if not record.key in current_obj_keys:
            # Create new objects.
            ostring = "Creating %s." % record.key
            print(ostring)
            if caller:
                caller.msg(ostring)

            try:
                object_record = object_model.objects.get(key=record.key)
                typeclass_path = TYPECLASS_SET.get_module(
                    object_record.typeclass)
                obj = create.create_object(typeclass_path, object_record.name)
                count_create += 1
            except Exception as e:
                ostring = "Can not create obj %s: %s" % (record.key, e)
                print(ostring)
                print(traceback.print_exc())
                if caller:
                    caller.msg(ostring)
                continue

            try:
                obj.set_data_key(record.key)
                utils.set_obj_unique_type(obj, type_name)
            except Exception as e:
                ostring = "Can not set data info to obj %s: %s" % (record.key,
                                                                   e)
                print(ostring)
                print(traceback.print_exc())
                if caller:
                    caller.msg(ostring)
                continue

    ostring = "Removed %d object(s). Created %d object(s). Updated %d object(s). Total %d objects.\n"\
              % (count_remove, count_create, count_update, len(objects_data))
    print(ostring)
    if caller:
        caller.msg(ostring)
示例#4
0
                caller.msg(ostring)

            try:
                obj = create.create_object(record.typeclass.path, record.name)
                count_create += 1
            except Exception, e:
                ostring = "Can not create obj %s: %s" % (record.key, e)
                print(ostring)
                print(traceback.print_exc())
                if caller:
                    caller.msg(ostring)
                continue

            try:
                obj.set_data_key(record.key)
                utils.set_obj_unique_type(obj, model_name)
            except Exception, e:
                ostring = "Can not set data info to obj %s: %s" % (record.key, e)
                print(ostring)
                print(traceback.print_exc())
                if caller:
                    caller.msg(ostring)
                continue

    ostring = "Removed %d object(s). Created %d object(s). Updated %d object(s). Total %d objects.\n"\
              % (count_remove, count_create, count_update, len(model_obj.objects.all()))
    print(ostring)
    if caller:
        caller.msg(ostring)

示例#5
0
            try:
                typeclass = typeclass_objects.get(key=record.typeclass)
                obj = create.create_object(typeclass.path, record.name)
                count_create += 1
            except Exception, e:
                ostring = "Can not create obj %s: %s" % (record.key, e)
                print(ostring)
                print(traceback.print_exc())
                if caller:
                    caller.msg(ostring)
                continue

            try:
                obj.set_data_key(record.key)
                utils.set_obj_unique_type(obj, type_name)
            except Exception, e:
                ostring = "Can not set data info to obj %s: %s" % (record.key, e)
                print(ostring)
                print(traceback.print_exc())
                if caller:
                    caller.msg(ostring)
                continue

        if record.typeclass == settings.TWO_WAY_EXIT_TYPECLASS_KEY:
            # If it's a two way exit, create the reverse exit.
            reverse_exit_key = settings.REVERSE_EXIT_PREFIX + record.key
            if not reverse_exit_key in current_obj_keys:
                ostring = "Creating %s." % reverse_exit_key
                print(ostring)
                if caller: