Exemple #1
0
def patch(target, obj):
    prop, new_value = next_word(obj)
    if not new_value:
        return "New value required"
    if new_value == "None":
        new_value = None
    patch_object(target, prop, new_value)
    return "Object successfully patched"
Exemple #2
0
def add_flag(source, target, obj):
    flag_id, flag_value = next_word(target)
    if not flag_value:
        raise ActionError("Value for flag {} required.".format(flag_id))
    try:
        flag_value = str_to_primitive(flag_value)
    except ValueError:
        raise ActionError("Cannot parse {}".format(flag_value))
    obj.flags[flag_id] = flag_value
    source.display_line("Flag {} set to {} on {}.".format(flag_id, flag_value, obj.name))
Exemple #3
0
def patch_db(target):
    obj_type, remaining = next_word(target)
    obj_id, remaining = next_word(remaining)
    if not obj_id:
        return "Object id required."
    prop, new_value = next_word(remaining)
    if not prop:
        return "Property name required."
    if not new_value:
        return "Value required."
    if new_value == "None":
        new_value = None
    key = ':'.join([obj_type, obj_id])
    obj = db.load_object(key)
    if not obj:
        return "Object not found"
    patch_object(obj, prop, new_value)
    db.save_object(obj)
    return "Object " + key + " patched"