def _set_defaults(cfg): env = _identifier_environments[IDENTIFIER_ENVIRONMENT] config.add_section('client') cfg.set('client', "service_url", env["service_url"]) cfg.set('client', "client_id", env["client_id"]) cfg.set('client', "scope", env["scope"]) config.add_section('tokens') cfg.set('tokens', 'access_token', '') cfg.set('tokens', 'access_token_expires', '0') cfg.set('tokens', 'refresh_token', '') config = ConfigParser() def _save(): with open(IDENTIFIER_CONFIG_FILE, 'w') as configfile: config.write(configfile) # Monkey-patch config so other things can call # config.save() without having to care about file # location. config.save = _save if path.exists(IDENTIFIER_CONFIG_FILE): config.read(IDENTIFIER_CONFIG_FILE) else: _set_defaults(config)