Skip to content
Snippets Groups Projects
Commit f362ab48 authored by Juraj Paluba's avatar Juraj Paluba
Browse files

Merge branch '3-create-parser-for-variables-from-the-json-object' into 'develop'

Resolve "Create parser for variables from the json object"

Closes #3

See merge request !10
parents 2c017e35 4d75c021
Branches
Tags
2 merge requests!12Merge develop to master,!10Resolve "Create parser for variables from the json object"
Pipeline #143516 passed
from typing import List
import yaml import yaml
from generator.var_object import Variable from generator.var_object import Variable
def get_variables(variables_raw: dict) -> List[Variable]:
var_objects = []
for variable_name, variable_options in variables_raw.items():
v_type = variable_options["type"]
v_min = variable_options.get("min")
v_max = variable_options.get("max")
v_length = variable_options.get("length")
v_prohibited = variable_options.get("prohibited")
if v_prohibited is None:
v_prohibited = []
var_objects.append(Variable(variable_name, v_type, v_min, v_max, v_prohibited, v_length))
return var_objects
def parser_var_file(var_file): def parser_var_file(var_file):
""" """
Main function to parsen source data stored in file. Main function to parsen source data stored in file.
...@@ -19,20 +36,9 @@ def parser_var_file(var_file): ...@@ -19,20 +36,9 @@ def parser_var_file(var_file):
""" """
try: try:
var_list = yaml.load(var_file, Loader=yaml.FullLoader) variables_raw = yaml.load(var_file, Loader=yaml.FullLoader)
var_objects = [] return get_variables(variables_raw)
for var in var_list.keys(): except Exception as exc:
v_name = var # TODO: Remove this horrendous exception handling!
v_type = var_list[var]["type"] print(f"Something went wrong: {exc}")
v_min = var_list[var].get("min")
v_max = var_list[var].get("max")
v_length = var_list[var].get("length")
v_prohibited = var_list[var].get("prohibited")
if v_prohibited is None:
v_prohibited = []
var_objects.append(Variable(v_name, v_type, v_min, v_max, v_prohibited, v_length))
except Exception as e:
print("Error occure")
return None return None
return var_objects
[metadata] [metadata]
version = v0.1.0rc1 version = v0.1.1rc0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment