예제 #1
0
def _choose_attachment(attachments):
    """Let user choose from multiple attachments. Attachments with duplicate names will display their id."""
    attachment_map = _create_attachment_map(attachments)
    choices = list(attachment_map.keys())

    answer = io.multi_choice('Multiple attachments found. Choose which one to import:', choices)
    return attachment_map[answer]
예제 #2
0
def _get_principal_type(args):
    principal_name = args.receiver
    if args.user:
        if not user_exists(principal_name):
            raise McmdError('No user found with name %s' % principal_name)
        return PrincipalType.USER
    elif args.role:
        if not role_exists(principal_name):
            raise McmdError('No role found with name %s' % principal_name)
        return PrincipalType.ROLE
    else:
        # No principal type specified, let's guess it
        results = dict()
        for principal_type in PrincipalType:
            if principal_exists(principal_name, principal_type):
                results[principal_type.value] = principal_name

        if len(results) == 0:
            raise McmdError('No principals found with name %s' % principal_name)
        elif len(results) > 1:
            choices = results.keys()
            answer = multi_choice('Multiple principals found with name %s. Choose one:' % principal_name, choices)
            return PrincipalType[answer.upper()]
        else:
            return PrincipalType[list(results)[0].upper()]
예제 #3
0
def _get_resource_type(args):
    resource_id = args.resource
    if args.entity_type:
        ensure_resource_exists(resource_id, ResourceType.ENTITY_TYPE)
        return ResourceType.ENTITY_TYPE
    elif args.package:
        ensure_resource_exists(resource_id, ResourceType.PACKAGE)
        return ResourceType.PACKAGE
    elif args.plugin:
        ensure_resource_exists(resource_id, ResourceType.PLUGIN)
        return ResourceType.PLUGIN
    else:
        # No resource type specified, let's guess it
        results = dict()
        for resource_type in ResourceType:
            if resource_exists(resource_id, resource_type):
                results[resource_type.get_label()] = resource_id

        if len(results) == 0:
            raise McmdError('No resources found with id %s' % resource_id)
        elif len(results) > 1:
            choices = results.keys()
            answer = multi_choice('Multiple resources found for id %s. Choose one:' % resource_id, choices)
            return ResourceType.of_label(answer)
        else:
            return ResourceType.of_label(list(results)[0])
def config_set_host(args):
    if args.url:
        url = args.url
    else:
        auths = config.get('host', 'auth')
        urls = [auth['url'] for auth in auths]
        url = io.multi_choice('Please select a host:', urls)

    io.start("Switching to host {}".format(highlight(url)))
    config.set_host(url)
def _choose_file(paths, name):
    """
    _choose_file asks the user to choose a file out of the possible file paths
    :param paths: the list of paths to the file
    :param name: the filename
    :return: the selected path
    """
    choices = [str(path) for path in paths]
    answer = io.multi_choice('Multiple files found for %s. Pick one:' % name,
                             choices)
    return Path(answer)
예제 #6
0
def _guess_resource_type(resource_id):
    results = dict()
    for resource_type in ResourceType:
        if resource_exists(resource_id, resource_type):
            results[resource_type.get_label()] = resource_id

    if len(results) == 0:
        raise McmdError('No resources found with id %s' % resource_id)
    elif len(results) > 1:
        choices = results.keys()
        answer = multi_choice(
            'Multiple resources found for id %s. Choose one:' % resource_id,
            choices)
        return ResourceType.of_label(answer)
    else:
        return ResourceType.of_label(list(results)[0])
예제 #7
0
def _guess_principal_type(principal_name):
    results = dict()
    for principal_type in PrincipalType:
        if principal_exists(principal_name, principal_type):
            results[principal_type.value] = principal_name

    if len(results) == 0:
        raise McmdError('No principals found with name %s' % principal_name)
    elif len(results) > 1:
        choices = results.keys()
        answer = multi_choice(
            'Multiple principals found with name %s. Choose one:' %
            principal_name, choices)
        return PrincipalType[answer.upper()]
    else:
        return PrincipalType[list(results)[0].upper()]
예제 #8
0
def _choose_file(paths, name):
    choices = [str(path) for path in paths]
    answer = io.multi_choice('Multiple files found for %s. Pick one:' % name, choices)
    return Path(answer)