def _handle_global_configuration(): # print location of global configuration print(MSG_GLOBAL_SETTINGS_LOCATION.format(GLOBAL_CONFIG_PATH)) if os.path.isfile(ACTIVE_CONTEXT_CONFIG_PATH): # print location of the active env configuration if it exists print( MSG_ACTIVE_CONTEXT_SETTINGS_LOCATION.format( ACTIVE_CONTEXT_CONFIG_PATH)) # set up the config parsers file_config = configparser.SafeConfigParser() config_exists = file_config.read( [GLOBAL_CONFIG_PATH, ACTIVE_CONTEXT_CONFIG_PATH]) global_config = configparser.SafeConfigParser() global_config.read(GLOBAL_CONFIG_PATH) should_modify_global_config = False if config_exists: # print current config and prompt to allow global config modification _print_cur_configuration(file_config) should_modify_global_config = prompt_y_n(MSG_PROMPT_MANAGE_GLOBAL, default='n') answers['modify_global_prompt'] = should_modify_global_config if not config_exists or should_modify_global_config: # no config exists yet so configure global config or user wants to modify global config output_index = prompt_choice_list(MSG_PROMPT_GLOBAL_OUTPUT, OUTPUT_LIST, default=get_default_from_config(global_config, \ 'core', 'output', OUTPUT_LIST)) answers['output_type_prompt'] = output_index answers['output_type_options'] = str(OUTPUT_LIST) allow_telemetry = prompt_y_n(MSG_PROMPT_TELEMETRY, default='y') answers['telemetry_prompt'] = allow_telemetry # save the global config try: global_config.add_section('core') except configparser.DuplicateSectionError: pass global_config.set('core', 'output', OUTPUT_LIST[output_index]['name']) global_config.set('core', 'collect_telemetry', 'yes' if allow_telemetry else 'no') if not os.path.isdir(GLOBAL_CONFIG_DIR): os.makedirs(GLOBAL_CONFIG_DIR) with open(GLOBAL_CONFIG_PATH, 'w') as configfile: global_config.write(configfile)
def _handle_global_configuration(): # print location of global configuration print(MSG_GLOBAL_SETTINGS_LOCATION.format(GLOBAL_CONFIG_PATH)) if os.path.isfile(ACTIVE_CONTEXT_CONFIG_PATH): # print location of the active env configuration if it exists print(MSG_ACTIVE_CONTEXT_SETTINGS_LOCATION.format(ACTIVE_CONTEXT_CONFIG_PATH)) # set up the config parsers file_config = configparser.SafeConfigParser() config_exists = file_config.read([GLOBAL_CONFIG_PATH, ACTIVE_CONTEXT_CONFIG_PATH]) global_config = configparser.SafeConfigParser() global_config.read(GLOBAL_CONFIG_PATH) should_modify_global_config = False if config_exists: # print current config and prompt to allow global config modification _print_cur_configuration(file_config) should_modify_global_config = prompt_y_n(MSG_PROMPT_MANAGE_GLOBAL, default='n') answers['modify_global_prompt'] = should_modify_global_config if not config_exists or should_modify_global_config: # no config exists yet so configure global config or user wants to modify global config output_index = prompt_choice_list(MSG_PROMPT_GLOBAL_OUTPUT, OUTPUT_LIST, default=get_default_from_config(global_config, \ 'core', 'output', OUTPUT_LIST)) answers['output_type_prompt'] = output_index answers['output_type_options'] = str(OUTPUT_LIST) allow_telemetry = prompt_y_n(MSG_PROMPT_TELEMETRY, default='y') answers['telemetry_prompt'] = allow_telemetry # save the global config try: global_config.add_section('core') except configparser.DuplicateSectionError: pass global_config.set('core', 'output', OUTPUT_LIST[output_index]['name']) global_config.set('core', 'collect_telemetry', 'yes' if allow_telemetry else 'no') if not os.path.isdir(GLOBAL_CONFIG_DIR): os.makedirs(GLOBAL_CONFIG_DIR) with open(GLOBAL_CONFIG_PATH, 'w') as configfile: global_config.write(configfile)
def _handle_context_configuration(): envs = _get_envs() if envs: should_configure_envs = prompt_y_n(MSG_PROMPT_MANAGE_ENVS, default='n') answers['configure_envs_prompt'] = should_configure_envs if not should_configure_envs: return env_to_configure_index = prompt_choice_list(MSG_PROMPT_WHICH_CONTEXT, envs + \ ['Create new context (not yet supported)']) answers['env_to_configure_prompt'] = env_to_configure_index if env_to_configure_index == len(envs): # The last choice was picked by the user which corresponds to 'create new context' _create_or_update_env() else: # modify existing context _create_or_update_env(envs[env_to_configure_index]) else: # no env exists so create first context _create_or_update_env('default')