def dump(data): d_dump = {"deploy": []} d_depend = [] for d_yml in data: if d_yml["just_child_val"]: d_depend.append({"key": d_yml["parent"], "val": d_yml["name"]}) else: pre_yml = {d_yml["name"]: {"template": d_yml["template"]}} for k, v in d_yml.items(): if k not in [ "name", "template", "stack", "parent", "just_child_val" ]: if not utils.check_key(pre_yml[d_yml["name"]], "parameters"): pre_yml[d_yml["name"]]["parameters"] = {k: v} else: pre_yml[d_yml["name"]]["parameters"].update({k: v}) if not utils.check_key(d_dump, d_yml["stack"]): d_dump[d_yml["stack"]] = pre_yml else: d_dump[d_yml["stack"]].update(pre_yml) if d_yml["parent"]: d_depend.append({"key": d_yml["parent"], "val": d_yml["name"]}) else: if len(d_depend) > 0: for k_depend in d_depend: pre_yml[d_yml["name"]]["parameters"].update( {k_depend["key"]: k_depend["val"]}) d_dump["deploy"].append("{}.{}".format(d_yml["stack"], d_yml["name"])) return d_dump
def dump(data): d_dump = {"deploy": []} d_depend = [] for d_yml in data: pre_yml = {d_yml["name"]: {"template": d_yml["template"]}} for k, v in d_yml.items(): if k not in ["name", "template", "stack", "parent"]: if not utils.check_key(pre_yml[d_yml["name"]], "parameters"): pre_yml[d_yml["name"]]["parameters"] = {k: v} else: pre_yml[d_yml["name"]]["parameters"].update({k: v}) if not utils.check_key(d_dump, d_yml["stack"]): d_dump[d_yml["stack"]] = pre_yml else: d_dump[d_yml["stack"]].update(pre_yml) if d_yml["parent"]: d_depend.append({"key": d_yml["parent"], "val": d_yml["name"]}) else: if len(d_depend) > 0: for k_depend in d_depend: pre_yml[d_yml["name"]]["parameters"].update({ k_depend["key"]: k_depend["val"] }) d_dump["deploy"].append("{}.{}".format(d_yml["stack"], d_yml["name"])) return d_dump
def setup_form(stack, project, parent=None): init = { "form": [{ "type": "TitleText", "name": "Name", "key": "name" }], "depend": [], "number": [], "stack": stack, "project": project, "parent": parent } if parent: init["parent"] = parent repo = utils.repodata()[stack][project] if utils.check_key(repo, "parameters"): param = repo["parameters"] param_index = utils.get_index(param) for index in param_index: prop = param[index] if not utils.check_key(prop, "default"): if not 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 initialize(manifest_fie): init = list() utils.log_info("Initialization....") key = utils.do_deploy_dir(manifest_fie) for stack in utils.initdir(key): for project in key["stack"][stack]: template = key["data"][stack][project]["template"] try: parameters = key["data"][stack][project]["parameters"] except: parameters = None url = False try: url = utils.repodata()[stack][template]["url"] except: utils.log_err("template {} is not exist!".format(template)) exit() dest = "{}/{}/{}".format(key["deploy_dir"], stack, project) utils.log_info("Build {} {} template".format(project, stack)) if not utils.template_url(url, dest): utils.log_err("Check your internet connection!") exit() utils.log_info("Done...") """ Stack init dict """ stack_init = {} stack_init["dir"] = dest stack_init["project"] = project stack_init["stack"] = stack stack_init["env_file"] = False if parameters: utils.log_info("Create {} {} environment file".format( project, stack)) utils.yaml_create("{}/env.yml".format(dest), { "parameters": parameters }) utils.log_info("Done...") stack_init["env_file"] = "{}/env.yml".format(dest) init.append(stack_init) """ Reformat squences deploy """ if utils.check_key(key["data"], "deploy"): if len(key["data"]["deploy"]) > 0: set_sequence = list() for deploy in key["data"]["deploy"]: set_deploy = deploy.split(".") set_stack = set_deploy[0] set_project = set_deploy[1] set_sequence.append([ new_init for new_init in init if (new_init["stack"] == set_stack) and ( new_init["project"] == set_project) ][0]) init = set_sequence utils.yaml_create("{}/deploy.yml".format(key["deploy_dir"]), init) return init
def setup_form(stack, project, parent=None): init = { "form": [], "depend": [], "number": [], "stack": stack, "project": project, "parent": parent, } if parent: init["parent"] = parent repo = utils.repodata()[stack][project] default_form_name = {"type": "TitleText", "name": "Name", "key": "name"} if 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) else: init["form"].append(default_form_name) if utils.check_key(repo, "parameters"): param = repo["parameters"] param_index = utils.get_index(param) for index in param_index: prop = param[index] if not utils.check_key(prop, "default"): if not 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