Example #1
0
def patch_db(verb, args, command, **ignored):
    if len(args) == 0:
        return "Type required."
    obj_type = args[0]
    if len(args) == 1:
        return "Object id required."
    obj_id = args[1]
    if len(args) == 2:
        return "Property name required."
    prop = args[2]
    new_value = find_extra(verb, 3, command)
    if not new_value:
        return "Value required."
    if new_value == "None":
        new_value = None
    key = ":".join([obj_type, obj_id])
    if obj_type == "player":
        obj = load_object(Player, obj_id)
    else:
        obj = load_cached(key)
    if not obj:
        return "Object not found"
    try:
        patch_object(obj, prop, new_value)
    except PatchError as exp:
        return exp.message

    save_object(obj)
    return "Object " + key + " patched"
Example #2
0
def patch(source, verb, args, command, **ignored):
    try:
        split_ix = args.index(":")
        target_id = args[:split_ix]
        prop = args[split_ix + 1]
        new_value =  find_extra(verb, split_ix + 2, command)
    except (ValueError, IndexError):
        return "Syntax -- 'patch [target] [:] [prop_name] [new_value]'"
    target_list = list(source.matching_targets(target_id, "__dict__"))
    if not target_list:
        return "No matching target"
    if len(target_list) > 1:
        return "Multiple matching targets"
    if not new_value:
        return "New value required"
    if new_value == "None":
        new_value = None
    try:
        patch_object(target_list[0][0], prop, new_value)
    except PatchError as exp:
        return exp.message
    return "Object successfully patched"