from configparser import ConfigParser class ChartConfig: def __init__(self, path): cfgp = ConfigParser() cfgp.read(path) self.chart_config = cfgp["chart"] def get_variable_parameter_config(self, key): config = {} positionnal = ["cat", "color", "unit"] if key in self.chart_config.keys(): raw_value = self.chart_config[key] arguments = raw_value.split(",") keyword_mode = False for i, argument in enumerate(arguments): pieces = argument.split(":") if len(pieces) == 2: keyword_mode = True if pieces[1] != "": config[pieces[0]] = pieces[1] else: if not keyword_mode: #everything is going well if pieces[0] != "": config[positionnal[i]] = pieces[0] else: #we cannot have a positionnal argument after a keyword argument return None return config else: return None