コード例 #1
0
ファイル: config.py プロジェクト: dron1/lago
    def update_parser(self, parser):
        """Update config dictionary with declared arguments in an argparse.parser
        New variables will be created, and existing ones overridden.

        Args:
            parser (argparse.ArgumentParser): parser to read variables from

        """

        self._parser = parser
        ini_str = argparse_to_ini(parser)
        configp = configparser.ConfigParser(allow_no_value=True)
        configp.read_dict(self._config)
        configp.read_string(ini_str)
        self._config.update(
            {s: dict(configp.items(s))
             for s in configp.sections()})
コード例 #2
0
ファイル: config.py プロジェクト: nirs/lago
    def update_parser(self, parser):
        """Update config dictionary with declared arguments in an argparse.parser
        New variables will be created, and existing ones overridden.

        Args:
            parser (argparse.ArgumentParser): parser to read variables from

        """

        self._parser = parser
        ini_str = argparse_to_ini(parser)
        configp = configparser.ConfigParser(allow_no_value=True)
        configp.read_dict(self._config)
        configp.read_string(ini_str)
        self._config.update(
            {s: dict(configp.items(s))
             for s in configp.sections()}
        )
コード例 #3
0
    def get_ini(self, defaults_only=False, incl_unset=False):
        """Return the config dictionary in INI format
        Args:
            defaults_only (bool): if set, will ignore arguments set by the CLI.

        Returns:
            str: string of the config file in INI format

        """
        if self._parser:
            if not defaults_only:
                self._parser.set_defaults(
                    **self.get_section(self.root_section))
            return argparse_to_ini(parser=self._parser, incl_unset=incl_unset)
        else:
            configp = configparser.ConfigParser(allow_no_value=True)
            configp.read_dict(self._config)
            with StringIO() as out_ini:
                configp.write(out_ini)
                return out_ini.getvalue()
コード例 #4
0
ファイル: config.py プロジェクト: lago-project/lago
    def get_ini(self, defaults_only=False, incl_unset=False):
        """Return the config dictionary in INI format
        Args:
            defaults_only (bool): if set, will ignore arguments set by the CLI.

        Returns:
            str: string of the config file in INI format

        """
        if self._parser:
            if not defaults_only:
                self._parser.set_defaults(
                    **self.get_section(self.root_section)
                )
            return argparse_to_ini(parser=self._parser, incl_unset=incl_unset)
        else:
            configp = configparser.ConfigParser(allow_no_value=True)
            configp.read_dict(self._config)
            with StringIO() as out_ini:
                configp.write(out_ini)
                return out_ini.getvalue()
コード例 #5
0
ファイル: config.py プロジェクト: dron1/lago
    def get_ini(self, incl_unset=False):
        """Return the config dictionary in INI format
        Args:
            incl_unset (bool): include variables with no defaults.

        Returns:
            str: string of the config file in INI format

        """

        configp = configparser.ConfigParser(allow_no_value=True)
        configp.read_dict(self._config)
        with StringIO() as config_ini:
            if self._parser:
                self._parser.set_defaults(
                    **self.get_section(self.root_section))
                argparse_ini = argparse_to_ini(parser=self._parser,
                                               incl_unset=incl_unset)
                return argparse_ini
            else:
                configp.write(config_ini)
                return config_ini.getvalue()
コード例 #6
0
ファイル: config.py プロジェクト: nirs/lago
    def get_ini(self, incl_unset=False):
        """Return the config dictionary in INI format
        Args:
            incl_unset (bool): include variables with no defaults.

        Returns:
            str: string of the config file in INI format

        """

        configp = configparser.ConfigParser(allow_no_value=True)
        configp.read_dict(self._config)
        with StringIO() as config_ini:
            if self._parser:
                self._parser.set_defaults(
                    **self.get_section(self.root_section)
                )
                argparse_ini = argparse_to_ini(
                    parser=self._parser, incl_unset=incl_unset
                )
                return argparse_ini
            else:
                configp.write(config_ini)
                return config_ini.getvalue()