Make brother_ql info a click.group()

This commit is contained in:
Philipp Klaus
2018-09-03 16:50:23 +02:00
parent 7ab1e672b7
commit 7f28027bfe
2 changed files with 61 additions and 59 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ The main user interface of this package is the command line tool `brother_ql`.
Commands: Commands:
analyze interpret a binary file containing raster... analyze interpret a binary file containing raster...
discover find connected label printers discover find connected label printers
info list available choices (for labels or models) info list available labels, models etc.
print Print a label print Print a label
send send an instruction file to the printer send send an instruction file to the printer
+60 -58
View File
@@ -53,69 +53,71 @@ def discover_and_list_available_devices(backend):
log_discovered_devices(available_devices) log_discovered_devices(available_devices)
print(textual_description_discovered_devices(available_devices)) print(textual_description_discovered_devices(available_devices))
@cli.command() @cli.group()
@click.argument('info', click.Choice(('labels', 'models', 'env')))
@click.pass_context @click.pass_context
def info(ctx, *args, **kwargs): def info(ctx, *args, **kwargs):
""" list available choices (for labels or models) """ """ list available labels, models etc. """
if kwargs['info'] == 'models':
"""List the models (choices for --model)
List the models that can be used with this software. @info.command(name='models')
Those are the choices avaiable for the --model option. @click.pass_context
""" def models_cmd(ctx, *args, **kwargs):
print('Supported models:') """
for model in models: print(" " + model) List the choices for --model
"""
print('Supported models:')
for model in models: print(" " + model)
elif kwargs['info'] == 'labels': @info.command()
""" @click.pass_context
List labels (types and sizes). def labels(ctx, *args, **kwargs):
"""
List the choices for --label
"""
from brother_ql.output_helpers import textual_label_description
print(textual_label_description(label_sizes))
This command lists all labels (label types and label sizes) @info.command()
that can be used with this software. """ @click.pass_context
from brother_ql.output_helpers import textual_label_description def env(ctx, *args, **kwargs):
print(textual_label_description(label_sizes)) """
print debug info about running environment
elif kwargs['info'] == 'env': """
""" import sys, platform, os, shutil
Print information about the running environment of brother_ql. from pkg_resources import get_distribution, working_set
""" print("\n##################\n")
import sys, platform, os, shutil print("Information about the running environment of brother_ql.")
from pkg_resources import get_distribution, working_set print("(Please provide this information when reporting any issue.)\n")
print("\n##################\n") # computer
print("Information about the running environment of brother_ql.") print("About the computer:")
print("(Please provide this information when reporting any issue.)\n") for attr in ('platform', 'processor', 'release', 'system', 'machine', 'architecture'):
# computer print(' * '+attr.title()+':', getattr(platform, attr)())
print("About the computer:") # Python
for attr in ('platform', 'processor', 'release', 'system', 'machine', 'architecture'): print("About the installed Python version:")
print(' * '+attr.title()+':', getattr(platform, attr)()) py_version = str(sys.version).replace('\n', ' ')
# Python print(" *", py_version)
print("About the installed Python version:") # brother_ql
py_version = str(sys.version).replace('\n', ' ') print("About the brother_ql package:")
print(" *", py_version) pkg = get_distribution('brother_ql')
# brother_ql print(" * package location:", pkg.location)
print("About the brother_ql package:") print(" * package version: ", pkg.version)
pkg = get_distribution('brother_ql') try:
print(" * package location:", pkg.location) cli_loc = shutil.which('brother_ql')
print(" * package version: ", pkg.version) except:
try: cli_loc = 'unknown'
cli_loc = shutil.which('brother_ql') print(" * brother_ql CLI path:", cli_loc)
except: # brother_ql's requirements
cli_loc = 'unknown' print("About the requirements of brother_ql:")
print(" * brother_ql CLI path:", cli_loc) fmt = " {req:14s} | {spec:10s} | {ins_vers:17s}"
# brother_ql's requirements print(fmt.format(req='requirement', spec='requested', ins_vers='installed version'))
print("About the requirements of brother_ql:") print(fmt.format(req='-' * 14, spec='-'*10, ins_vers='-'*17))
fmt = " {req:14s} | {spec:10s} | {ins_vers:17s}" requirements = list(pkg.requires())
print(fmt.format(req='requirement', spec='requested', ins_vers='installed version')) requirements.sort(key=lambda x: x.project_name)
print(fmt.format(req='-' * 14, spec='-'*10, ins_vers='-'*17)) for req in requirements:
requirements = list(pkg.requires()) proj = req.project_name
requirements.sort(key=lambda x: x.project_name) req_pkg = get_distribution(proj)
for req in requirements: spec = ' '.join(req.specs[0]) if req.specs else 'any'
proj = req.project_name print(fmt.format(req=proj, spec=spec, ins_vers=req_pkg.version))
req_pkg = get_distribution(proj) print("\n##################\n")
spec = ' '.join(req.specs[0]) if req.specs else 'any'
print(fmt.format(req=proj, spec=spec, ins_vers=req_pkg.version))
print("\n##################\n")
@cli.command('print', short_help='Print a label') @cli.command('print', short_help='Print a label')
@click.argument('images', nargs=-1, metavar='IMAGE [IMAGE] ...') @click.argument('images', nargs=-1, metavar='IMAGE [IMAGE] ...')