Esempio n. 1
0
    def write_config(self, params):
        """Writes a key-value pair into an INI type config file."""
        # Get file
        if 'file' not in params:
            raise ScriptingError('"file" parameter is mandatory for the '
                                 'write_conf command', params)
        config_file = self._get_file(params['file'])
        if not config_file:
            config_file = self._substitute(params['file'])

        # Create it if necessary
        basedir = os.path.dirname(config_file)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        parser = EvilConfigParser(allow_no_value=True,
                                  dict_type=MultiOrderedDict)
        parser.optionxform = str  # Preserve text case
        parser.read(config_file)

        if not parser.has_section(params['section']):
            parser.add_section(params['section'])
        parser.set(params['section'], params['key'], params['value'])

        with open(config_file, 'wb') as f:
            parser.write(f)
Esempio n. 2
0
    def write_config(self, params):
        """Write a key-value pair into an INI type config file."""
        self._check_required_params(['file', 'section', 'key', 'value'],
                                    params, 'write_config')
        # Get file
        config_file = self._get_file(params['file'])
        if not config_file:
            config_file = self._substitute(params['file'])

        # Create it if necessary
        basedir = os.path.dirname(config_file)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        parser = EvilConfigParser(allow_no_value=True,
                                  dict_type=MultiOrderedDict,
                                  strict=False)
        parser.optionxform = str  # Preserve text case
        parser.read(config_file)

        value = self._substitute(params['value'])

        if not parser.has_section(params['section']):
            parser.add_section(params['section'])
        parser.set(params['section'], params['key'], value)

        with open(config_file, 'wb') as f:
            parser.write(f)
Esempio n. 3
0
    def write_config(self, params):
        """Write a key-value pair into an INI type config file."""
        self._check_required_params(['file', 'section', 'key', 'value'],
                                    params, 'write_config')
        # Get file
        config_file_path = self._get_file(params['file'])

        # Create dir if necessary
        basedir = os.path.dirname(config_file_path)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        parser = EvilConfigParser(allow_no_value=True,
                                  dict_type=MultiOrderedDict,
                                  strict=False)
        parser.optionxform = str  # Preserve text case
        parser.read(config_file_path)

        value = self._substitute(params['value'])

        if not parser.has_section(params['section']):
            parser.add_section(params['section'])
        parser.set(params['section'], params['key'], value)

        with open(config_file_path, 'wb') as config_file:
            parser.write(config_file)
Esempio n. 4
0
    def write_config(self, params):
        """Writes a key-value pair into an INI type config file."""
        # Get file
        if 'file' not in params:
            raise ScriptingError('"file" parameter is mandatory for the '
                                 'write_conf command', params)
        config_file = self._get_file(params['file'])
        if not config_file:
            config_file = self._substitute(params['file'])

        # Create it if necessary
        basedir = os.path.dirname(config_file)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        parser = EvilConfigParser(allow_no_value=True,
                                  dict_type=MultiOrderedDict)
        parser.optionxform = str  # Preserve text case
        parser.read(config_file)

        if not parser.has_section(params['section']):
            parser.add_section(params['section'])
        parser.set(params['section'], params['key'], params['value'])

        with open(config_file, 'wb') as f:
            parser.write(f)
Esempio n. 5
0
    def write_config(self, params):
        """Write a key-value pair into an INI type config file."""
        if params.get("data"):
            self._check_required_params(["file", "data"], params,
                                        "write_config")
        else:
            self._check_required_params(["file", "section", "key", "value"],
                                        params, "write_config")
        # Get file
        config_file_path = self._get_file(params["file"])

        # Create dir if necessary
        basedir = os.path.dirname(config_file_path)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        merge = params.get("merge", True)

        parser = EvilConfigParser(allow_no_value=True,
                                  dict_type=MultiOrderedDict,
                                  strict=False)
        parser.optionxform = str  # Preserve text case
        if merge:
            parser.read(config_file_path)

        data = {}
        if params.get("data"):
            data = params["data"]
        else:
            data[params["section"]] = {}
            data[params["section"]][params["key"]] = params["value"]

        for section, keys in data.items():
            if not parser.has_section(section):
                parser.add_section(section)
            for key, value in keys.items():
                value = self._substitute(value)
                parser.set(section, key, value)

        with open(config_file_path, "wb") as config_file:
            parser.write(config_file)
Esempio n. 6
0
    def write_config(self, params):
        """Write a key-value pair into an INI type config file."""
        if params.get("data", None):
            self._check_required_params(["file", "data"], params, "write_config")
        else:
            self._check_required_params(
                ["file", "section", "key", "value"], params, "write_config"
            )
        # Get file
        config_file_path = self._get_file(params["file"])

        # Create dir if necessary
        basedir = os.path.dirname(config_file_path)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        merge = params.get("merge", True)

        parser = EvilConfigParser(
            allow_no_value=True, dict_type=MultiOrderedDict, strict=False
        )
        parser.optionxform = str  # Preserve text case
        if merge:
            parser.read(config_file_path)

        data = {}
        if params.get("data", None):
            data = params["data"]
        else:
            data[params["section"]] = {}
            data[params["section"]][params["key"]] = params["value"]

        for section, keys in data.items():
            if not parser.has_section(section):
                parser.add_section(section)
            for key, value in keys.items():
                value = self._substitute(value)
                parser.set(section, key, value)

        with open(config_file_path, "wb") as config_file:
            parser.write(config_file)
Esempio n. 7
0
    def write_config(self, params):
        self._check_required_params(["file", "section", "key", "value"], params, "move")
        """Write a key-value pair into an INI type config file."""
        # Get file
        config_file = self._get_file(params["file"])
        if not config_file:
            config_file = self._substitute(params["file"])

        # Create it if necessary
        basedir = os.path.dirname(config_file)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        parser = EvilConfigParser(allow_no_value=True, dict_type=MultiOrderedDict)
        parser.optionxform = str  # Preserve text case
        parser.read(config_file)

        if not parser.has_section(params["section"]):
            parser.add_section(params["section"])
        parser.set(params["section"], params["key"], params["value"])

        with open(config_file, "wb") as f:
            parser.write(f)