def test_is_valid_name(self): for name in [ "abc", "123", "____", "_", "a_b", "a_1", "1_b", "ABC" ]: self.assertTrue(TaskID.is_valid_name(name)) for name in [ "a.1", None, "%abc", "", " " ]: self.assertFalse(TaskID.is_valid_name(name))
def __init__(self, name, rtcfg, run_mode, start_point): if not TaskID.is_valid_name(name): raise TaskDefError("Illegal task name: %s" % name) self.run_mode = run_mode self.rtconfig = rtcfg self.start_point = start_point self.sequences = [] self.used_in_offset_trigger = False # some defaults self.max_future_prereq_offset = None self.sequential = False self.suite_polling_cfg = {} self.clocktrigger_offset = None self.expiration_offset = None self.namespace_hierarchy = [] self.dependencies = {} self.outputs = set() self.graph_children = {} self.graph_parents = {} self.param_var = {} self.external_triggers = [] self.xtrig_labels = {} # {sequence: [labels]} self.name = name self.elapsed_times = deque(maxlen=self.MAX_LEN_ELAPSED_TIMES)
def __init__(self, name, rtcfg, run_mode, start_point, spawn_ahead): if not TaskID.is_valid_name(name): raise TaskDefError("Illegal task name: %s" % name) self.run_mode = run_mode self.rtconfig = rtcfg self.start_point = start_point self.spawn_ahead = spawn_ahead self.sequences = [] self.used_in_offset_trigger = False # some defaults self.max_future_prereq_offset = None self.intercycle_offsets = set([]) self.sequential = False self.suite_polling_cfg = {} self.clocktrigger_offset = None self.expiration_offset = None self.namespace_hierarchy = [] self.dependencies = {} self.outputs = [] self.param_var = {} self.external_triggers = [] self.xtrig_labels = set() self.xclock_label = None # Note a task can only have one clock xtrigger - if it depends on # several we just keep the label of the one with the largest offset # (this is determined and set during suite config parsing, to avoid # storing the offset here in the taskdef). self.name = name self.elapsed_times = deque(maxlen=self.MAX_LEN_ELAPSED_TIMES)
def main(_, options, suite, *task_args): """Implement "cylc show" CLI.""" pclient = SuiteRuntimeClient(suite, timeout=options.comms_timeout) json_filter = {} if not task_args: query = WORKFLOW_META_QUERY query_kwargs = { 'request_string': query, 'variables': { 'wFlows': [suite] } } # Print suite info. results = pclient('graphql', query_kwargs) for workflow in results['workflows']: flat_data = flatten_data(workflow) if options.json: json_filter.update(flat_data) else: for key, value in sorted(flat_data.items(), reverse=True): ansiprint( f'<bold>{key}:</bold> {value or "<m>(not given)</m>"}') task_names = [arg for arg in task_args if TaskID.is_valid_name(arg)] task_ids = [arg for arg in task_args if TaskID.is_valid_id_2(arg)] if task_names: tasks_query = TASK_META_QUERY tasks_kwargs = { 'request_string': tasks_query, 'variables': { 'wFlows': [suite], 'taskIds': task_names } } # Print suite info. results = pclient('graphql', tasks_kwargs) multi = len(results['tasks']) > 1 for task in results['tasks']: flat_data = flatten_data(task['meta']) if options.json: json_filter.update({task['name']: flat_data}) else: if multi: print(f'----\nTASK NAME: {task["name"]}') for key, value in sorted(flat_data.items(), reverse=True): ansiprint( f'<bold>{key}:</bold> {value or "<m>(not given)</m>"}') if task_ids: tp_query = TASK_PREREQS_QUERY tp_kwargs = { 'request_string': tp_query, 'variables': { 'wFlows': [suite], 'taskIds': [ f'{c}{ID_DELIM}{n}' for n, c in [ TaskID.split(t_id) for t_id in task_ids if TaskID.is_valid_id(t_id) ] ] + [ f'{c}{ID_DELIM}{n}' for c, n in [ t_id.rsplit(TaskID.DELIM2, 1) for t_id in task_ids if not TaskID.is_valid_id(t_id) ] ] } } results = pclient('graphql', tp_kwargs) multi = len(results['taskProxies']) > 1 for t_proxy in results['taskProxies']: task_id = TaskID.get(t_proxy['name'], t_proxy['cyclePoint']) if options.json: json_filter.update({task_id: t_proxy}) else: if multi: print(f'----\nTASK ID: {task_id}') prereqs = [] for item in t_proxy['prerequisites']: prefix = '' multi_cond = len(item['conditions']) > 1 if multi_cond: prereqs.append([ True, '', item['expression'].replace('c', ''), item['satisfied'] ]) for cond in item['conditions']: if multi_cond and not options.list_prereqs: prefix = f'\t{cond["exprAlias"].strip("c")} = ' _, _, point, name = cond['taskId'].split(ID_DELIM) cond_id = TaskID.get(name, point) prereqs.append([ False, prefix, f'{cond_id} {cond["reqState"]}', cond['satisfied'] ]) if options.list_prereqs: for composite, _, msg, _ in prereqs: if not composite: print(msg) else: flat_meta = flatten_data(t_proxy['task']['meta']) for key, value in sorted(flat_meta.items(), reverse=True): ansiprint(f'<bold>{key}:</bold>' f' {value or "<m>(not given)</m>"}') ansiprint('\n<bold>prerequisites</bold>' ' (<red>- => not satisfied</red>):') if not prereqs: print(' (None)') for _, prefix, msg, state in prereqs: print_msg_state(f'{prefix}{msg}', state) ansiprint('\n<bold>outputs</bold>' ' (<red>- => not completed</red>):') if not t_proxy['outputs']: print(' (None)') for key, val in t_proxy['outputs'].items(): print_msg_state(f'{task_id} {key}', val) if t_proxy['extras']: print('\nother:') for key, value in t_proxy['extras'].items(): print(' o %s ... %s' % (key, value)) if not results['taskProxies']: ansiprint(f"<red>No matching tasks found: {task_ids}", file=sys.stderr) sys.exit(1) if options.json: print(json.dumps(json_filter, indent=4))
def main(_, options, suite, *task_args): """Implement "cylc show" CLI.""" pclient = SuiteRuntimeClient(suite, options.owner, options.host, options.port, options.comms_timeout) json_filter = [] if not task_args: # Print suite info. suite_info = pclient('get_suite_info') if options.json: json_filter.append(suite_info) else: for key, value in sorted(suite_info.items(), reverse=True): ansiprint( f'<bold>{key}:</bold> {value or "<m>(not given)</m>"}') task_names = [arg for arg in task_args if TaskID.is_valid_name(arg)] task_ids = [arg for arg in task_args if TaskID.is_valid_id_2(arg)] if task_names: results = pclient('get_task_info', {'names': task_names}) if options.json: json_filter.append(results) else: for task_name, result in sorted(results.items()): if len(results) > 1: print("----\nTASK NAME: %s" % task_name) for key, value in sorted(result.items(), reverse=True): ansiprint( f'<bold>{key}:</bold> {value or "<m>(not given)</m>"}') if task_ids: results, bad_items = pclient('get_task_requisites', { 'task_globs': task_ids, 'list_prereqs': options.list_prereqs }) if options.json: json_filter.append(results) else: for task_id, result in sorted(results.items()): if len(results) > 1: print("----\nTASK ID: %s" % task_id) if options.list_prereqs: for prereq in result["prerequisites"]: print(prereq) else: for key, value in sorted(result["meta"].items(), reverse=True): ansiprint(f'<bold>{key}:</bold>' f' {value or "<m>(not given)</m>"}') for name, done in [("prerequisites", "satisfied"), ("outputs", "completed")]: ansiprint(f'\n<bold>{name}</bold>' f' (<red>- => not {done}</red>):') if not result[name]: print(' (None)') for msg, state in result[name]: if state: ansiprint(f'<green> + {msg}</green>') else: ansiprint(f'<red> - {msg}</red>') if result["extras"]: print('\nother:') for key, value in result["extras"].items(): print(' o %s ... %s' % (key, value)) for bad_item in bad_items: ansiprint(f"<red>No matching tasks found: {bad_item}\n", file=sys.stderr) if bad_items: sys.exit(1) if options.json: print(json.dumps(json_filter, indent=4))