def process_var_envs(executor_name):
    end = False
    section = Sections.EXECUTOR_VARENVS.format(executor_name)

    while not end:
        print(
            f"The actual {Bcolors.BOLD}{Bcolors.OKBLUE}{executor_name}"
            f" executor's environment variables{Bcolors.ENDC} are:"
            f" {Bcolors.OKGREEN}{config.instance.options(section)}"
            f"{Bcolors.ENDC}"
        )
        value = choose_adm("environment variable")
        if value == "A":
            env_var = click.prompt("Environment variable name").lower()
            if env_var in config.instance.options(section):
                print(f"{Bcolors.WARNING}The environment variable {env_var} " f"already exists{Bcolors.ENDC}")
            else:
                value = click.prompt("Environment variable value")
                config.instance.set(section, env_var, value)
        elif value == "M":
            env_var = click.prompt("Environment variable name").lower()
            if env_var not in config.instance.options(section):
                print(f"{Bcolors.WARNING}There is no {env_var} environment " f"variable{Bcolors.ENDC}")
            else:
                def_value, env_var = get_new_name(env_var, section, "environment variable")
                value = click.prompt("Environment variable value", default=def_value)
                config.instance.set(section, env_var, value)
        elif value == "D":
            env_var = click.prompt("Environment variable name").lower()
            if env_var not in config.instance.options(section):
                print(f"{Bcolors.WARNING}There is no {env_var}" f"environment variable{Bcolors.ENDC}")
            else:
                config.instance.remove_option(section, env_var)
        else:
            end = True
def process_params(executor_name):
    end = False
    section = Sections.EXECUTOR_PARAMS.format(executor_name)

    while not end:
        print(
            f"The actual {Bcolors.BOLD}{Bcolors.OKBLUE}{executor_name}"
            f" executor's arguments{Bcolors.ENDC} are: "
            f"{Bcolors.OKGREEN}{config.instance.options(section)}"
            f"{Bcolors.ENDC}"
        )
        value = choose_adm("argument")
        if value == "A":
            param = click.prompt("Argument name").lower()
            if param in config.instance.options(section):
                print(f"{Bcolors.WARNING}The argument {param} already exists" f"{Bcolors.ENDC}")
            else:
                value = confirm_prompt("Is mandatory?")
                config.instance.set(section, param, f"{value}")
        elif value == "M":
            param = click.prompt("Argument name").lower()
            if param not in config.instance.options(section):
                print(f"{Bcolors.WARNING}There is no {param} argument" f"{Bcolors.ENDC}")
            else:
                def_value, param = get_new_name(param, section, "argument")
                value = confirm_prompt("Is mandatory?", default=def_value)
                config.instance.set(section, param, f"{value}")
        elif value == "D":
            param = click.prompt("Argument name").lower()
            if param not in config.instance.options(section):
                print(f"{Bcolors.WARNING}There is no {param} argument" f"{Bcolors.ENDC}")
            else:
                config.instance.remove_option(section, param)
        else:
            end = True
def process_workspaces() -> None:
    end = False
    section = Sections.SERVER

    workspaces = config.instance[Sections.SERVER].get("workspaces", "")
    workspaces = workspaces.split(",")
    if "" in workspaces:
        workspaces.remove("")

    while not end:
        print(f"The actual workspaces{Bcolors.ENDC} are:" f" {Bcolors.OKGREEN}{workspaces}{Bcolors.ENDC}")
        value = choose_adm("workspace", ignore=["M"])
        if value == "A":
            workspace_name = click.prompt("Workspace name")
            if workspace_name in workspaces:
                print(f"{Bcolors.WARNING}The workspace {workspace_name} already " f"exists{Bcolors.ENDC}")
            else:
                workspaces.append(workspace_name)
        elif value == "D":
            workspace_name = click.prompt("workspace name")
            if workspace_name not in workspaces:
                print(f"{Bcolors.WARNING}There is no {workspace_name}" f"workspace{Bcolors.ENDC}")
            else:
                workspaces.remove(workspace_name)
        else:
            end = True

    config.instance.set(section, "workspaces", ",".join(workspaces))
