add extended version information

This commit is contained in:
Patrick Kanzler 2023-09-24 23:42:07 +02:00
parent 6d0c475b9a
commit 486f4a50dc
3 changed files with 54 additions and 3 deletions

View File

@ -18,7 +18,8 @@ I have:
**Printer:** Manufacturer Model XVI **Printer:** Manufacturer Model XVI
<!-- since version 2.0.1 you can type 'python-escpos version' in your shell. <!-- since version 2.0.1 you can type 'python-escpos version' in your shell.
Alternatively you could use '__version__' in module escpos. --> Starting with python-escpos version 3.0, please replace the information below
with the output of `python-escpos version_extended`. -->
**python-escpos version:** 0.0.0 **python-escpos version:** 0.0.0
**python version:** 0.0 **python version:** 0.0

View File

@ -11,6 +11,7 @@ It requires you to have a configuration file. See documentation for details.
import argparse import argparse
import platform
try: try:
import argcomplete import argcomplete
@ -21,7 +22,9 @@ import sys
import six import six
from . import config, version from . import config
from . import printer as escpos_printer_module
from . import version
# Must be defined before it's used in DEMO_FUNCTIONS # Must be defined before it's used in DEMO_FUNCTIONS
@ -454,6 +457,36 @@ ESCPOS_COMMANDS = [
] ]
def print_extended_information() -> None:
print(f"* python-escpos version: `{version.version}`")
print(
f"* python version: `{platform.python_implementation()} v{platform.python_version()}`"
)
print(f"* platform: `{platform.platform()}`")
print(
f"* printer driver `USB` is usable: `{escpos_printer_module.Usb.is_usable()}`"
)
print(
f"* printer driver `File` is usable: `{escpos_printer_module.File.is_usable()}`"
)
print(
f"* printer driver `Network` is usable: `{escpos_printer_module.Network.is_usable()}`"
)
print(
f"* printer driver `Serial` is usable: `{escpos_printer_module.Serial.is_usable()}`"
)
print(f"* printer driver `LP` is usable: `{escpos_printer_module.LP.is_usable()}`")
print(
f"* printer driver `Dummy` is usable: `{escpos_printer_module.Dummy.is_usable()}`"
)
print(
f"* printer driver `CupsPrinter` is usable: `{escpos_printer_module.CupsPrinter.is_usable()}`"
)
print(
f"* printer driver `Win32Raw` is usable: `{escpos_printer_module.Win32Raw.is_usable()}`"
)
def main(): def main():
"""Handle main entry point of CLI script. """Handle main entry point of CLI script.
@ -520,10 +553,16 @@ def main():
) )
parser_command_version = command_subparsers.add_parser( parser_command_version = command_subparsers.add_parser(
"version", help="Print the version of python-escpos" "version", help="Print the version information of python-escpos"
) )
parser_command_version.set_defaults(version=True) parser_command_version.set_defaults(version=True)
parser_command_version_extended = command_subparsers.add_parser(
"version_extended",
help="Print the extended version information of python-escpos (for bug reports)",
)
parser_command_version_extended.set_defaults(version_extended=True)
# hook in argcomplete # hook in argcomplete
if "argcomplete" in globals(): if "argcomplete" in globals():
argcomplete.autocomplete(parser) argcomplete.autocomplete(parser)
@ -543,6 +582,11 @@ def main():
print(version.version) print(version.version)
sys.exit() sys.exit()
print_version_extended = command_arguments.pop("version_extended", None)
if print_version_extended:
print_extended_information()
sys.exit()
# If there was a config path passed, grab it # If there was a config path passed, grab it
config_path = command_arguments.pop("config", None) config_path = command_arguments.pop("config", None)

View File

@ -81,6 +81,12 @@ class TestCLI:
assert not result.stderr assert not result.stderr
assert escpos.__version__ == result.stdout.strip() assert escpos.__version__ == result.stdout.strip()
def test_cli_version_extended(self):
"""Test the extended version information"""
result = self.env.run("python-escpos", "version_extended")
assert not result.stderr
# TODO test output
@pytest.mark.skip( @pytest.mark.skip(
reason="disable this test as it is not that easy anymore to predict the outcome of this call" reason="disable this test as it is not that easy anymore to predict the outcome of this call"
) )