Example #1
0
def action_edit(command_data, opts):
    client_name = opts.client_name
    if client_name == None:
        print "Need client name to show the attr for"
        sys.exit(1)

    zkroot = command_data["zkdetails"]["zkroot"]
    if not is_existing_client(zkroot, client_name):
        print "Invalid client[{client_name}]".format(**locals())
        sys.exit(1)

    zk_client = command_data["zkdetails"]["zk_client"]
    ensure_client_has_attr(zkroot, zk_client, client_name)

    data_fpath = zkroot + gdata[
        "all_clients_node_path"] + "/" + client_name + "/attr/_data_"
    #do the edit
    from subprocess import call
    editor = seldon_utils.get_editor()
    call([editor, data_fpath])

    f = open(data_fpath)
    json = f.read()
    f.close()
    data = seldon_utils.json_to_dict(json)

    if data is None:
        print "Invalid attr json!"
    else:
        write_data_to_file(data_fpath, data)
        node_path = gdata["all_clients_node_path"] + "/" + client_name + "/attr"
        zk_utils.node_set(zk_client, node_path,
                          seldon_utils.dict_to_json(data))
        show_attr(data)
Example #2
0
def action_edit(command_data, opts):
    client_name = opts.client_name
    if client_name == None:
        print "Need client name to show the attr for"
        sys.exit(1)

    zkroot = command_data["zkdetails"]["zkroot"]
    if not is_existing_client(zkroot, client_name):
        print "Invalid client[{client_name}]".format(**locals())
        sys.exit(1)

    zk_client = command_data["zkdetails"]["zk_client"]
    ensure_client_has_attr(zkroot, zk_client, client_name)

    data_fpath = zkroot + gdata["all_clients_node_path"] + "/" + client_name + "/attr/_data_"
    #do the edit
    from subprocess import call
    editor=seldon_utils.get_editor()
    call([editor, data_fpath])

    f = open(data_fpath)
    json = f.read()
    f.close()
    data = seldon_utils.json_to_dict(json)

    if data is None:
        print "Invalid attr json!"
    else:
        write_data_to_file(data_fpath, data)
        node_path = gdata["all_clients_node_path"]+"/"+client_name+"/attr"
        zk_utils.node_set(zk_client, node_path, seldon_utils.dict_to_json(data))
        show_attr(data)
Example #3
0
def subcmd_edit(command_data):
    def have_client_name():
        if client_name == None:
            print "Need client name to edit model for"
            return False
        else:
            return True

    def have_valid_client_name():
        if not is_existing_client(zkroot, client_name):
            print "Invalid client[{client_name}]".format(**locals())
            return False
        else:
            return True

    client_name = command_data["subcmd_args"][0] if len(command_data["subcmd_args"])>0 else None
    if not have_client_name(): return
    zk_client = command_data["zkdetails"]["zk_client"]
    zkroot = command_data["zkdetails"]["zkroot"]
    if not have_valid_client_name(): return

    models_for_client_fpath = "{zkroot}{all_clients_node_path}/{client_name}/offline".format(zkroot=zkroot,all_clients_node_path=gdata["all_clients_node_path"],client_name=client_name)

    models = os.listdir(models_for_client_fpath)

    for idx,model in enumerate(models):
        print "    [{idx}] {model}".format(**locals())
    q="Choose model: "
    model_idx = None
    try:
        model_idx = int(raw_input(q))
    except ValueError:
        pass

    model_name = models[model_idx] if model_idx != None and model_idx>=0 and model_idx<len(models) else None

    if model_name == None:
        print "Invaild model"
        return

    data_fpath = "{zkroot}{all_clients_node_path}/{client_name}/offline/{model_name}/_data_".format(zkroot=zkroot,all_clients_node_path=gdata["all_clients_node_path"],client_name=client_name,model_name=model_name)

    #do the edit
    editor=seldon_utils.get_editor()
    call([editor, data_fpath])

    f = open(data_fpath)
    json = f.read()
    f.close()
    data = seldon_utils.json_to_dict(json)

    if data is None:
        print "Invalid model json!"
    else:
        write_data_to_file(data_fpath, data)
        node_path = "{all_clients_node_path}/{client_name}/offline/{model_name}".format(all_clients_node_path=gdata["all_clients_node_path"],client_name=client_name,model_name=model_name)
        pp(node_path)
        zk_utils.node_set(zk_client, node_path, seldon_utils.dict_to_json(data))
