本文整理匯總了Python中click.echo_via_pager方法的典型用法代碼示例。如果您正苦於以下問題:Python click.echo_via_pager方法的具體用法?Python click.echo_via_pager怎麽用?Python click.echo_via_pager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類click
的用法示例。
在下文中一共展示了click.echo_via_pager方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: rib_getversion
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
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()
示例2: rib_modify
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
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()
示例3: help_tasks
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
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()
示例4: list_services
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
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))
示例5: get_build_logs
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
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
# ===========
示例6: echo_via_pager
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
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)
示例7: _page
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
def _page(it):
click.echo_via_pager('\n'.join(map(str, it)))
示例8: ls
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
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)
),
)
示例9: echo_warnings_via_pager
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
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
),
)
示例10: paging
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
def paging(lines):
"""Page through output."""
data = '\n'.join(['Line %d' % num for num in range(lines)])
click.echo_via_pager(data)
示例11: _echo
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
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)
示例12: gnmi_get
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
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()
示例13: request
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
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))
示例14: response
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
def response(ctx, paging):
'''
Displays response from the last RPC call.
'''
if paging:
click.echo_via_pager(str(ctx.obj['manager'].rpcs[ctx.obj['RPC_TYPE']][ctx.obj['RPC_NAME']].response))
else:
click.secho(str(ctx.obj['manager'].rpcs[ctx.obj['RPC_TYPE']][ctx.obj['RPC_NAME']].response))
示例15: error
# 需要導入模塊: import click [as 別名]
# 或者: from click import echo_via_pager [as 別名]
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))