Python click.echo_via_pager() Examples
The following are 30
code examples of click.echo_via_pager().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
click
, or try the search function
.
Example #1
Source File: serve.py From kaos with Apache License 2.0 | 6 votes |
def get_build_logs(facade: ServeFacade, job_id, out_dir): """ Retrieve logs from a running endpoint. """ try: # ensure arguments are correctly defined validate_inputs([job_id], ['ind']) click.echo("{} - Retrieving {} from {}".format( click.style("Info", bold=True, fg='green'), click.style("build-logs", bold=True), click.style(job_id, bold=True, fg='green', dim=True))) logs = facade.get_build_logs(job_id) click.echo_via_pager(logs) facade.write_build_logs(job_id, logs, out_dir) except Exception as e: handle_specific_exception(e) handle_exception(e) # SERVE kill # ===========
Example #2
Source File: cli.py From nidaba with GNU General Public License v2.0 | 6 votes |
def help_tasks(ctx, param, value): if not value or ctx.resilient_parsing: return from nidaba import celery t = celery.app.tasks hidden = ['util'] last = u'' docs = u'' for k in sorted(t.keys()): hier = k.split('.') if hier[0] == 'nidaba': if hier[1] in hidden: continue elif hier[1] != last: docs += '{}\n{}\n\n'.format(hier[1].title(), len(hier[1]) * '-') last = hier[1] docs += '{}\n{}\n\n{}'.format(hier[-1], len(hier[-1]) * '~', getdoc(t[k].run).decode('utf-8').partition('Returns:')[0]) click.echo_via_pager(docs) ctx.exit()
Example #3
Source File: services.py From core with GNU General Public License v3.0 | 6 votes |
def list_services(): """List all services and statuses.""" try: data = [] svcs = services.get() llen = len(sorted(svcs, key=lambda x: len(x.name))[-1].name) for x in svcs: data.append( click.style( '{name: <{fill}}'.format(name=x.name, fill=llen + 3), fg="white", bold=True) + click.style( x.state.capitalize(), fg="green" if x.state == "running" else "red") + " " + click.style( "Enabled" if x.enabled else "Disabled", fg="green" if x.enabled else "red") ) click.echo_via_pager("\n".join(data)) except Exception as e: raise CLIException(str(e))
Example #4
Source File: grpc_shell.py From SROS-grpc-services with BSD 3-Clause "New" or "Revised" License | 6 votes |
def rib_modify(ctx,name, paging): ''' RibApi.Modify ''' if ctx.invoked_subcommand != 'help': try: rpc_type = 'RibApi.Modify' if name in ctx.obj['manager'].rpcs[rpc_type]: if ctx.invoked_subcommand is None: if paging: click.echo_via_pager(ctx.obj['manager'].get_rpc(type=rpc_type, name=name)) else: click.echo(ctx.obj['manager'].get_rpc(type=rpc_type, name=name)) else: click.secho('Rpc with name \'{name}\' doesnt exists, adding one to rpc manager'.format(name=name), fg='yellow') ctx.obj['manager'].rpcs[rpc_type][name] = rib_api.Modify(stub=ctx.obj['rib_fib_stub'], metadata=ctx.obj['context'].metadata, name=name) ctx.obj['RPC_NAME'] = name ctx.obj['RPC_TYPE'] = rpc_type except KeyError as e: click.secho('\nYou have to create at least one connection before creating RPCs\n', fg='red') sys.exit()
Example #5
Source File: grpc_shell.py From SROS-grpc-services with BSD 3-Clause "New" or "Revised" License | 6 votes |
def rib_getversion(ctx, name, paging): if ctx.invoked_subcommand != 'help': try: rpc_type = 'RibApi.GetVersion' if name in ctx.obj['manager'].rpcs[rpc_type]: if ctx.invoked_subcommand is None: if paging: click.echo_via_pager(ctx.obj['manager'].get_rpc(type=rpc_type, name=name)) else: click.echo(ctx.obj['manager'].get_rpc(type=rpc_type, name=name)) else: click.secho('Rpc with name \'{name}\' doesnt exists, adding one to rpc manager'.format(name=name), fg='yellow') ctx.obj['manager'].rpcs[rpc_type][name] = rib_api.GetVersion(stub=ctx.obj['rib_fib_stub'], metadata=ctx.obj['context'].metadata, name=name) ctx.obj['RPC_NAME'] = name ctx.obj['RPC_TYPE'] = rpc_type except KeyError as e: click.secho('\nYou have to create at least one connection before creating RPCs\n', fg='red') sys.exit()
Example #6
Source File: cat_impl.py From guildai with Apache License 2.0 | 5 votes |
def _page(path): f = _open_file(path) click.echo_via_pager(f.read())
Example #7
Source File: cli.py From lexico with MIT License | 5 votes |
def view(): '''Lists all the words present in your dictionary.''' #TODO: More information/table columns words = get_words() formatted_words = format_words(words) display_words = tabulate_words(formatted_words) click.echo_via_pager(display_words)
Example #8
Source File: main.py From pgcli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def echo_via_pager(self, text, color=None): if self.pgspecial.pager_config == PAGER_OFF or self.watch_command: click.echo(text, color=color) elif "pspg" in os.environ.get("PAGER", "") and self.table_format == "csv": click.echo_via_pager(text, color) elif self.pgspecial.pager_config == PAGER_LONG_OUTPUT: lines = text.split("\n") # The last 4 lines are reserved for the pgcli menu and padding if self.is_too_tall(lines) or any(self.is_too_wide(l) for l in lines): click.echo_via_pager(text, color=color) else: click.echo(text, color=color) else: click.echo_via_pager(text, color)
Example #9
Source File: execution.py From ceph-lcm with Apache License 2.0 | 5 votes |
def log(ctx, execution_id, client): """Get execution log (plain text from ansible-playbook) for a certain execution.""" response = client.get_execution_log(execution_id, headers={"Content-Type": "text/plain"}, raw_response=True, stream=True) if ctx.obj["pager"]: click.echo_via_pager(response.text) else: for line in response.iter_lines(decode_unicode=True): click.echo(line)
Example #10
Source File: utils.py From ceph-lcm with Apache License 2.0 | 5 votes |
def format_output_json(ctx, response, error=False): response = json_dumps(response) response = colorize(response, ctx.obj["color"], "json") if error: click.echo(response, err=True) elif ctx.obj["pager"]: click.echo_via_pager(response) else: click.echo(response)
Example #11
Source File: services.py From core with GNU General Public License v3.0 | 5 votes |
def log(name): """Get logs since last boot for a particular service""" try: service = services.get(name) if not service: raise CLIException("No service found") if service.stype == "system": data = shell("journalctl -x -b 0 -u {0}".format(service.sfname)) click.echo_via_pager( data["stdout"].decode() ) else: click.echo_via_pager(service.get_log()) except Exception as e: raise CLIException(str(e))
Example #12
Source File: mssql_cli.py From mssql-cli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _output_query(self, output): """ Specifies how query output is handled """ if self.interactive_mode: click.echo_via_pager('\n'.join(output)) else: if self.output_file: try: with open(self.output_file, 'w', encoding='utf-8') as f: click.echo('\n'.join(output), file=f) except IOError as e: click.secho(str(e), err=True, fg='red') sys.exit(1) else: click.echo('\n'.join(output))
Example #13
Source File: cli.py From lexico with MIT License | 5 votes |
def add(word): '''Finds the dictionary data about a word.''' #TODO: raise error if word is None: word = click.prompt('Enter the word', type=str) word = word.lower() try: word_data = fetch_word(word) except ConfigFileError: click.echo('You need to initialize the application.') click.echo('Run:\n\t\t $ lexico init') else: click.echo_via_pager(word_data.stringify())
Example #14
Source File: help_impl.py From guildai with Apache License 2.0 | 5 votes |
def _print_help(help, args): if args.no_pager: click.echo(help) else: click.echo_via_pager(help)
Example #15
Source File: cli.py From guildai with Apache License 2.0 | 5 votes |
def page(text): click.echo_via_pager(text)
Example #16
Source File: output.py From http-prompt with MIT License | 5 votes |
def write(self, data): if isinstance(data, six.binary_type): data = data.decode('utf-8') # echo_via_pager() already appends a '\n' at the end of text, # so we use rstrip() to remove extra newlines (#89) click.echo_via_pager(data.rstrip())
Example #17
Source File: serve.py From kaos with Apache License 2.0 | 5 votes |
def list_endpoint(facade: ServeFacade): """ List all running endpoints. """ try: data = facade.list() building_table, n_building = render_queued_table(data['building'], header='BUILDING', include_ind=False, drop_cols={'progress'}) running_table = "" n_running = len(data['endpoints']) running_jobs = data['endpoints'] if n_running > 0: running_table = \ f"\n{render_table(running_jobs, 'RUNNING', drop_cols={'code', 'image', 'model', 'progress'})}\n" facade.cache(running_jobs) if n_running + n_building > 30: click.echo_via_pager(f'{building_table}{running_table}') elif n_running + n_building > 0: click.echo(f'{building_table}{running_table}') else: click.echo("{} - There are currently {} running endpoints - first run {}".format( click.style("Warning", bold=True, fg='yellow'), click.style('no', bold=True, fg='red'), click.style("kaos serve deploy", bold=True, fg='green'))) except Exception as e: handle_specific_exception(e) handle_exception(e) # SERVE deploy # ============
Example #18
Source File: serve.py From kaos with Apache License 2.0 | 5 votes |
def get_logs(facade: ServeFacade, endpoint, ind, out_dir): """ Retrieve logs from a running endpoint. """ try: # ensure arguments are correctly defined validate_inputs([endpoint, ind], ['endpoint', 'ind']) # selection by index if ind is not None: endpoint = facade.get_endpoint_by_ind(ind) click.echo("{} - Retrieving {} from {}".format( click.style("Info", bold=True, fg='green'), click.style("logs", bold=True), click.style(endpoint, bold=True, fg='green', dim=True))) logs = facade.get_serve_logs(endpoint) click.echo_via_pager(logs) facade.write_serve_logs(endpoint, logs, out_dir) except Exception as e: handle_specific_exception(e) handle_exception(e) # BUILD SERVE logs # ================
Example #19
Source File: notebook.py From kaos with Apache License 2.0 | 5 votes |
def list_notebooks(facade: NotebookFacade): """ List all available running notebooks. """ try: data = facade.list() building_table, n_building = render_queued_table(data['building'], header='BUILDING', include_ind=False, drop_cols={'progress'}) running_table = "" running_jobs = data['notebooks'] n_running = len(running_jobs) if n_running > 0: running_table = \ f"\n{render_table(running_jobs, 'RUNNING', drop_cols={'code', 'image', 'model', 'progress'})}\n" facade.cache(running_jobs) if n_running + n_building > 30: click.echo_via_pager(f'{building_table}{running_table}') elif n_running + n_building > 0: click.echo(f'{building_table}{running_table}') else: click.echo("{} - There are currently {} active notebooks - first run {}".format( click.style("Warning", bold=True, fg='yellow'), click.style('no', bold=True, fg='red'), click.style("kaos notebook deploy", bold=True, fg='green'))) except Exception as e: handle_specific_exception(e) handle_exception(e) # NOTEBOOK deploy # ===============
Example #20
Source File: notebook.py From kaos with Apache License 2.0 | 5 votes |
def get_build_logs(facade: NotebookFacade, job_id, out_dir): """ Retrieve logs from building notebook source image. """ # get logs for a specific job try: # ensure arguments are correctly defined validate_inputs([job_id], ['job_id']) click.echo("{} - Retrieving {} from {}".format( click.style("Info", bold=True, fg='green'), click.style("build-logs", bold=True), click.style(job_id, bold=True, fg='green', dim=True))) logs = facade.get_build_logs(job_id) click.echo_via_pager(logs) facade.write_build_logs(job_id, logs, out_dir) except Exception as e: handle_specific_exception(e) handle_exception(e) # NOTEBOOK kill # =============
Example #21
Source File: train.py From kaos with Apache License 2.0 | 5 votes |
def get_logs(facade: TrainFacade, job_id, ind, out_dir): """ Retrieve logs from a training job. """ # build output directory (default = workspace) # get logs for a specific job try: # ensure arguments are correctly defined validate_inputs([job_id, ind], ['job_id', 'ind']) # selection by index if ind is not None: job_id = facade.get_job_by_ind(ind) click.echo("{} - Retrieving {} from {}".format( click.style("Info", bold=True, fg='green'), click.style("logs", bold=True), click.style(job_id, bold=True, fg='green', dim=True))) logs = facade.get_train_logs(job_id) click.echo_via_pager(logs) facade.write_train_logs(job_id, logs, out_dir) except Exception as e: handle_specific_exception(e) handle_exception(e) # Kill TRAIN job provenance # ==============
Example #22
Source File: grpc_shell.py From SROS-grpc-services with BSD 3-Clause "New" or "Revised" License | 5 votes |
def error(ctx, paging): ''' Displays error from last rpc call. ''' if paging: click.echo_via_pager(str(ctx.obj['manager'].rpcs[ctx.obj['RPC_TYPE']][ctx.obj['RPC_NAME']].error)) else: click.secho(str(ctx.obj['manager'].rpcs[ctx.obj['RPC_TYPE']][ctx.obj['RPC_NAME']].error))
Example #23
Source File: carml_readme.py From carml with The Unlicense | 5 votes |
def run(reactor, cfg, tor): readme = pkg_resources.resource_string('carml', '../README.rst') # uhm, docutils documentation is confusing as all hell and no good # examples of "convert this rST string to anything else" .. :/ but # we should "render" it to text click.echo_via_pager(readme.decode('utf8'))
Example #24
Source File: cli.py From pybel with MIT License | 5 votes |
def _page(it): click.echo_via_pager('\n'.join(map(str, it)))
Example #25
Source File: cli.py From pybel with MIT License | 5 votes |
def ls(manager: Manager, url: Optional[str], namespace_id: Optional[int]): """List cached namespaces.""" if url: n = manager.get_or_create_namespace(url) _page(n.entries) elif namespace_id is not None: _ls(manager, Namespace, namespace_id) else: click.echo_via_pager( '\n'.join( "{}\t{}\t{}".format(n.id, n.name, n.url) for n in manager.session.query(Namespace) ), )
Example #26
Source File: cli.py From pybel with MIT License | 5 votes |
def echo_warnings_via_pager(warnings: List[WarningTuple], sep: str = '\t') -> None: """Output the warnings from a BEL graph with Click and the system's pager.""" # Exit if no warnings if not warnings: click.echo('Congratulations! No warnings.') sys.exit(0) max_line_width = max( len(str(exc.line_number)) for _, exc, _ in warnings ) max_warning_width = max( len(exc.__class__.__name__) for _, exc, _ in warnings ) s1 = '{:>' + str(max_line_width) + '}' + sep s2 = '{:>' + str(max_warning_width) + '}' + sep def _make_line(path: str, exc: BELParserWarning): s = click.style(path, fg='cyan') + sep s += click.style(s1.format(exc.line_number), fg='blue', bold=True) s += click.style( s2.format(exc.__class__.__name__), fg=('red' if exc.__class__.__name__.endswith('Error') else 'yellow'), ) s += click.style(exc.line, bold=True) + sep s += click.style(str(exc)) return s click.echo_via_pager( '\n'.join( _make_line(path, exc) for path, exc, _ in warnings ), )
Example #27
Source File: cli.py From PyCon2019-Click-Tutorial with Mozilla Public License 2.0 | 5 votes |
def paging(lines): """Page through output.""" data = '\n'.join(['Line %d' % num for num in range(lines)]) click.echo_via_pager(data)
Example #28
Source File: cli.py From databrewer with MIT License | 5 votes |
def _echo(output, min_lines=10): ctx = click.get_current_context() if ctx.obj.get('use_pager') and output.count('\n') > min_lines: _func = click.echo_via_pager else: _func = click.echo _func(output, sys.stdout)
Example #29
Source File: grpc_shell.py From SROS-grpc-services with BSD 3-Clause "New" or "Revised" License | 5 votes |
def gnmi_get(ctx, name, paging): ''' gNMI.Get unary rpc - sends resquest consisting of paths to deserved data and returns all the data at once in GetRespone - one noticfication per one path requested. Since whole response must be srialized at remote device before sending, this rpc is not suitable for retrieving large sets of data. ''' if ctx.invoked_subcommand != 'help': try: rpc_type = 'gNMI.Get' if name in ctx.obj['manager'].rpcs[rpc_type]: if ctx.invoked_subcommand is None: if paging: click.echo_via_pager(ctx.obj['manager'].get_rpc(type=rpc_type, name=name)) else: click.echo(ctx.obj['manager'].get_rpc(type=rpc_type, name=name)) else: click.secho('Rpc with name \'{name}\' doesnt exists, adding one to rpc manager'.format(name=name), fg='yellow') ctx.obj['manager'].rpcs[rpc_type][name] = gnmi.Get(stub=ctx.obj['gnmi_stub'], metadata=ctx.obj['context'].metadata, name=name, delimiter=default_delimiter) ctx.obj['RPC_NAME'] = name ctx.obj['RPC_TYPE'] = rpc_type except KeyError as e: click.secho('\nYou have to create at least one connection before creating RPCs\n', fg='red') sys.exit()
Example #30
Source File: grpc_shell.py From SROS-grpc-services with BSD 3-Clause "New" or "Revised" License | 5 votes |
def request(ctx, paging): ''' Displays request currently being built in clients. ''' if paging: click.echo_via_pager(str(ctx.obj['manager'].rpcs[ctx.obj['RPC_TYPE']][ctx.obj['RPC_NAME']].request)) else: click.secho(str(ctx.obj['manager'].rpcs[ctx.obj['RPC_TYPE']][ctx.obj['RPC_NAME']].request))