from configparser import ConfigParser
class ChartConfig:
    def __init__(self):
        cfgp = ConfigParser()
        cfgp.read("./variables_config.ini")
        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
                    config[pieces[0]] = pieces[1]
                else:
                    if not keyword_mode: #everything is going well
                        config[positionnal[i]] = pieces[0]
                    else: #we cannot have a positionnal argument after a keyword argument
                        return None
            return config
        else:
            return None