def process_params(executor_name):
    end = False
    if "params" not in config.instance[Sections.AGENT][
            Sections.EXECUTORS][executor_name]:
        config.instance[Sections.AGENT][
            Sections.EXECUTORS][executor_name]["params"] = {}
    section = config.instance[Sections.AGENT][
        Sections.EXECUTORS][executor_name].get("params")

    while not end:
        print(f"The current {Bcolors.BOLD}{Bcolors.OKBLUE}{executor_name}"
              f" executor's arguments{Bcolors.ENDC} are: "
              f"{Bcolors.OKGREEN}{list(section.keys())}"
              f"{Bcolors.ENDC}")
        value = choose_adm("argument")
        if value == "A":
            param = click.prompt("Argument name").lower()
            if param in section:
                print(f"{Bcolors.WARNING}The argument {param} already exists"
                      f"{Bcolors.ENDC}")
            else:
                mandatory = confirm_prompt("Is mandatory?")
                input_type = click.prompt("Type?",
                                          type=click.Choice(DATA_TYPE.keys()))
                input_base_type = DATA_TYPE[input_type].type().base
                section[param] = {
                    "mandatory": mandatory,
                    "type": input_type,
                    "base": input_base_type
                }
        elif value == "M":
            param = click.prompt("Argument name").lower()
            if param not in section:
                print(f"{Bcolors.WARNING}There is no {param} argument"
                      f"{Bcolors.ENDC}")
            else:
                def_value, param = get_new_name(param, section, "argument")
                mandatory = confirm_prompt("Is mandatory?",
                                           default=def_value["mandatory"])
                input_type = click.prompt("Type?",
                                          type=click.Choice(DATA_TYPE.keys()),
                                          default=def_value["type"])
                input_base_type = DATA_TYPE[input_type].type().base
                section[param] = {
                    "mandatory": mandatory,
                    "type": input_type,
                    "base": input_base_type
                }
        elif value == "D":
            param = click.prompt("Argument name").lower()
            if param not in section:
                print(f"{Bcolors.WARNING}There is no {param} argument"
                      f"{Bcolors.ENDC}")
            else:
                section.pop(param)
        else:
            end = True
Esempio n. 5
0
    async def process_executors(self):
        end = False

        while not end:
            print(f"The actual configured {Bcolors.OKBLUE}{Bcolors.BOLD}"
                  f"executors{Bcolors.ENDC} are: {Bcolors.OKGREEN}"
                  f"{self.executors_list}{Bcolors.ENDC}")
            value = choose_adm("executor")
            if value.upper() == "A":
                await self.new_executor()
            elif value.upper() == "M":
                self.edit_executor()
            elif value.upper() == "D":
                self.delete_executor()
            else:
                end = True
Esempio n. 6
0
    async def process_executors(self):
        end = False

        while not end:
            print(f"The actual configured {Bcolors.OKBLUE}{Bcolors.BOLD}"
                  f"executors{Bcolors.ENDC} are: {Bcolors.OKGREEN}"
                  f"{list(self.executors_dict.keys())}{Bcolors.ENDC}")
            value = choose_adm("executor")
            if value.upper() == "A":
                await self.new_executor()
            elif value.upper() == "M":
                self.edit_executor()
            elif value.upper() == "D":
                self.delete_executor()
            else:
                quit_executor_msg = f"{Bcolors.WARNING}There are no executors loaded. Are you sure?{Bcolors.ENDC}"
                return confirm_prompt(
                    quit_executor_msg,
                    default=False) if not self.executors_dict else True
def process_var_envs(executor_name):
    end = False
    if "varenvs" not in config.instance[Sections.AGENT][
            Sections.EXECUTORS][executor_name]:
        config.instance[Sections.AGENT][
            Sections.EXECUTORS][executor_name]["varenvs"] = {}
    section = config.instance[Sections.AGENT][
        Sections.EXECUTORS][executor_name].get("varenvs")

    while not end:
        print(f"The current {Bcolors.BOLD}{Bcolors.OKBLUE}{executor_name}"
              f" executor's environment variables{Bcolors.ENDC} are:"
              f" {Bcolors.OKGREEN}{list(section.keys())}"
              f"{Bcolors.ENDC}")
        value = choose_adm("environment variable")
        if value == "A":
            env_var = click.prompt("Environment variable name").lower()
            if env_var in section:
                print(f"{Bcolors.WARNING}The environment variable {env_var} "
                      f"already exists{Bcolors.ENDC}")
            else:
                value = click.prompt("Environment variable value")
                section[env_var] = value
        elif value == "M":
            env_var = click.prompt("Environment variable name").lower()
            if env_var not in section:
                print(f"{Bcolors.WARNING}There is no {env_var} environment "
                      f"variable{Bcolors.ENDC}")
            else:
                def_value, env_var = get_new_name(env_var, section,
                                                  "environment variable")
                value = click.prompt("Environment variable value",
                                     default=def_value)
                section[env_var] = value
        elif value == "D":
            env_var = click.prompt("Environment variable name").lower()
            if env_var not in section:
                print(f"{Bcolors.WARNING}There is no {env_var}"
                      f"environment variable{Bcolors.ENDC}")
            else:
                section.pop(env_var)
        else:
            end = True