Ejemplo n.º 1
0
def _user_confirmed(confirmation, command_args):
    if callable(confirmation):
        return confirmation(command_args)
    try:
        if isinstance(confirmation, string_types):
            return prompt_y_n(confirmation)
        return prompt_y_n('Are you sure you want to perform this operation?')
    except NoTTYException:
        logger.warning('Unable to prompt for confirmation as no tty available. Use --yes.')
        return False
Ejemplo n.º 2
0
def _user_confirmed(confirmation, command_args):
    if callable(confirmation):
        return confirmation(command_args)
    try:
        if isinstance(confirmation, string_types):
            return prompt_y_n(confirmation)
        return prompt_y_n('Are you sure you want to perform this operation?')
    except NoTTYException:
        logger.warning(
            'Unable to prompt for confirmation as no tty available. Use --yes.'
        )
        return False
Ejemplo n.º 3
0
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
        enable_file_logging = prompt_y_n(MSG_PROMPT_FILE_LOGGING, default='n')
        # save the global config
        try:
            global_config.add_section('core')
        except configparser.DuplicateSectionError:
            pass
        try:
            global_config.add_section('logging')
        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')
        global_config.set('logging', 'enable_log_file',
                          'yes' if enable_file_logging 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)
Ejemplo n.º 4
0
def create(client,
           resource_group_name,
           account_name,
           sku_name,
           kind,
           location,
           tags=None,
           yes=None):

    terms = 'Notice\nMicrosoft will use data you send to the Cognitive'\
        'Services to improve Microsoft products and services.'\
        'For example we may use content that you provide to the Cognitive'\
        'Services to improve our underlying algorithms and models over time.'\
        'Where you send personal data to the Cognitive Services, you are responsible'\
        'for obtaining sufficient consent from the data subjects.'\
        'The General Privacy and Security Terms in the Online Services Terms '\
        '(https://www.microsoft.com/en-us/Licensing/product-licensing/products.aspx) '\
        'do not apply to the Cognitive Services.'\
        'You must comply with use and display requirements for the Bing Search APIs.'\
        '\n\nPlease refer to the Microsoft Cognitive Services section in the Online '\
        'Services Terms for details.'
    hint = '\nPlease select'
    if yes:
        logger.warning(terms)
    else:
        logger.warning(terms)
        option = prompt_y_n(hint)
        if not option:
            raise CLIError('Operation cancelled.')
    sku = Sku(sku_name)
    properties = {}
    params = CognitiveServicesAccountCreateParameters(sku, kind, location,
                                                      properties, tags)
    return client.create(resource_group_name, account_name, params)
def create(
        client, resource_group_name, account_name, sku_name, kind, location, tags=None, yes=None):

    terms = 'Notice\nMicrosoft will use data you send to the Cognitive'\
        'Services to improve Microsoft products and services.'\
        'Where you send personal data to the Cognitive Services, you are responsible '\
        'for obtaining sufficient consent from the data subjects.'\
        'The General Privacy and Security Terms in the Online Services Terms '\
        'do not apply to the Cognitive Services.'\
        'Please refer to the Microsoft Cognitive Services section in the Online '\
        'Services Terms'\
        ' (https://www.microsoft.com/en-us/Licensing/product-licensing/products.aspx)'\
        ' for details.'\
        'Microsoft offers policy controls that may be used to disable new Cognitive'\
        ' Services deployments (https://docs.microsoft.com/en-us/azure/cognitive-servic'\
        'es/cognitive-services-apis-create-account).'
    hint = '\nPlease select'
    if yes:
        logger.warning(terms)
    else:
        logger.warning(terms)
        option = prompt_y_n(hint)
        if not option:
            raise CLIError('Operation cancelled.')
    sku = Sku(sku_name)
    properties = {}
    params = CognitiveServicesAccountCreateParameters(sku, kind, location, properties, tags)
    return client.create(resource_group_name, account_name, params)
Ejemplo n.º 6
0
def _user_confirmation(message, yes=False):
    if yes:
        return
    try:
        if not prompt_y_n(message):
            raise CLIError('Operation cancelled.')
    except NoTTYException:
        raise CLIError('Unable to prompt for confirmation as no tty available. Use --yes.')
Ejemplo n.º 7
0
def _deprecate_warning():
    logger.warning("The 'component' commands will be deprecated in the future.")
    logger.warning("az component and subcommands may not work unless the CLI is installed with pip.")
    try:
        ans = prompt_y_n("Are you sure you want to continue?", default='n')
        if not ans:
            raise CLIError('Operation cancelled.')
    except NoTTYException:
        pass
Ejemplo n.º 8
0
def _handle_global_configuration():
    # print location of global configuration
    print(MSG_GLOBAL_SETTINGS_LOCATION.format(GLOBAL_CONFIG_PATH))
    # set up the config parsers
    file_config = get_config_parser()
    config_exists = file_config.read([GLOBAL_CONFIG_PATH])
    global_config = get_config_parser()
    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)
        enable_file_logging = prompt_y_n(MSG_PROMPT_FILE_LOGGING, default='n')
        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
        try:
            global_config.add_section('logging')
        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')
        global_config.set('logging', 'enable_log_file', 'yes' if enable_file_logging else 'no')
        set_global_config(global_config)
Ejemplo n.º 9
0
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')
Ejemplo n.º 10
0
def ext_add_has_confirmed(command_args):
    return bool(
        not command_args.get('source')
        or prompt_y_n('Are you sure you want to install this extension?'))