Esempio n. 1
0
    def write(self, key, value, section):

        if not value:
            value = None
        elif key == "xmltv_offset":
            value = str(value)
        elif str(value) in ["0"]:
            value = 0
        elif isint(value):
            value = int(value)
        elif isfloat(value):
            value = float(value)
        elif is_arithmetic(value):
            value = eval(value)
        elif isinstance(value, list):
            ",".join(value)
        elif str(value).lower() in ["none", ""]:
            value = None
        elif str(value).lower() in ["false"]:
            value = False
        elif str(value).lower() in ["true"]:
            value = True

        self.dict[section][key] = value

        config_handler = configparser.ConfigParser()
        config_handler.read(self.config_file)

        if not config_handler.has_section(section):
            config_handler.add_section(section)

        config_handler.set(section, key, str(value))

        with open(self.config_file, 'w') as config_file:
            config_handler.write(config_file)
Esempio n. 2
0
    def read_json_config(self, conffilepath):
        with open(conffilepath, 'r') as jsonconf:
            confimport = json.load(jsonconf)
        for section in list(confimport.keys()):

            if section not in self.dict.keys():
                self.dict[section] = {}

            if section not in self.conf_default.keys():
                self.conf_default[section] = {}

            for key in list(confimport[section].keys()):

                if key not in list(self.conf_default[section].keys()):
                    self.conf_default[section][key] = {}

                confvalue = confimport[section][key]["value"]
                if key == "xmltv_offset":
                    confvalue = str(confvalue)
                elif isint(confvalue):
                    confvalue = int(confvalue)
                elif isfloat(confvalue):
                    confvalue = float(confvalue)
                elif is_arithmetic(confvalue):
                    confvalue = eval(confvalue)
                elif "," in confvalue:
                    confvalue = confvalue.split(",")
                elif str(confvalue).lower() in ["none"]:
                    confvalue = None
                elif str(confvalue).lower() in ["false"]:
                    confvalue = False
                elif str(confvalue).lower() in ["true"]:
                    confvalue = True

                self.dict[section][key] = confvalue

                self.conf_default[section][key]["value"] = confvalue

                for config_option in [
                        "config_web_hidden", "config_file", "config_web"
                ]:
                    if config_option not in list(
                            confimport[section][key].keys()):
                        config_option_value = False
                    else:
                        config_option_value = confimport[section][key][
                            config_option]
                        if str(config_option_value).lower() in ["none"]:
                            config_option_value = None
                        elif str(config_option_value).lower() in ["false"]:
                            config_option_value = False
                        elif str(config_option_value).lower() in ["true"]:
                            config_option_value = True
                    self.conf_default[section][key][
                        config_option] = config_option_value
Esempio n. 3
0
    def get_real_conf_value(self, key, confvalue):
        """
        Check config value is prepped correctly.
        """

        if not confvalue:
            confvalue = None

        elif isinstance(confvalue, type(None)):
            confvalue = None

        elif key == "xmltv_offset":
            confvalue = str(confvalue)

        elif str(confvalue) in [0, "0"]:
            confvalue = 0

        elif isint(confvalue):
            confvalue = int(confvalue)

        elif isfloat(confvalue):
            confvalue = float(confvalue)

        elif is_arithmetic(confvalue):
            confvalue = eval(confvalue)

        elif "," in confvalue:
            confvalue = confvalue.split(",")

        elif str(confvalue).lower() in ["none", ""]:
            confvalue = None

        elif str(confvalue).lower() in ["false"]:
            confvalue = False

        elif str(confvalue).lower() in ["true"]:
            confvalue = True

        return confvalue
Esempio n. 4
0
 def get_real_conf_value(self, key, confvalue):
     if not confvalue:
         confvalue = None
     elif key == "xmltv_offset":
         confvalue = str(confvalue)
     elif str(confvalue) in ["0"]:
         confvalue = 0
     elif isint(confvalue):
         confvalue = int(confvalue)
     elif isfloat(confvalue):
         confvalue = float(confvalue)
     elif is_arithmetic(confvalue):
         confvalue = eval(confvalue)
     elif "," in confvalue:
         confvalue = confvalue.split(",")
     elif str(confvalue).lower() in ["none", ""]:
         confvalue = None
     elif str(confvalue).lower() in ["false"]:
         confvalue = False
     elif str(confvalue).lower() in ["true"]:
         confvalue = True
     return confvalue
Esempio n. 5
0
 def read_config(self, conffilepath):
     config_handler = configparser.ConfigParser()
     config_handler.read(conffilepath)
     for each_section in config_handler.sections():
         if each_section.lower() not in list(self.dict.keys()):
             self.dict[each_section.lower()] = {}
         for (each_key, each_val) in config_handler.items(each_section):
             if not each_val:
                 each_val = None
             elif each_val.lower() in ["none", "false"]:
                 each_val = False
             elif each_val.lower() in ["true"]:
                 each_val = True
             elif isint(each_val):
                 each_val = int(each_val)
             elif isfloat(each_val):
                 each_val = float(each_val)
             elif is_arithmetic(each_val):
                 each_val = eval(each_val)
             elif "," in each_val:
                 each_val = each_val.split(",")
             self.dict[each_section.lower()][each_key.lower()] = each_val
Esempio n. 6
0
    def read_ini_config(self, conffilepath):
        config_handler = configparser.ConfigParser()
        config_handler.read(conffilepath)
        for each_section in config_handler.sections():
            if each_section.lower() not in list(self.dict.keys()):
                self.dict[each_section.lower()] = {}
            for (each_key, each_val) in config_handler.items(each_section):
                if not each_val:
                    each_val = None
                elif each_key == "xmltv_offset":
                    each_val = str(each_val)
                elif each_val.lower() in ["none"]:
                    each_val = None
                elif each_val.lower() in ["false"]:
                    each_val = False
                elif each_val.lower() in ["true"]:
                    each_val = True
                elif isint(each_val):
                    each_val = int(each_val)
                elif isfloat(each_val):
                    each_val = float(each_val)
                elif is_arithmetic(each_val):
                    each_val = eval(each_val)
                elif "," in each_val:
                    each_val = each_val.split(",")

                import_val = True
                if each_section in list(self.conf_default.keys()):
                    if each_key in list(
                            self.conf_default[each_section].keys()):
                        if not self.conf_default[each_section][each_key][
                                "config_file"]:
                            import_val = False

                if import_val:
                    self.dict[each_section.lower()][
                        each_key.lower()] = each_val