def main(_, options, suite): """Implement cylc broadcast.""" pclient = SuiteRuntimeClient(suite, timeout=options.comms_timeout) mutation_kwargs = { 'request_string': MUTATION, 'variables': { 'wFlows': [suite], 'bMode': 'Set', 'cPoints': options.point_strings, 'nSpaces': options.namespaces, 'bSettings': options.settings, 'bCutoff': options.expire, } } query_kwargs = { 'request_string': QUERY, 'variables': { 'wFlows': [suite], 'nIds': [] } } if options.show or options.showtask: if options.showtask: try: task, point = TaskID.split(options.showtask) query_kwargs['variables']['nIds'] = [ f'{point}{ID_DELIM}{task}' ] except ValueError: raise UserInputError("TASKID must be " + TaskID.SYNTAX) result = pclient('graphql', query_kwargs) for wflow in result['workflows']: settings = wflow['broadcasts'] padding = get_padding(settings) * ' ' if options.raw: print(str(settings)) else: print_tree(settings, padding, options.unicode) sys.exit(0) report_cancel = True report_set = False if options.clear: mutation_kwargs['variables']['bMode'] = 'Clear' if options.expire: mutation_kwargs['variables']['bMode'] = 'Expire' # implement namespace and cycle point defaults here namespaces = options.namespaces if not namespaces: namespaces = ["root"] point_strings = options.point_strings if not point_strings: point_strings = ["*"] if options.cancel or options.cancel_files: settings = [] for option_item in options.cancel: if "=" in option_item: raise UserInputError( "--cancel=[SEC]ITEM does not take a value") option_item = option_item.strip() setting = get_rdict(option_item) settings.append(setting) files_to_settings(settings, options.cancel_files, options.cancel) mutation_kwargs['variables'].update({ 'bMode': 'Clear', 'cPoints': point_strings, 'nSpaces': namespaces, 'bSettings': settings, }) if options.settings or options.setting_files: settings = [] for option_item in options.settings: if "=" not in option_item: raise UserInputError("--set=[SEC]ITEM=VALUE requires a value") lhs, rhs = [s.strip() for s in option_item.split("=", 1)] setting = get_rdict(lhs, rhs) settings.append(setting) files_to_settings(settings, options.setting_files) mutation_kwargs['variables'].update({ 'bMode': 'Set', 'cPoints': point_strings, 'nSpaces': namespaces, 'bSettings': settings, }) report_cancel = False report_set = True results = pclient('graphql', mutation_kwargs) for result in results['broadcast']['result']: modified_settings = result['response'][0] bad_options = result['response'][1] if modified_settings: print( get_broadcast_change_report(modified_settings, is_cancel=report_cancel)) sys.exit(report_bad_options(bad_options, is_set=report_set))
def main(_, options, suite): """Implement cylc broadcast.""" pclient = SuiteRuntimeClient( suite, options.owner, options.host, options.port, options.comms_timeout) if options.show or options.showtask: if options.showtask: try: TaskID.split(options.showtask) except ValueError: raise UserInputError("TASKID must be " + TaskID.SYNTAX) settings = pclient('get_broadcast', {'task_id': options.showtask}) padding = get_padding(settings) * ' ' if options.raw: print(str(settings)) else: print_tree(settings, padding, options.unicode) sys.exit(0) if options.clear: modified_settings, bad_options = pclient( 'clear_broadcast', {'point_strings': options.point_strings, 'namespaces': options.namespaces} ) if modified_settings: print(get_broadcast_change_report( modified_settings, is_cancel=True)) sys.exit(report_bad_options(bad_options)) if options.expire: modified_settings, bad_options = pclient( 'expire_broadcast', {'cutoff': options.expire} ) if modified_settings: print(get_broadcast_change_report( modified_settings, is_cancel=True)) sys.exit(report_bad_options(bad_options)) # implement namespace and cycle point defaults here namespaces = options.namespaces if not namespaces: namespaces = ["root"] point_strings = options.point_strings if not point_strings: point_strings = ["*"] if options.cancel or options.cancel_files: settings = [] for option_item in options.cancel: if "=" in option_item: raise UserInputError( "--cancel=[SEC]ITEM does not take a value") option_item = option_item.strip() setting = get_rdict(option_item) settings.append(setting) files_to_settings(settings, options.cancel_files, options.cancel) modified_settings, bad_options = pclient( 'clear_broadcast', {'point_strings': point_strings, 'namespaces': namespaces, 'cancel_settings': settings} ) if modified_settings: print(get_broadcast_change_report( modified_settings, is_cancel=True)) sys.exit(report_bad_options(bad_options)) if options.settings or options.setting_files: settings = [] for option_item in options.settings: if "=" not in option_item: raise UserInputError( "--set=[SEC]ITEM=VALUE requires a value") lhs, rhs = [s.strip() for s in option_item.split("=", 1)] setting = get_rdict(lhs, rhs) settings.append(setting) files_to_settings(settings, options.setting_files) modified_settings, bad_options = pclient( 'put_broadcast', {'point_strings': point_strings, 'namespaces': namespaces, 'settings': settings } ) print(get_broadcast_change_report(modified_settings)) sys.exit(report_bad_options(bad_options, is_set=True))
def main(parser, options, regfilter=None): if regfilter: try: regfilter = re.compile(regfilter) except re.error as exc: raise ValueError("%s: %s" % (regfilter, exc)) allsuites = list( get_scan_items_from_fs(reg_pattern=regfilter, active_only=False)) if options.fail and not allsuites: raise SystemExit('ERROR: no suites matched.') if not options.tree: if options.align: maxlen_suite = 0 maxlen_title = 0 for suite, dir_, title in allsuites: if len(suite) > maxlen_suite: maxlen_suite = len(suite) if len(title) > maxlen_title: maxlen_title = len(title) spacer_suite = maxlen_suite * ' ' spacer_title = maxlen_title * ' ' for suite, dir_, title in allsuites: dir_ = re.sub('^' + os.environ['HOME'], '~', dir_) if options.align: suite = suite + spacer_suite[len(suite):] title = title + spacer_title[len(title):] if not options.x and not options.y: line = suite + ' | ' + title + ' | ' + dir_ elif not options.y: line = suite + ' | ' + title elif not options.x: line = suite + ' | ' + dir_ else: line = suite print(line) else: tree = {} if options.align: maxlen_title = 0 for suite, dir_, title in allsuites: if len(title) > maxlen_title: maxlen_title = len(title) spacer_title = maxlen_title * ' ' for suite, dir_, title in allsuites: dir_ = re.sub('^' + os.environ['HOME'], '~', dir_) if options.align: title = title + spacer_title[len(title):] regpath = suite.split(REG_DELIM) sub = tree for key in regpath[:-1]: if key not in sub: sub[key] = {} sub = sub[key] if not options.x and not options.y: line = title + ' | ' + dir_ elif not options.y: line = ' ' + title elif not options.x: line = ' ' + dir_ else: line = '' sub[regpath[-1]] = line pad = get_padding(allsuites) print_tree(tree, pad, options.unicode)