def setup_form(stack, project, parent=None): init = { "form": [{ "type": "TitleText", "name": "User Id", "key": "userId" }], "depend": [], "number": [], "stack": stack, "project": project, "parent": parent } if parent: init["parent"] = parent repo = yaml_utils.repodata()[stack][project] if yaml_utils.check_key(repo, "parameters"): param = repo["parameters"] param_index = yaml_utils.get_index(param) for index in param_index: prop = param[index] if not yaml_utils.check_key(prop, "default"): if not yaml_utils.check_key(prop, "dependences"): init["form"].append({ "type": "TitleText", "name": prop["label"], "key": index }) if prop["type"] == "number": init["number"].append(index) else: depend = prop["dependences"] if depend.split(":")[0] == "func": func_name = depend.split(":")[1] init["form"].append({ "type": "TitleSelectOne", "name": prop["label"], "key": index, "scroll_exit": True, "values": globals()[func_name](), "max_height": 7, "value": [ 0, ] }) if depend.split(":")[0] == "repo": repo_name = depend.split(":")[1] init["depend"].append({ "name": prop["label"], "key": index, "repo": repo_name }) return init
def get_stack(): try: d_stack = yaml_utils.get_index(yaml_utils.repodata()) f_stack = [ { "type": "TitleSelectOne", "name": "Select Stack ", "key": "stack", "values": d_stack }, ] stack = cli_utils.prompt_generator("", f_stack) return stack[f_stack[0]["key"]] except: return None
def get_project(templates): try: d_template = yaml_utils.get_index(yaml_utils.repodata()[templates]) f_template = [ { "type": "TitleSelectOne", "name": "-------------------", "key": "template", "values": d_template }, ] template = cli_utils.prompt_generator("Select Templates ", f_template) return template[f_template[0]["key"]] except: return None
def get_stack(): d_stack = yaml_utils.get_index(yaml_utils.repodata()) f_stack = [ { "type": "TitleSelectOne", "name": "Select Stack :", "key": "stack", "values": d_stack }, ] stack = cli_utils.form_generator("Stack list", f_stack) try: return d_stack[stack["stack"].value[0]] except: return None
def get_project(templates): d_template = yaml_utils.get_index(yaml_utils.repodata()[templates]) f_template = [ { "type": "TitleSelectOne", "name": "Select template :", "key": "template", "values": d_template }, ] template = cli_utils.form_generator("Templates", f_template) try: return (d_template[template["template"].value[0]]) except: return None
def setup_form(stack, project, parent=None): init = { "form": [], "depend": [], "number": [], "stack": stack, "project": project, "parent": parent } if parent: init["parent"] = parent repo = yaml_utils.repodata()[stack][project] default_form_name = {} if yaml_utils.check_key(repo, "lists"): repo_lists = repo["lists"] """ if type of 'repo_list' is list """ if isinstance(repo_lists, list): init["form"].append({ "type": "TitleSelect", "name": "Name", "key": "name", "values": repo_lists }) else: """ if type of 'repo_list' is string """ repo_lists = globals()[repo["lists"]]() if len(repo_lists) > 0: init["form"].append({ "type": "TitleSelect", "name": "Name", "key": "name", "values": repo_lists }) else: init["form"].append(default_form_name) if yaml_utils.check_key(repo, "parameters"): param = repo["parameters"] param_index = yaml_utils.get_index(param) for index in param_index: prop = param[index] if not yaml_utils.check_key(prop, "default"): if not yaml_utils.check_key(prop, "dependences"): formItem = { "type": "TitleText", "name": prop["label"], "key": index, } if 'required' not in prop: formItem['required'] = True else: formItem['required'] = prop['required'] init["form"].append(formItem) if prop["type"] == "number": init["number"].append(index) else: depend = prop["dependences"] if depend.split(":")[0] == "func": func_name = depend.split(":")[1] init["form"].append({ "type": "TitleSelectOne", "name": prop["label"], "key": index, "scroll_exit": True, "values": globals()[func_name](), "max_height": 7, "value": [ 0, ] }) if depend.split(":")[0] == "repo": repo_name = depend.split(":")[1] init["depend"].append({ "name": prop["label"], "key": index, "repo": repo_name }) return init