Example #4
0
def action_edit(command_data, opts, extra_args):
    zkroot = command_data["zkdetails"]["zkroot"]

    def get_valid_client():
        client_name = opts.client_name
        if client_name == None:
            print "Need client name to show models for"
            sys.exit(1)

        if not is_existing_client(zkroot, client_name):
            print "Invalid client[{client_name}]".format(**locals())
            sys.exit(1)
        return client_name

    def get_valid_model():
        model_name = opts.model_name
        if model_name == None:
            print "Need model name to use"
            sys.exit(1)

        default_models = command_data["conf_data"]["default_models"]
        if model_name not in default_models.keys():
            print "Invalid model name: {model_name}".format(**locals())
            sys.exit(1)
        return model_name

    client_name = get_valid_client()
    model_name = get_valid_model()

    zk_client = command_data["zkdetails"]["zk_client"]

    data_fpath = "{zkroot}{all_clients_node_path}/{client_name}/offline/{model_name}/_data_".format(
        zkroot=zkroot,
        all_clients_node_path=gdata["all_clients_node_path"],
        client_name=client_name,
        model_name=model_name)

    #do the edit
    editor = seldon_utils.get_editor()
    call([editor, data_fpath])

    f = open(data_fpath)
    json = f.read()
    f.close()
    data = seldon_utils.json_to_dict(json)

    if data is None:
        print "Invalid model json!"
    else:
        write_data_to_file(data_fpath, data)
        node_path = "{all_clients_node_path}/{client_name}/offline/{model_name}".format(
            all_clients_node_path=gdata["all_clients_node_path"],
            client_name=client_name,
            model_name=model_name)
        pp(node_path)
        zk_utils.node_set(zk_client, node_path,
                          seldon_utils.dict_to_json(data))
Example #5
0
def action_edit(command_data, opts):
    zkroot = command_data["zkdetails"]["zkroot"]
    def get_valid_client():
        client_name = opts.client_name
        if client_name == None:
            print "Need client name to show models for"
            sys.exit(1)

        if not is_existing_client(zkroot, client_name):
            print "Invalid client[{client_name}]".format(**locals())
            sys.exit(1)
        return client_name

    def get_valid_model():
        model_name = opts.model_name
        if model_name == None:
            print "Need model name to use"
            sys.exit(1)

        default_models = command_data["conf_data"]["default_models"]
        if model_name not in default_models.keys():
            print "Invalid model name: {model_name}".format(**locals())
            sys.exit(1)
        return model_name

    client_name = get_valid_client()
    model_name = get_valid_model()

    zk_client = command_data["zkdetails"]["zk_client"]

    data_fpath = "{zkroot}{all_clients_node_path}/{client_name}/offline/{model_name}/_data_".format(zkroot=zkroot,all_clients_node_path=gdata["all_clients_node_path"],client_name=client_name,model_name=model_name)

    #do the edit
    editor=seldon_utils.get_editor()
    call([editor, data_fpath])

    f = open(data_fpath)
    json = f.read()
    f.close()
    data = seldon_utils.json_to_dict(json)

    if data is None:
        print "Invalid model json!"
    else:
        write_data_to_file(data_fpath, data)
        node_path = "{all_clients_node_path}/{client_name}/offline/{model_name}".format(all_clients_node_path=gdata["all_clients_node_path"],client_name=client_name,model_name=model_name)
        pp(node_path)
        zk_utils.node_set(zk_client, node_path, seldon_utils.dict_to_json(data))