How to use configparser - 10 common examples

To help you get started, we’ve selected a few configparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Python-Markdown / markdown / tests / util.py View on Github external
def get(self, section, option):  value = ConfigParser.get(self, section, option) if option == 'extensions': if len(value.strip()): return value.split(',') else: return [] if value.lower() in ['yes', 'true', 'on', '1']: return True if value.lower() in ['no', 'false', 'off', '0']: return False return value
github olivierhagolle / Start_maja / test / test_Start_maja.py View on Github external
def modify_folders_file(root, new_file, **kwargs): """ Modify the template test_folders file with the given arguments :param root: The path to the existing template file :param new_file: The new file path :param kwargs: The arguments to modify inside the file :return: The full path to the new file """ try: import configparser as cfg except ImportError: import ConfigParser as cfg assert os.path.isfile(root)  cfg_parser = cfg.RawConfigParser() cfg_parser.read(root) for arg in kwargs: cfg_parser.set("PATH", arg, kwargs[arg]) with open(new_file, 'w') as f: cfg_parser.write(f) return new_file
github stb-tester / lirc / python-pkg / lirc / client.py View on Github external
if 'LIRC_SOCKET_PATH' in os.environ: return os.environ['LIRC_SOCKET_PATH'] path = lirc.config.SYSCONFDIR + '/lirc/lirc_options.conf' parser = configparser.SafeConfigParser() try: parser.read(path) except configparser.Error: pass else: if parser.has_section('lircd'): try: path = str(parser.get('lircd', 'output')) if os.path.exists(path): return path  except configparser.NoOptionError: pass return lirc.config.VARRUNDIR + '/lirc/lircd'
github getting-things-gnome / gtg / tests / core / test_config.py View on Github external
def test_falls_back_when_there_is_config_error(self, mock_log):  self.mock_parser.side_effect = configparser.Error() open_config_file('gtg.conf') self.mock_parser.assert_called_once_with('gtg.conf') self.assertTrue(mock_log.warning.called)
github datadotworld / data.world-py / tests / datadotworld / test_config.py View on Github external
def default_config_file(config_file_path): config_parser = configparser.ConfigParser()  config_parser.set(configparser.DEFAULTSECT, 'auth_token', 'file_token') config_parser.write(open(config_file_path, 'w'))
github aws / efs-utils / test / mount_efs_test / test_is_ocsp_enabled.py View on Github external
def _get_config(stunnel_check_cert_validity): try:  config = ConfigParser.SafeConfigParser() except AttributeError: config = ConfigParser() config.add_section(mount_efs.CONFIG_SECTION) if stunnel_check_cert_validity is not None: config.set(mount_efs.CONFIG_SECTION, 'stunnel_check_cert_validity', str(stunnel_check_cert_validity)) return config
github aws / efs-utils / test / mount_efs_test / test_add_stunnel_ca_options.py View on Github external
def _get_config(): try:  config = ConfigParser.SafeConfigParser() except AttributeError: config = ConfigParser() config.add_section(mount_efs.CONFIG_SECTION) return config
github aws / efs-utils / test / mount_efs_test / test_create_state_file_dir.py View on Github external
def _get_config(mode=None): try:  config = ConfigParser.SafeConfigParser() except AttributeError: config = ConfigParser() config.add_section(mount_efs.CONFIG_SECTION) if mode is not None: config.set(mount_efs.CONFIG_SECTION, 'state_file_dir_mode', mode) return config
github aws / efs-utils / test / watchdog_test / test_check_efs_mounts.py View on Github external
def _get_config(): try:  config = ConfigParser.SafeConfigParser() except AttributeError: config = ConfigParser() config.add_section(mount_efs.CONFIG_SECTION) config.set(mount_efs.CONFIG_SECTION, 'state_file_dir_mode', '750') return config
github JagandeepBrar / Plex-Assistant-Bot / backend / config.py View on Github external
def initParser(): global parser try:  parser = configparser.ConfigParser() parser.read(constants.CONFIG_FILE) if not(len(parser) > 1): raise Exception() logger.info(__name__, "Configparser initialized") except: logger.error(__name__, "Failed to load config.ini: Please ensure that a valid config file is located at {}".format(constants.CONFIG_FILE)) exit()