Commit 2ae15a1c authored by Jan Koniarik's avatar Jan Koniarik
Browse files

reviewed code for lib/config.py, some typos and unused variable

parent 25a554ab
"""
Library module to handle configuratio yaml file.
Library module to handle configuration yaml file.
Units:
- units are implemented as object, where each unit inherits Unit() object
- units are implemented as objects, where each unit inherits Unit() object
- in cases yaml library matches 'config_re' from this module, it's than
passed to module mechanism.
- regexp extracts value and unit, based on 'unit_config', method is
......@@ -13,7 +13,6 @@ import yaml
import re
import math
import collections
import parser
class Unit(float):
......@@ -186,6 +185,9 @@ def cfg_constructor(loader, node):
val = float(val)
if unit not in unit_config:
raise Exception("Found unknown unit: " + str(unit))
return unit_config[unit](val)
......@@ -212,14 +214,14 @@ ParseFormulaRes = collections.namedtuple(
def _parse_val(val, top_cfg):
""" parser for variables, if formula is fount, it tries to resolve it.
""" parser for variables, if formula is found, it tries to resolve it.
Returns 'ParseFormulaRes' """
res = re.match("^\s*%(.*)%\s*$", val)
if res is None:
return ParseFormulaRes(val=val, replaced_count=0, unreplaced_count=0)
# extract formula itlsef
# extract formula itself
formula = res.group(1)
# use 're' to match all names in formula
......@@ -235,7 +237,7 @@ def _parse_val(val, top_cfg):
# for each matched formula:
for var in vars:
if var in ["max", "min", "abs", "Distance", "Angle"]:
if var in ignored_names:
continue
# split variable name into separate keys
......@@ -300,7 +302,7 @@ def _parse_val(val, top_cfg):
def _parse_config_rec(cfg, top_cfg):
""" Recursive parser of dictionary config, primary goal is to parse formulars.
""" Recursive parser of dictionary config, primary goal is to parse formulas.
Should be only executed over list or dictionary.
Does not parse yaml files, it processes parsed yaml config file.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment