def test_list(self): path = os.path.dirname(os.path.abspath(__file__)) + '/data/testrunner_test' #print('listing sandboxes in %s' % path) items = sandbox.list(path) self.assertEqual(2, len(items)) # Guarantee that they come back in sorted order self.assertTrue(cmp(items[0], items[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
def list_sandboxes(sandboxes=None, selector=None, choose=False, display_only_matches=False): # If we're not in interactive mode, there's no point in numbering # the sandboxes so they can be selected. if not prompter.can_interact(): choose = False if choose: sep = DELIM_COLOR + ' - ' + NORMTXT else: sep = '' if not choose: runningMask = inertMask = '' if not sandboxes: sandboxes = sandbox.list(config.sandbox_container_folder) elif type(sandboxes) != type([]): sandboxes = choose_sandbox(None, sandboxes, allow_multi_matches=True) if not sandboxes: print('No sandboxes defined.') else: n = 1 for sb in sandboxes: id = '' if choose: id = str(n) if selector and not selector(sb): if display_only_matches: n += 1 continue id = ' '.rjust(len(id)) row = '' if id: if n < 10: row += ' ' row += PARAM_COLOR + id if sep: row += sep row += PARAM_COLOR + sb.get_name().ljust(35) row += DELIM_COLOR + ' - ' + NORMTXT if hasattr(sb, 'schedule') and (not (sb.schedule is None)): row += str(sb.schedule) else: if sb.get_sandboxtype().get_should_schedule( ) and not config.schedule_continuous_manually: row += 'auto-scheduled' else: row += 'unscheduled' if sb.get_sandboxtype().get_should_publish(): row += '; publishing enabled' if sb.is_locked(): row += ' (pid=%s)' % str(sb.get_lock_obj().pid) printc(row) n += 1
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]
def list_sandboxes(sandboxes=None, selector=None, choose=False, display_only_matches=False): # If we're not in interactive mode, there's no point in numbering # the sandboxes so they can be selected. if not prompter.can_interact(): choose = False if choose: sep = DELIM_COLOR + ' - ' + NORMTXT else: sep = '' if not choose: runningMask = inertMask = '' if not sandboxes: sandboxes = sandbox.list(config.sandbox_container_folder) elif type(sandboxes) != type([]): sandboxes = choose_sandbox(None, sandboxes, allow_multi_matches=True) if not sandboxes: print('No sandboxes defined.') else: n = 1 for sb in sandboxes: id = '' if choose: id = str(n) if selector and not selector(sb): if display_only_matches: n += 1 continue id = ' '.rjust(len(id)) row = '' if id: if n < 10: row += ' ' row += PARAM_COLOR + id if sep: row += sep row += PARAM_COLOR + sb.get_name().ljust(35) row += DELIM_COLOR +' - ' + NORMTXT if hasattr(sb, 'schedule') and (not (sb.schedule is None)): row += str(sb.schedule) else: if sb.get_sandboxtype().get_should_schedule() and not config.schedule_continuous_manually: row += 'auto-scheduled' else: row += 'unscheduled' if sb.get_sandboxtype().get_should_publish(): row += '; publishing enabled' if sb.is_locked(): row += ' (pid=%s)' % str(sb.get_lock_obj().pid) printc(row) n += 1
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]
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