def main(): parser = argparse.ArgumentParser( description="Run Tutorterminal application.") parser.add_argument("files", metavar="files", type=str, nargs="+", help="the script files to run") args = parser.parse_args() files = args.files invalid_files = list( filter(lambda x: x[0], map(lambda x: (not os.path.isfile(x), x), files))) if invalid_files: for _, fname in invalid_files: files.remove(fname) ansiprint("<red>Warning - '{}' not found!</red>".format(fname)) num_scripts = len(files) for index in range(num_scripts): file = files[index] ansiprint( "<bold><light-blue>Running script [{}/{}] - <yellow>'{}'</yellow></light-blue>" .format(index + 1, num_scripts, file)) process(open(file).readlines())
def prompt(): ansiprint( "<bold><green>[In]</green></bold> <light-blue>" + os.path.abspath(".") + "</light-blue>$ ", end="", )
def checkfile(content, exists=True): if exists ^ os.path.exists(content): ansiprint("<fg red> Arquivo/diretório " + ("inexistente" if exists else "existente") + ": " + content + ". Procure por ajuda.") return False return True
def screen_out(filename, c_a_d, s_a_d, t_a_d, c_a, s_a, t_a, a_tad, a_oa, a_azi, a_ele, a_aor): """ Result output to screen :param filename: :param c_a_d: :param s_a_d: :param t_a_d: :param c_a: :param s_a: :param t_a: :param a_tad: :param a_oa: :param a_azi: :param a_ele: :param a_aor: """ ansiprint(f""" Copyright (C) 2020-{datetime.today().year} | Lorenz Peter Schweinsberg DVM | lorenz.schweinsberg@fu–berlin.de GNU GENERAL PUBLIC LICENSE Version 3 This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it under certain conditions; For details visit <https://www.gnu.org/licenses/>. Input Values: ============= {'coronal_component <red>C</red> [degrees] = ':>50}{c_a_d:6.1f} {'sagittal_component <red>S</red> [degrees] = ':>50}{s_a_d:6.1f} {'torsion_component <red>T</red> [degrees] = ':>50}{t_a_d:6.1f} Transformation of degrees in radians {'coronal_component C in rad = ':>39}{c_a:8.4f} {'sagittal_component S in rad = ':>39}{s_a:8.4f} {'torsion_component T in rad = ':>39}{t_a:8.4f} Calculation according to Sangeorzan, Judd (1989) ================================================ {'true angular deformity (15) A = ':>39}{degrees(a_tad):8.1f} degrees ({a_tad:8.4f} rad ) {'orientation angle (16) ':>35}{chr(945)}{'= ':>3}{degrees(a_oa):8.1f} degrees ({a_oa:8.4f} rad ) {'azimuth of vektor k (13) ':>35}{chr(int("3A6", 16))}{'= ':>3}{degrees(a_azi):8.1f} degrees ({a_azi:8.4f} rad ) {'elevation of vector k (12) ':>35}{chr(int("398", 16))}{'= ':>3}{degrees(a_ele):8.1f} degrees ({a_ele:8.4f} rad ) {'angle of rotation around k (14) ':>35}{chr(int("3B2", 16))}{'= ':>3}{degrees(a_aor):8.1f} degrees ({a_aor:8.4f} rad ) results are stored in {filename} """)
def print_qa(qa): qa_body = json.loads(qa) qa_str = pformat(qa_body, indent=2) try: for answer in qa_body['answers']: original_span = answer['original_span'] if original_span != '': qa_str = highlight(original_span, qa_str) except KeyError as e: print(f'[ERROR]: {e}') ansiprint(qa_str)
async def run(self, grbl, cli, opts, args, extra_input): msg = ''' <b>Grblcom commands:</b> <b>%run [-m|--mode=sync,async] [file]</b> TODO: <b>%check [-m|--mode=sync,async] [file]</b> TODO: ''' ansiprint(textwrap.dedent(msg).strip())
def print(self) -> None: """Prints this model plan to the terminal in a readable format.""" ansiprint(f"<b><white>{self.config.model.__name__}:</white></b>") for partition in self.deletions: ansiprint("<b><red> - %s</red></b>" % partition.name()) for key, value in partition.deconstruct().items(): ansiprint(f"<white> <b>{key}</b>: {value}</white>") for partition in self.creations: ansiprint("<b><green> + %s</green></b>" % partition.name()) for key, value in partition.deconstruct().items(): ansiprint(f"<white> <b>{key}</b>: {value}</white>")
def process(script): processing = "" tmp_processing = "" for line in script: if processing: if line.strip() == "###": f_open = open(processing, "w") f_open.write(tmp_processing) f_open.close() processing = "" tmp_processing = [] tmp_processing += line continue if not line.strip(): continue line = line.strip() if " " not in line: line += " " command, content = line.split(" ", 1) content = content.strip() if command == "!checkfile": # checkfile not exists if not checkfile(content, False): exit(1) if command == "checkfile": # checkfile if not checkfile(content): exit(1) if command == "##": ansiprint(content) if command == "#": ansiprint(content) if command == "enter": enter() if command == "run_free": if not run_command(content, free=True): exit(1) if command == "run": if not run_command(content): exit(1) if command == "run_auto": if not run_command(content, auto=True): exit(1) if command == "###": processing = content
def run_command(content, free=False, auto=False): user_input = content if auto: prompt() ansiprint(content) else: user_input = shlex.split(query_user(content)) output = "<bold><red>[Out]</red></bold> " err = "<bold><red>[ERR]</red></bold> " with subprocess.Popen( user_input, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) as process: for line in process.stdout.readlines(): ansiprint(output + line.decode("utf-8"), end="") for line in process.stderr.readlines(): ansiprint(err + line.decode("utf-8"), end="") process.wait() if process.returncode != 0: ansiprint( "Algo parece ter dado errado... procure por ajuda ou verifique os comandos executados." ) return False return True
def print(self) -> None: """Prints this plan to the terminal in a readable format.""" for model_plan in self.model_plans: model_plan.print() print("") create_count = len(self.creations) delete_count = len(self.deletions) ansiprint( f"<b><red>{delete_count} partitions will be deleted</red></b>") ansiprint( f"<b><green>{create_count} partitions will be created</green></b>")
async def __call__(self, grbl, cli, input_line: str, request_input: typing.Callable): args, opts = None, None if self._parser: args = shlex.split(input_line)[1:] try: opts, _ = self._parser.parse_known_args(args) except argparse.ArgumentError as error: ansiprint(f'<r>error: {error}</r>') return msg = 'Command "%s" called with arguments "%s" parsed into "%s"' log.debug(msg, self.__class__.__name__, args, opts) return await self.run(grbl, cli, opts, request_input)
def main(): _parse_args() try: password = generate_password(app_settings.count, app_settings.lower_case, \ app_settings.upper_case, app_settings.numbers, \ app_settings.punctuation, app_settings.exclude) ansiprint(f'<b,g,>Password: </b,g,><b,w,>{password}</b,w,>') except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stderr) return 1 return 0
def query_user(content): fancy_input = lambda: prompt() or input() user_input = fancy_input() while not user_input: ansiprint("Comando nao pode ser vazio.") user_input = fancy_input() while not re.match(content, user_input): ansiprint( "<fg red>Certeza que deseja continuar? A entrada parece ser diferente do indicado.</fg red> <bold>[s/N]</bold> ", end="", ) user_test = input() if user_test == "n" or not user_test: user_input = fancy_input() else: break return user_input
def screen_out(filename, c_a_d, s_a_d, t_a_d, c_a, s_a, t_a, a_tad, a_oa, a_azi, a_ele, a_aor): """ Result output to screen :param filename: :param c_a_d: :param s_a_d: :param t_a_d: :param c_a: :param s_a: :param t_a: :param a_tad: :param a_oa: :param a_azi: :param a_ele: :param a_aor: """ ansiprint(f""" Input Values: {'coronal_component <red>C</red> [degrees] = ':>50}{c_a_d:6.1f} {'sagittal_component <red>S</red> [degrees] = ':>50}{s_a_d:6.1f} {'torsion_component <red>T</red> [degrees] = ':>50}{t_a_d:6.1f} Transformation of degrees in radians {'coronal_component C in rad = ':>39}{c_a:8.4f} {'sagittal_component S in rad = ':>39}{s_a:8.4f} {'torsion_component T in rad = ':>39}{t_a:8.4f} Calculation according to Sangeorzan, Judd (1989) {'true angular deformity (15) A = ':>39}{degrees(a_tad):8.1f} degrees ({a_tad:8.4f} rad ) {'orientation angle (16) ':>35}{chr(945)}{'= ':>3}{degrees(a_oa):8.1f} degrees ({a_oa:8.4f} rad ) {'azimuth of vektor k (13) ':>35}{chr(int("3A6", 16))}{'= ':>3}{degrees(a_azi):8.1f} degrees ({a_azi:8.4f} rad ) {'angle of rotation (12) ':>35}{chr(int("398", 16))}{'= ':>3}{degrees(a_ele):8.1f} degrees ({a_ele:8.4f} rad ) {'angle of rotation around k (14) ':>35}{chr(int("3B2", 16))}{'= ':>3}{degrees(a_aor):8.1f} degrees ({a_aor:8.4f} rad ) results are stored in {filename} """)
def query_and_test(): """Use `q` to query server, get contexts, and query_all pipelines""" n = len(q) + 4 ansiprint(h1('*'*n)) ansiprint(h1('* ') + h2(q) + h1(' *')) ansiprint(h1('*'*n)) pprint(requests.post(ep,json={'question':q}).json()) get_ctx_by_query(q) for ctx in ctxs: ansiprint(h1('docId: ') + h2(ctx['_id'])) query_all(q, ctx)
def workflow_meta_query(workflow_id, pclient, options, json_filter): query = WORKFLOW_META_QUERY query_kwargs = { 'request_string': query, 'variables': { 'wFlows': [workflow_id] } } # Print workflow info. results = pclient('graphql', query_kwargs) for workflow_id in results['workflows']: flat_data = flatten_data(workflow_id) 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>"}') return 0
def task_meta_query(workflow_id, task_names, pclient, options, json_filter): tasks_query = TASK_META_QUERY tasks_kwargs = { 'request_string': tasks_query, 'variables': { 'wFlows': [workflow_id], 'taskIds': task_names, }, } # Print workflow 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>"}') return 0
def query_all(question,context): """Get answer to question given context for all pipelines""" if isinstance(context,dict): context = context['text'] ansiprint(h1('question:') + ' ' + h2(question)) ansiprint(h1('context:')) ctx_ = textwrap.fill(context, 60) ctx_ = textwrap.indent(ctx_, ' -- ') print(ctx_) for name,pipeline in pipelines.items(): ansiprint(h3(name)) answer = pipeline({'question':question, 'context':context}, handle_impossible_answer=True) pprint(answer) b,e = answer['start'],answer['end'] context_ = context[max(b-30,0):e+30] b_ = 30 - max(0,30-b) e_ = b_ + e-b t1,t2,t3 = context_[0:b_],context_[b_:e_],context_[e_:] ansiprint(t1 + h2(t2) + t3)
async def sync_run(self, grbl: SerialGrbl, gcode, break_on_error=True): with grbl.control_queue_ctx(): for line in gcode: await grbl.write(line.encode('ascii')) res = await grbl.active_queue.get() ansiprint(f'{line} ... ', end='') if res == 'ok': ansiprint('<b><g>ok</g></b>') elif res.startswith('error:'): ansiprint(f'<b><r>{res}</r></b>') if break_on_error: break else: await grbl.stdout_queue.put(res)
async def reader_coro(grbl, cli, loop): while True: line = await grbl.stdout_queue.get() # TODO: Using print_tokens/tprint causes strange text output issues # TODO: when combined with patch_stdout. We'll just use another # TODO: terminal colorization method for now. if line == 'ok': ansiprint('<b><g>ok</g></b>') #tprint((Token.Ok, line), output=cli.output) elif line.startswith('Grbl') and line.endswith(']'): ansiprint(f'<b>{line}</b>') # elif line.startswith('<') and line.endswith('>'): # ansiprint(f'<b>{line}</b>') elif line.startswith('error:'): msg = line.split(':', 1)[-1] ansiprint(f'<b><r>error:</r></b>{msg}') elif line[0] == '[' and line[-1] == ']': ansiprint(f'<b><y>{line}</y></b>') else: #tprint((Token, line), output=cli.output) print(line) cli.request_redraw()
def handle( self, dry: bool, yes: bool, using: Optional[str], skip_create: bool, skip_delete: bool, *args, **kwargs, ): # disable coloring if no terminal is attached if not sys.stdout.isatty(): colorama.init(strip=True) partitioning_manager = self._partitioning_manager() plan = partitioning_manager.plan(skip_create=skip_create, skip_delete=skip_delete, using=using) creations_count = len(plan.creations) deletions_count = len(plan.deletions) if creations_count == 0 and deletions_count == 0: ansiprint("<b><white>Nothing to be done.</white></b>") return plan.print() if dry: return if not yes: sys.stdout.write( ansistring( "<b><white>Do you want to proceed? (y/N) </white></b>")) if not self._ask_for_confirmation(): ansiprint("<b><white>Operation aborted.</white></b>") return plan.apply(using=using) ansiprint("<b><white>Operations applied.</white></b>")
def prereqs_and_outputs_query( workflow_id, tokens_list, pclient, options, json_filter, ): ids_list = [ # convert the tokens into standardised IDs tokens.relative_id for tokens in tokens_list ] tp_query = TASK_PREREQS_QUERY tp_kwargs = { 'request_string': tp_query, 'variables': { 'wFlows': [workflow_id], 'taskIds': ids_list, } } results = pclient('graphql', tp_kwargs) multi = len(results['taskProxies']) > 1 for t_proxy in results['taskProxies']: task_id = Tokens(t_proxy['id']).relative_id if options.json: json_filter.update({task_id: t_proxy}) else: if multi: ansiprint(f'------\n<bold>Task ID:</bold> {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")} = ' prereqs.append([ False, prefix, f'{cond["taskId"]} {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 output in t_proxy['outputs']: info = f'{task_id} {output["label"]}' print_msg_state(info, output['satisfied']) if (t_proxy['clockTrigger']['timeString'] or t_proxy['externalTriggers'] or t_proxy['xtriggers']): ansiprint('\n<bold>other</bold>' ' (<red>- => not satisfied</red>):') if t_proxy['clockTrigger']['timeString']: state = t_proxy['clockTrigger']['satisfied'] time_str = t_proxy['clockTrigger']['timeString'] print_msg_state('Clock trigger time reached', state) print(f' o Triggers at ... {time_str}') for ext_trig in t_proxy['externalTriggers']: state = ext_trig['satisfied'] print_msg_state(f'{ext_trig["label"]} ... {state}', state) for xtrig in t_proxy['xtriggers']: state = xtrig['satisfied'] print_msg_state( f'xtrigger "{xtrig["label"]} = {xtrig["id"]}"', state) if not results['taskProxies']: ansiprint(f"<red>No matching tasks found: {', '.join(ids_list)}", file=sys.stderr) return 1 return 0
def run( # noqa: WPS231 (high complexity) cmd: CmdFuncType, args=None, kwargs=None, number: int = 1, capture: Optional[Union[str, bool, Capture]] = None, title: Optional[str] = None, fmt: Optional[str] = None, pty: bool = False, progress: bool = True, nofail: bool = False, quiet: bool = False, silent: bool = False, stdin: Optional[str] = None, ) -> RunResult: """ Run a command in a subprocess or a Python function, and print its output if it fails. Arguments: cmd: The command to run. args: Arguments to pass to the callable. kwargs: Keyword arguments to pass to the callable. number: The command number. capture: The output to capture. title: The command title. fmt: The output format. pty: Whether to run in a PTY. progress: Whether to show progress. nofail: Whether to always succeed. quiet: Whether to not print the command output. silent: Don't print anything. stdin: String to use as standard input. Returns: The command exit code, or 0 if `nofail` is True. """ format_name: str = fmt or os.environ.get("FAILPRINT_FORMAT", DEFAULT_FORMAT) # type: ignore format_name = accept_custom_format(format_name) format_obj = formats.get(format_name, formats[DEFAULT_FORMAT]) env = Environment(autoescape=False) # noqa: S701 (no HTML: no need to escape) env.filters["indent"] = textwrap.indent command = printable_command(cmd, args, kwargs) if not silent and progress and format_obj.progress_template: progress_template = env.from_string(format_obj.progress_template) ansiprint(progress_template.render({"title": title, "command": command}), end="\r") capture = cast_capture(capture) if callable(cmd): code, output = run_function(cmd, args, kwargs, capture, stdin) else: code, output = run_command(cmd, capture, format_obj.accept_ansi, pty, stdin) if not silent: template = env.from_string(format_obj.template) ansiprint( template.render( { "title": title, "command": command, "code": code, "success": code == 0, "failure": code != 0, "number": number, "output": output, "nofail": nofail, "quiet": quiet, "silent": silent, }, ), ) return RunResult(0 if nofail else code, output)
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 enter(): ansiprint("<bold><white>Aperte ENTER para continuar...</white></bold>") input()
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))
def print_msg_state(msg, state): if state: ansiprint(f'<green> + {msg}</green>') else: ansiprint(f'<red> - {msg}</red>')
def ls( nodelist, json, invalid, long, unrecognized, recurse, tsv, directory, nocolor, ): """Print attributes of nodes in data store. \b Example: bionorm node-attributes . # attributes of current directory bionorm node-attributes Medicago_truncatula/ # organism directory bionorm node-attributes Medicago_truncatula/jemalong_A17.gnm5.FAKE/ # genome directory bionorm node-attributes Medicago_truncatula/jemalong_A17.gnm5.ann1.FAKE/ # annotation directory """ n_invalid = 0 n_unrecognized = 0 att_dict_list = [] for node in args_to_pathlist(nodelist, directory, recurse): node = CollectionPath(node) if node.collection_attributes.invalid_key is not None: node_is_invalid = True n_invalid += 1 else: node_is_invalid = False if invalid: continue if node.collection_attributes.file_type == "unrecognized": node_is_unrecognized = True n_unrecognized += 1 else: node_is_unrecognized = False if unrecognized: continue if json: print(jsonlib.dumps(node.collection_attributes)) elif long: print(node.collection_attributes.describe(node), end="") print(node.collection_attributes, end="") elif tsv: att_dict_list.append(dict(node.collection_attributes)) else: if nocolor: print(node) elif node_is_invalid: ansiprint(f"<{INVALID_COLOR}>{node}</{INVALID_COLOR}>") elif node_is_unrecognized: ansiprint( f"<{UNRECOGNIZED_COLOR}>{node}</{UNRECOGNIZED_COLOR}>") else: print(node) if tsv: att_frame = pd.DataFrame(att_dict_list) att_frame.to_csv(COLLECTION_ATT_FILENAME, sep="\t") logger.info(f"{len(att_frame)} attribute records written to" f" {COLLECTION_ATT_FILENAME}") if n_unrecognized: logger.warning(f"{n_unrecognized} unrecognized files were found.") if n_invalid: logger.error(f"{n_invalid} invalid nodes were found.")