Esempio n. 1
0
def choose_sandbox(verb, name=None, selector=None, enforce=True, allow_multi_matches=False, msg=None, display_only_matches=False):
    '''
    Figure out which sandbox(es) user wants to operate on.
    '''
    sb = None
    if name=='all':
        name='*'
    elif name == 'last':
        mostRecentlyStarted = sadm_sandbox.list_recent_starts(1)
        if not mostRecentlyStarted:
            return []
        name = mostRecentlyStarted[0][0]
    # Depending on how we're called, we might get either a name as the first
    # arg and a selector as the second, a name with no selector, or a selector
    # as the first arg and no name. In the latter case, swap args so we
    # interpret correctly.
    if (not (name is None)) and (type(name) == _FUNC_TYPE) and (selector is None):
        selector = name
        name = '*'
    sandboxes = sandbox.list(config.sandbox_container_folder)
    if not name:
        sb = _prompt_for_sandbox(verb, sandboxes, selector, allow_multi_matches, msg, display_only_matches)
    else:
        sb = sadm_sandbox.get_by_name_pattern(sandboxes, name, allow_multi_matches)
        if sb and enforce and (not (selector is None)):
            sb = [s for s in sb if _validate_sandbox_choice(s, selector, verb)]
        if sb and not allow_multi_matches:
            sb = sb[0]
    return sb
Esempio n. 2
0
def _prompt_for_sandbox(verb,
                        sandboxes=None,
                        selector=None,
                        allow_multi_matches=False,
                        msg=None,
                        display_only_matches=False):
    if not prompter.can_interact():
        return
    prompter.set_mode(INTERACTIVE_MODE)
    if sandboxes is None:
        sandboxes = sandbox.list(config.sandbox_container_folder)
    if not sandboxes:
        print('No sandboxes defined.')
        return
    # If we're trying to allow selection of just a subset -- either ones
    # that have active ctest instances, or ones that don't -- then check
    # whether that is even valid.
    subset = not (selector is None)
    if subset:
        if count(sandboxes, selector) == 0:
            print('No sandboxes support %s right now.' % verb)
            return
    list_sandboxes(sandboxes,
                   selector,
                   choose=True,
                   display_only_matches=display_only_matches)
    print('')
    if not msg:
        msg = 'Sandbox?'
        if allow_multi_matches:
            msg += ' (wildcards match name; * or "all"=all)'
    which = prompt(msg)
    if not which:
        return
    if which == 'all':
        which = '*'
    selected = []
    if which[0].isdigit():
        which = int(which)
        if which < 1 or which > len(sandboxes):
            invalid = True
        else:
            selected.append(sandboxes[which - 1])
    else:
        selected = get_by_name_pattern(sandboxes, which, allow_multi_matches)
    if not selected:
        print('No match for sandbox "%s".' % str(which))
    selected = [
        sb for sb in selected if _validate_sandbox_choice(sb, selector, verb)
    ]
    if allow_multi_matches:
        return selected
    return selected[0]
Esempio n. 3
0
def _prompt_for_sandbox(verb, sandboxes=None, selector=None, allow_multi_matches=False, msg=None, display_only_matches=False):
    if not prompter.can_interact():
        return
    prompter.set_mode(INTERACTIVE_MODE)
    if sandboxes is None:
        sandboxes = sandbox.list(config.sandbox_container_folder)
    if not sandboxes:
        print('No sandboxes defined.')
        return
    # If we're trying to allow selection of just a subset -- either ones
    # that have active ctest instances, or ones that don't -- then check
    # whether that is even valid.
    subset = not (selector is None)
    if subset:
        if count(sandboxes, selector) == 0:
            print('No sandboxes support %s right now.' % verb)
            return
    list_sandboxes(sandboxes, selector, choose=True, display_only_matches=display_only_matches)
    print('')
    if not msg:
        msg = 'Sandbox?'
        if allow_multi_matches:
            msg += ' (wildcards match name; * or "all"=all)'
    which = prompt(msg)
    if not which:
        return
    if which=='all':
        which='*'
    selected = []
    if which[0].isdigit():
        which = int(which)
        if which < 1 or which > len(sandboxes):
            invalid = True
        else:
            selected.append(sandboxes[which - 1])
    else:
        selected = get_by_name_pattern(sandboxes, which, allow_multi_matches)
    if not selected:
        print('No match for sandbox "%s".' % str(which))
    selected = [sb for sb in selected if _validate_sandbox_choice(sb, selector, verb)]
    if allow_multi_matches:
        return selected
    return selected[0]
Esempio n. 4
0
def choose_sandbox(verb,
                   name=None,
                   selector=None,
                   enforce=True,
                   allow_multi_matches=False,
                   msg=None,
                   display_only_matches=False):
    '''
    Figure out which sandbox(es) user wants to operate on.
    '''
    sb = None
    if name == 'all':
        name = '*'
    elif name == 'last':
        mostRecentlyStarted = sadm_sandbox.list_recent_starts(1)
        if not mostRecentlyStarted:
            return []
        name = mostRecentlyStarted[0][0]
    # Depending on how we're called, we might get either a name as the first
    # arg and a selector as the second, a name with no selector, or a selector
    # as the first arg and no name. In the latter case, swap args so we
    # interpret correctly.
    if (not (name is None)) and (type(name)
                                 == _FUNC_TYPE) and (selector is None):
        selector = name
        name = '*'
    sandboxes = sandbox.list(config.sandbox_container_folder)
    if not name:
        sb = _prompt_for_sandbox(verb, sandboxes, selector,
                                 allow_multi_matches, msg,
                                 display_only_matches)
    else:
        sb = sadm_sandbox.get_by_name_pattern(sandboxes, name,
                                              allow_multi_matches)
        if sb and enforce and (not (selector is None)):
            sb = [s for s in sb if _validate_sandbox_choice(s, selector, verb)]
        if sb and not allow_multi_matches:
            sb = sb[0]
    return sb