def init(stack=None, project=None): select_stack = stack while not select_stack: select_stack = get_stack() select_project = project while not select_project: select_project = get_project(select_stack) fields = exec_form(select_stack, select_project) data = list() for field in fields["init"]: f_field = eval(str(field["form"])) validate = False while not validate: f_form = eval(str(field["form"])) form = utils.form_generator("Setup {}".format(field["project"]), f_form) for k, v in form.items(): if isinstance(v.value, list): for role in f_field: if role["key"] == k: form[k] = role["values"][v.value[0]] else: form[k] = v.value if field["parent"]: form["parent"] = field["parent"] else: form["parent"] = None form["stack"] = field["stack"] form["template"] = field["project"] """ Check if data is null """ null_data = 0 for k_data, v_data in form.items(): if v_data == "": null_data += 1 if len(field["number"]) > 0: if k_data in field["number"]: if utils.isint(v_data): form[k_data] = int(v_data) elif utils.isfloat(v_data): form[k_data] = float(v_data) else: null_data += 1 if null_data == 0: validate = True data.append(form) utils.yaml_create("neo.yml", dump(data)) return utils.read_file("neo.yml")
def get_stack(): d_stack = utils.get_index(utils.repodata()) f_stack = [{ "type": "TitleSelectOne", "name": "Select Stack :", "key": "stack", "values": d_stack, }] stack = utils.form_generator("Stack list", f_stack) try: return d_stack[stack["stack"].value[0]] except: return None
def get_project(templates): d_template = utils.get_index(utils.repodata()[templates]) f_template = [{ "type": "TitleSelectOne", "name": "Select template :", "key": "template", "values": d_template, }] template = utils.form_generator("Templates", f_template) try: return d_template[template["template"].value[0]] except: return None
def get_project(templates): d_template = utils.get_index(utils.repodata()[templates]) f_template = [ { "type": "TitleSelectOne", "name": "Select template :", "key": "template", "values": d_template }, ] template = utils.form_generator("Templates", f_template) try: return (d_template[template["template"].value[0]]) except: return None
def get_stack(): d_stack = utils.get_index(utils.repodata()) f_stack = [ { "type": "TitleSelectOne", "name": "Select Stack :", "key": "stack", "values": d_stack }, ] stack = utils.form_generator("Stack list", f_stack) try: return d_stack[stack["stack"].value[0]] except: return None
def test_form_generator(self, monkeypatch): monkeypatch.setattr("neo.libs.utils.form_generator", lambda x, y: ('foo', 'bar')) out = utils.form_generator('fofo', 'baz') assert out == ('foo', 'bar')