From 78b5667ca48f1338a4ba482c4cf4413a09ea89fe Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Fri, 10 Aug 2018 15:49:40 +0200 Subject: [PATCH] New CLI command `brother_ql info env` This command lists the running conditions as shown below: ################## Information about the running environment of brother_ql. (Please provide this information when reporting any issue.) About the computer: * Platform: Linux-4.4.138-59-default-x86_64-with-SuSE-42.3-x86_64 * Processor: x86_64 * Release: 4.4.138-59-default * System: Linux * Machine: x86_64 * Architecture: ('64bit', 'ELF') About the installed Python version: * 3.7.0 (default, Jul 31 2018, 19:42:44) [GCC 4.8.5] About the brother_ql package: * package location: /local/pyvenv/py37loc/lib/python3.7/site-packages * package version: 0.9.dev0 * brother_ql CLI path: /local/pyvenv/py37loc/bin/brother_ql About the requirements of brother_ql: requirement | requested | installed version -------------- | ---------- | ----------------- click | any | 6.7 future | any | 0.16.0 packbits | any | 0.6 pillow | >= 3.3.0 | 5.2.0 ################## --- brother_ql/cli.py | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/brother_ql/cli.py b/brother_ql/cli.py index 9efea76..3c633ce 100755 --- a/brother_ql/cli.py +++ b/brother_ql/cli.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # Python standard library +from __future__ import print_function import logging # external dependencies @@ -53,7 +54,7 @@ def discover_and_list_available_devices(backend): print(textual_description_discovered_devices(available_devices)) @cli.command() -@click.argument('info', click.Choice(('labels', 'models'))) +@click.argument('info', click.Choice(('labels', 'models', 'env'))) @click.pass_context def info(ctx, *args, **kwargs): """ list available choices (for labels or models) """ @@ -75,6 +76,47 @@ def info(ctx, *args, **kwargs): from brother_ql.output_helpers import textual_label_description print(textual_label_description(label_sizes)) + elif kwargs['info'] == 'env': + """ + Print information about the running environment of brother_ql. + """ + import sys, platform, os, shutil + from pkg_resources import get_distribution, working_set + print("\n##################\n") + print("Information about the running environment of brother_ql.") + print("(Please provide this information when reporting any issue.)\n") + # computer + print("About the computer:") + for attr in ('platform', 'processor', 'release', 'system', 'machine', 'architecture'): + print(' * '+attr.title()+':', getattr(platform, attr)()) + # Python + print("About the installed Python version:") + py_version = str(sys.version).replace('\n', ' ') + print(" *", py_version) + # brother_ql + print("About the brother_ql package:") + pkg = get_distribution('brother_ql') + print(" * package location:", pkg.location) + print(" * package version: ", pkg.version) + try: + cli_loc = shutil.which('brother_ql') + except: + cli_loc = 'unknown' + print(" * brother_ql CLI path:", cli_loc) + # brother_ql's requirements + print("About the requirements of brother_ql:") + fmt = " {req:14s} | {spec:10s} | {ins_vers:17s}" + print(fmt.format(req='requirement', spec='requested', ins_vers='installed version')) + print(fmt.format(req='-' * 14, spec='-'*10, ins_vers='-'*17)) + requirements = list(pkg.requires()) + requirements.sort(key=lambda x: x.project_name) + for req in requirements: + proj = req.project_name + req_pkg = get_distribution(proj) + 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') @click.argument('images', nargs=-1, metavar='IMAGE [IMAGE] ...') @click.option('-l', '--label', type=click.Choice(label_sizes), envvar='BROTHER_QL_LABEL', help='The label (size, type - die-cut or endless). Run `brother_ql info labels` for a full list including ideal pixel dimensions.')