From 80b714fdae6f600593278a56ddfe04cc8c6fe984 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sat, 23 Jul 2016 10:00:40 +0200 Subject: [PATCH 1/2] add basic argcomplete support --- setup.py | 2 ++ src/escpos/cli.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/setup.py b/setup.py index e4edbf3..7a3895b 100755 --- a/setup.py +++ b/setup.py @@ -110,6 +110,8 @@ setup( 'six', 'appdirs', 'pyyaml', + 'argparse', + 'argcomplete', ], setup_requires=[ 'setuptools_scm', diff --git a/src/escpos/cli.py b/src/escpos/cli.py index 5457df5..3e3311d 100644 --- a/src/escpos/cli.py +++ b/src/escpos/cli.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# PYTHON_ARGCOMPLETE_OK """ CLI This module acts as a command line interface for python-escpos. It mirrors @@ -14,6 +15,11 @@ from __future__ import print_function from __future__ import unicode_literals import argparse +try: + import argcomplete +except ImportError: + # this CLI works nevertheless without argcomplete + pass # noqa import sys import six from . import config @@ -499,6 +505,10 @@ def main(): help='Print the version of python-escpos') parser_command_version.set_defaults(version=True) + # hook in argcomplete + if 'argcomplete' in globals(): + argcomplete.autocomplete(parser) + # Get only arguments actually passed args_dict = vars(parser.parse_args()) if not args_dict: From fd3f1067fe8df97036409614f6b4fb0c903a628b Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sat, 23 Jul 2016 11:34:18 +0200 Subject: [PATCH 2/2] DOC update documentation on installation and CLI --- doc/index.rst | 1 - doc/user/dependencies.rst | 57 --------------------------------------- doc/user/installation.rst | 42 +++++++++++++++++------------ 3 files changed, 25 insertions(+), 75 deletions(-) delete mode 100644 doc/user/dependencies.rst diff --git a/doc/index.rst b/doc/index.rst index 2b30b31..8e876a0 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -12,7 +12,6 @@ Content :maxdepth: 1 :caption: User Documentation - user/dependencies user/installation user/methods user/printers diff --git a/doc/user/dependencies.rst b/doc/user/dependencies.rst deleted file mode 100644 index cc2963d..0000000 --- a/doc/user/dependencies.rst +++ /dev/null @@ -1,57 +0,0 @@ -************ -Dependencies -************ - -Fedora ------- - -Fortunately everything is on Fedora repositories. - -:: - - # yum install python-imaging pyserial pyusb python-qrcode - -Ubuntu ------- - -Ultimately, this instructions also apply to Raspbian, in case you are -interested to install python-escpos on your Raspberry with Raspbian. - -Install the packages available on distro repositories. - -:: - - # apt-get install python-imaging pyserial - -The packages which are not available at Ubuntu repositories need to be -installed manually. - -pyusb -^^^^^ -This is the python binding to libusb-1.0 - -* Get the latest tarball from `sourceforge `__ -* Build and install it - -:: - - # tar zxvf pyusb-1.*.tar.gz - # cd pyusb-1.* - # python setup.py build - # sudo python setup.py install - -python-qrcode -^^^^^^^^^^^^^ - -This is the python module to generate QR Codes - -* Checkout the latest code from `github `__ -* Build and install it - -:: - - # git clone https://github.com/lincolnloop/python-qrcode - # cd python-qrcode - # python setup.py build - # sudo python setup.py install - diff --git a/doc/user/installation.rst b/doc/user/installation.rst index be08c8a..4c826b6 100644 --- a/doc/user/installation.rst +++ b/doc/user/installation.rst @@ -2,16 +2,26 @@ Installation ************ -System preparation ------------------- +:Last Reviewed: 2016-07-23 -1. Install the required - `dependencies `__ +Installation with PIP +--------------------- +Installation should be rather straight-forward. python-escpos is on PyPi, so you can simply enter: -2. Get the *Product ID* and *Vendor ID* from the lsusb command + :: + + pip install python-escpos + +This should install all necessary dependencies. Apart from that python-escpos should also be +available as a Debian package. If you want to always benefit from the newest stable releases you should probably +install from PyPi. + +Setup udev for USB-Printers +--------------------------- +1. Get the *Product ID* and *Vendor ID* from the lsusb command ``# lsusb Bus 002 Device 001: ID 1a2b:1a2b Device name`` -3. Create a udev rule to let users belonging to *dialout* group use the +2. Create a udev rule to let users belonging to *dialout* group use the printer. You can create the file ``/etc/udev/rules.d/99-escpos.rules`` and add the following: ``SUBSYSTEM=="usb", ATTRS{idVendor}=="1a2b", ATTRS{idProduct}=="1a2b", MODE="0664", GROUP="dialout"`` @@ -20,21 +30,19 @@ System preparation "dialout" group, or use another group you already belongs instead "dialout" and set it in the ``GROUP`` parameter in the above rule. -4. Restart udev ``# sudo service udev restart`` In some new systems it +3. Restart udev ``# sudo service udev restart`` In some new systems it is done with ``# sudo udevadm control --reload`` -Install -------- +Enabling tab-completion in CLI +------------------------------ +python-escpos has a CLI with tab-completion. This is realised with ``argcomplete``. +In order for this to work you have to enable tab-completion, which is described in +the `manual of argcomplete `__. -* Clone python-escpos from github -* Change directory to python-escpos and install the package +If you only want to enable it for python-escpos, or global activation does not work, try this: - :: + :: - # cd python-escpos - # python setup.py build - # sudo python setup.py install - -* Enjoy !!! + eval "$(register-python-argcomplete python-escpos)"