From 5078c49b3a478f75eab2364a4794f4e9e74b7ab1 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sun, 5 Feb 2017 11:01:33 +0100 Subject: [PATCH 1/9] add github upload for travis This automatically uploads succesfull release builds into the GitHub release. --- .travis.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3966d74..6f94072 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ matrix: env: TOXENV=docs - python: 2.7 env: TOXENV=flake8 - - python: 3.5 + - python: 3.6 env: TOXENV=flake8 allow_failures: - python: 3.6-dev @@ -44,3 +44,16 @@ notifications: email: on_success: never on_failure: change +deploy: +# Github deployment + - provider: releases + api_key: + secure: oiR3r5AIx9ENIRtbUKIxorRx8GMv4BxgVIZcieXbgSTN4DBZdRWdzs1Xxngu/90Xf79G0X+XGxZyXrYN7eFFNp0kUYj8kwZ1aS/dyR88scskumERWi1Hv5WUJrYGrDe7PcjNGsJ2jw0nNnRPKG87Y84aR4lQygyGBSlDcdrOBnBv0sHYJMxRvHSRkGgWpur06QIOGOk4oOipTXR/7E9cg3YQC5nvZAf2QiprwTa8IcOSFlZQPykEVRYSiAgXrgqBYcZzpX0hAGuIBv7DmPI2ORTF+t79Wbhxhnho3gGJleDv7Z96//sf1vQNCG6qOgeIc9ZY08Jm1AwXQoW0p6F1/XcEPxeyPDkXJzlojE9rjYNLCPL4gxb/LESEuUafm0U4JGMsZ6hnsBOw583yTuAdfQuJ9M+QaSyem6OVNkky3+DKAD3z0WJnl9jmGXIXigNSIxD25XhpvY+j9P0XTLBG1GT2Q+wXCIjSYJc2XnYcdgVJcLoxSWk1fKj/KPi7buAWtqwnL3tjeldpMMOZMliPUTWMM14zoGskHztt0JCkAtcotm9AQtvL8eZ2LHLDK/jyLzjv0wAwU5vzSVp14XHLZl7Q0AIoNc20p1EYGa9C/gSPd9CkrWZoG4lMOiAu3tp2PRLVrdXH3ZWSPQq4Ek5MczrUTkmB82XErNbOa8QB1Dw= + file: .tox/dist/python-escpos*.zip + file_glob: true + skip_cleanup: true + on: + tags: true + repo: python-escpos/python-escpos + branch: master + condition: $TRAVIS_PYTHON_VERSION = "3.5" From 7b24df6581e51d11624944dab6e970baf08df3a3 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Thu, 23 Mar 2017 15:35:32 +0100 Subject: [PATCH 2/9] remove patch-coverage because we don't use it --- codecov.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/codecov.yml b/codecov.yml index 3f03c93..7cb16a0 100644 --- a/codecov.yml +++ b/codecov.yml @@ -7,10 +7,6 @@ coverage: default: # status context target: auto threshold: "1%" - patch: - default: - target: auto - threshold: "1%" range: "60...100" comment: off From a0ef820947e1666313916f31ff65f94da03345c7 Mon Sep 17 00:00:00 2001 From: Sam Cheng Date: Wed, 22 Mar 2017 15:16:07 -0700 Subject: [PATCH 3/9] add support for an ESCPOS_CAPABILITIES_FILE environment variable. This is useful in situations where package structure is changed, such as using cx-freeze --- src/escpos/capabilities.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/escpos/capabilities.py b/src/escpos/capabilities.py index e4f1a18..adebf90 100644 --- a/src/escpos/capabilities.py +++ b/src/escpos/capabilities.py @@ -1,10 +1,15 @@ import re import six -from os import path +from os import environ, path import yaml # Load external printer database -with open(path.join(path.dirname(__file__), 'capabilities.json')) as f: +if 'ESCPOS_CAPABILITIES_FILE' in environ: + file_path = environ['ESCPOS_CAPABILITIES_FILE'] +else: + file_path = path.join(path.dirname(__file__), 'capabilities.json') + +with open(file_path) as f: CAPABILITIES = yaml.load(f) PROFILES = CAPABILITIES['profiles'] From 0f33d68f3ab00b80838f433b12382ac7602a6387 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Mon, 27 Mar 2017 15:30:14 +0200 Subject: [PATCH 4/9] add doc for ESCPOS_CAPABILITIES_FILE --- doc/user/usage.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/doc/user/usage.rst b/doc/user/usage.rst index 4ef0439..6d4e462 100644 --- a/doc/user/usage.rst +++ b/doc/user/usage.rst @@ -216,6 +216,32 @@ Here you can download an example, that will print a set of common barcodes: * :download:`barcode.bin ` by `@mike42 `_ +Advanced Usage: change capabilities-profile +------------------------------------------- + +Packaged together with the escpos-code is a capabilities-file. This file in +JSON-format describes the capabilities of different printers. It is developed and hosted in +`escpos-printer-db `_. + +Certain applications like the usage of `cx_freeze `_ might change the +packaging structure. This leads to the capabilities-profile not being found. +In this case you can use the environment-variable `ESCPOS_CAPABILITIES_FILE`. +The following code is an example. + +.. code-block:: shell + + # use packaged capabilities-profile + python-escpos cut + + # use capabilities-profile that you have put in /usr/python-escpos + export ESCPOS_CAPABILITIES_FILE=/usr/python-escpos/capabilities.json + python-escpos cut + + # use packaged file again + unset ESCPOS_CAPABILITIES_FILE + python-escpos cut + + Hint: preprocess printing ------------------------- From 29cc8baab7e94a92cc701ebd5bfdfc6dd296a758 Mon Sep 17 00:00:00 2001 From: Dmytro Katyukha Date: Fri, 3 Feb 2017 16:19:11 +0000 Subject: [PATCH 5/9] Handle cases when fullCut or partCut not available --- .gitignore | 5 +++++ capabilities-data | 2 +- src/escpos/escpos.py | 6 ++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 932ff9b..346833d 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,8 @@ src/escpos/version.py # testing temporary directories test/test-cli-output/ + +# vim swap files +*.swp +*.swn +*.swo diff --git a/capabilities-data b/capabilities-data index 31d2269..b6220ee 160000 --- a/capabilities-data +++ b/capabilities-data @@ -1 +1 @@ -Subproject commit 31d2269651d4d10ca51f59799ee4d05b4c4a1625 +Subproject commit b6220ee5c55b166f06d45a97f230312805b743b1 diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index 3e07fc0..a868daa 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -578,9 +578,11 @@ class Escpos(object): # Fix the size between last line and cut # TODO: handle this with a line feed self._raw(b"\n\n\n\n\n\n") - if mode.upper() == "PART": + + if mode.upper() == "PART" and self.profile.supports('paperPartCut'): self._raw(PAPER_PART_CUT) - else: # DEFAULT MODE: FULL CUT + elif mode.upper() != "PART" and self.profile.supports('paperFullCut'): + # DEFAULT MODE: FULL CUT self._raw(PAPER_FULL_CUT) def cashdraw(self, pin): From abbe32f845d9d1431f066a14087fbd29fd1982da Mon Sep 17 00:00:00 2001 From: Dmytro Katyukha Date: Mon, 6 Feb 2017 14:48:15 +0000 Subject: [PATCH 6/9] Refactored `cut` method. added `print_and_feed` method --- src/escpos/escpos.py | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index a868daa..406c3d5 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -564,7 +564,7 @@ class Escpos(object): self._raw(LINESPACING_FUNCS[divisor] + six.int2byte(spacing)) - def cut(self, mode=''): + def cut(self, mode='FULL'): """ Cut paper. Without any arguments the paper will be cut completely. With 'mode=PART' a partial cut will @@ -573,17 +573,25 @@ class Escpos(object): .. todo:: Check this function on TM-T88II. - :param mode: set to 'PART' for a partial cut + :param mode: set to 'PART' for a partial cut. default: 'FULL' + :raises ValueError: if mode not in ('FULL', 'PART') """ - # Fix the size between last line and cut - # TODO: handle this with a line feed - self._raw(b"\n\n\n\n\n\n") + self.print_and_feed(6) - if mode.upper() == "PART" and self.profile.supports('paperPartCut'): - self._raw(PAPER_PART_CUT) - elif mode.upper() != "PART" and self.profile.supports('paperFullCut'): - # DEFAULT MODE: FULL CUT - self._raw(PAPER_FULL_CUT) + mode = mode.upper() + if mode not in ('FULL', 'PART'): + raise ValueError("Mode must be one of ('FULL', 'PART')") + + if mode == "PART": + if self.profile.supports('paperPartCut'): + self._raw(PAPER_PART_CUT) + elif self.profile.supports('paperFullCut'): + self._raw(PAPER_FULL_CUT) + elif mode == "FULL": + if self.profile.supports('paperFullCut'): + self._raw(PAPER_FULL_CUT) + elif self.profile.supports('paperPartCut'): + self._raw(PAPER_PART_CUT) def cashdraw(self, pin): """ Send pulse to kick the cash drawer @@ -622,6 +630,20 @@ class Escpos(object): else: # DEFAULT: DOES NOTHING pass + def print_and_feed(self, n): + """ Print data in print buffer and feed *n* lines + + if n not in range (0, 255) then ValueError will be raised + + :param n: number of lines to feed. 0 <= n <= 255 + :raises ValueError: if not 0 <= n <= 255 + """ + if 0 <= n <= 255: + # ESC d n + self._raw(ESC + b"d" + six.int2byte(n)) + else: + raise ValueError("n must be betwen 0 and 255") + def control(self, ctl, pos=4): """ Feed control sequences From 43e0a87a74d4b24e840da50d02d46db90aef1d3c Mon Sep 17 00:00:00 2001 From: Dmytro Katyukha Date: Thu, 9 Feb 2017 09:44:57 +0000 Subject: [PATCH 7/9] Updated capabilities data to new version --- capabilities-data | 2 +- src/escpos/cli.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/capabilities-data b/capabilities-data index b6220ee..fd207aa 160000 --- a/capabilities-data +++ b/capabilities-data @@ -1 +1 @@ -Subproject commit b6220ee5c55b166f06d45a97f230312805b743b1 +Subproject commit fd207aa9debc9671405226598a086b282f9f3ad5 diff --git a/src/escpos/cli.py b/src/escpos/cli.py index dad2dfb..665e3b8 100644 --- a/src/escpos/cli.py +++ b/src/escpos/cli.py @@ -100,6 +100,12 @@ ESCPOS_COMMANDS = [ 'option_strings': ('--content',), 'help': 'Text to print as a qr code', 'required': True, + }, + { + 'option_strings': ('--size',), + 'help': 'QR code size (1-16) [default:3]', + 'required': False, + 'type': int, } ], }, From a7ee11a78c451f93a1d8b89a917711a7445acde3 Mon Sep 17 00:00:00 2001 From: Dmytro Katyukha Date: Thu, 9 Feb 2017 14:11:19 +0000 Subject: [PATCH 8/9] Bugfix in `control` method. print_and_feed default `n=1` --- src/escpos/escpos.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index 406c3d5..c238259 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -630,12 +630,12 @@ class Escpos(object): else: # DEFAULT: DOES NOTHING pass - def print_and_feed(self, n): + def print_and_feed(self, n=1): """ Print data in print buffer and feed *n* lines if n not in range (0, 255) then ValueError will be raised - :param n: number of lines to feed. 0 <= n <= 255 + :param n: number of n to feed. 0 <= n <= 255. default: 1 :raises ValueError: if not 0 <= n <= 255 """ if 0 <= n <= 255: @@ -658,11 +658,6 @@ class Escpos(object): :param pos: integer between 1 and 16, controls the horizontal tab position :raises: :py:exc:`~escpos.exceptions.TabPosError` """ - # Set tab positions - if not (1 <= pos <= 16): - raise TabPosError() - else: - self._raw(CTL_SET_HT + six.int2byte(pos)) # Set position if ctl.upper() == "LF": self._raw(CTL_LF) @@ -671,6 +666,12 @@ class Escpos(object): elif ctl.upper() == "CR": self._raw(CTL_CR) elif ctl.upper() == "HT": + if not (1 <= pos <= 16): + raise TabPosError() + else: + # Set tab positions + self._raw(CTL_SET_HT + six.int2byte(pos)) + self._raw(CTL_HT) elif ctl.upper() == "VT": self._raw(CTL_VT) From c1a7d71fd7ad519eafb53a8a587c3b2062e24040 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Wed, 29 Mar 2017 15:45:06 +0200 Subject: [PATCH 9/9] update changelog --- CHANGELOG.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d5a23a3..5ffef2b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,24 @@ Changelog ********* +2017-03-29 - Version 3.0a1 - "Headcrash" +---------------------------------------- +This release is the second alpha release of the new version 3.0. Please +be aware that the API will still change until v3.0 is released. + +changes +^^^^^^^ +- automatically upload releases to GitHub +- add environment variable ESCPOS_CAPABILITIES_FILE +- automatically handle cases where full cut or partial cut is not available +- add print_and_feed + +contributors +^^^^^^^^^^^^ +- Sam Cheng +- Patrick Kanzler +- Dmytro Katyukha + 2017-01-31 - Version 3.0a - "Grey Area" --------------------------------------- This release is the first alpha release of the new version 3.0. Please