refactor PEP8 and code style

This commit is contained in:
Patrick Kanzler 2016-06-19 12:25:40 +02:00
parent e814396bd8
commit 6697922b74
7 changed files with 48 additions and 37 deletions

View File

@ -18,6 +18,7 @@ import sys
import six import six
from . import config from . import config
# Must be defined before it's used in DEMO_FUNCTIONS # Must be defined before it's used in DEMO_FUNCTIONS
def str_to_bool(string): def str_to_bool(string):
""" Used as a type in argparse so that we get back a proper """ Used as a type in argparse so that we get back a proper
@ -427,6 +428,7 @@ ESCPOS_COMMANDS = [
}, },
] ]
def main(): def main():
""" """
@ -504,7 +506,6 @@ def main():
saved_config.load(config_path) saved_config.load(config_path)
printer = saved_config.printer() printer = saved_config.printer()
if not printer: if not printer:
raise Exception('No printers loaded from config') raise Exception('No printers loaded from config')
@ -519,6 +520,7 @@ def main():
command_arguments['printer'] = printer command_arguments['printer'] = printer
globals()[target_command](**command_arguments) globals()[target_command](**command_arguments)
def demo(printer, **kwargs): def demo(printer, **kwargs):
""" """
Prints specificed demos. Called when CLI is passed `demo`. This function Prints specificed demos. Called when CLI is passed `demo`. This function

View File

@ -16,6 +16,7 @@ import yaml
from . import printer from . import printer
from . import exceptions from . import exceptions
class Config(object): class Config(object):
""" Configuration handler class. """ Configuration handler class.
@ -115,4 +116,3 @@ class Config(object):
self._printer = getattr(printer, self._printer_name)(**self._printer_config) self._printer = getattr(printer, self._printer_name)(**self._printer_config)
return self._printer return self._printer

View File

@ -45,7 +45,7 @@ HW_SELECT = ESC + b'=\x01' # Printer select
HW_RESET = ESC + b'\x3f\x0a\x00' # Reset printer hardware HW_RESET = ESC + b'\x3f\x0a\x00' # Reset printer hardware
# (TODO: Where is this specified?) # (TODO: Where is this specified?)
#{ Cash Drawer (ESC p <pin> <on time: 2*ms> <off time: 2*ms>) # Cash Drawer (ESC p <pin> <on time: 2*ms> <off time: 2*ms>)
_CASH_DRAWER = lambda m, t1='', t2='': ESC + b'p' + m + six.int2byte(t1) + six.int2byte(t2) _CASH_DRAWER = lambda m, t1='', t2='': ESC + b'p' + m + six.int2byte(t1) + six.int2byte(t2)
CD_KICK_2 = _CASH_DRAWER(b'\x00', 50, 50) # Sends a pulse to pin 2 [] CD_KICK_2 = _CASH_DRAWER(b'\x00', 50, 50) # Sends a pulse to pin 2 []
CD_KICK_5 = _CASH_DRAWER(b'\x01', 50, 50) # Sends a pulse to pin 5 [] CD_KICK_5 = _CASH_DRAWER(b'\x01', 50, 50) # Sends a pulse to pin 5 []
@ -184,13 +184,13 @@ BARCODE_TYPES = {
'B': BARCODE_TYPE_B, 'B': BARCODE_TYPE_B,
} }
## QRCode error correction levels # QRCode error correction levels
QR_ECLEVEL_L = 0 QR_ECLEVEL_L = 0
QR_ECLEVEL_M = 1 QR_ECLEVEL_M = 1
QR_ECLEVEL_Q = 2 QR_ECLEVEL_Q = 2
QR_ECLEVEL_H = 3 QR_ECLEVEL_H = 3
## QRcode models # QRcode models
QR_MODEL_1 = 1 QR_MODEL_1 = 1
QR_MODEL_2 = 2 QR_MODEL_2 = 2
QR_MICRO = 3 QR_MICRO = 3

View File

@ -24,6 +24,7 @@ from .exceptions import *
from abc import ABCMeta, abstractmethod # abstract base class support from abc import ABCMeta, abstractmethod # abstract base class support
from escpos.image import EscposImage from escpos.image import EscposImage
@six.add_metaclass(ABCMeta) @six.add_metaclass(ABCMeta)
class Escpos(object): class Escpos(object):
""" ESC/POS Printer object """ ESC/POS Printer object
@ -122,11 +123,14 @@ class Escpos(object):
""" Print QR Code for the provided string """ Print QR Code for the provided string
:param content: The content of the code. Numeric data will be more efficiently compacted. :param content: The content of the code. Numeric data will be more efficiently compacted.
:param ec: Error-correction level to use. One of QR_ECLEVEL_L (default), QR_ECLEVEL_M, QR_ECLEVEL_Q or QR_ECLEVEL_H. :param ec: Error-correction level to use. One of QR_ECLEVEL_L (default), QR_ECLEVEL_M, QR_ECLEVEL_Q or
QR_ECLEVEL_H.
Higher error correction results in a less compact code. Higher error correction results in a less compact code.
:param size: Pixel size to use. Must be 1-16 (default 3) :param size: Pixel size to use. Must be 1-16 (default 3)
:param model: QR code model to use. Must be one of QR_MODEL_1, QR_MODEL_2 (default) or QR_MICRO (not supported by all printers). :param model: QR code model to use. Must be one of QR_MODEL_1, QR_MODEL_2 (default) or QR_MICRO (not supported
:param native: True to render the code on the printer, False to render the code as an image and send it to the printer (Default) by all printers).
:param native: True to render the code on the printer, False to render the code as an image and send it to the
printer (Default)
""" """
# Basic validation # Basic validation
if ec not in [QR_ECLEVEL_L, QR_ECLEVEL_M, QR_ECLEVEL_H, QR_ECLEVEL_Q]: if ec not in [QR_ECLEVEL_L, QR_ECLEVEL_M, QR_ECLEVEL_H, QR_ECLEVEL_Q]:
@ -435,7 +439,8 @@ class Escpos(object):
col_count = self.columns if columns is None else columns col_count = self.columns if columns is None else columns
self.text(textwrap.fill(txt, col_count)) self.text(textwrap.fill(txt, col_count))
def set(self, align='left', font='a', text_type='normal', width=1, height=1, density=9, invert=False, smooth=False, flip=False): def set(self, align='left', font='a', text_type='normal', width=1, height=1, density=9, invert=False, smooth=False,
flip=False):
""" Set text properties by sending them to the printer """ Set text properties by sending them to the printer
:param align: horizontal position for text, possible values are: :param align: horizontal position for text, possible values are:

View File

@ -210,6 +210,7 @@ class ConfigNotFoundError(Error):
def __str__(self): def __str__(self):
return "Configuration not found ({msg})".format(msg=self.msg) return "Configuration not found ({msg})".format(msg=self.msg)
class ConfigSyntaxError(Error): class ConfigSyntaxError(Error):
""" The configuration file is invalid """ The configuration file is invalid
@ -224,6 +225,7 @@ class ConfigSyntaxError(Error):
def __str__(self): def __str__(self):
return "Configuration syntax is invalid ({msg})".format(msg=self.msg) return "Configuration syntax is invalid ({msg})".format(msg=self.msg)
class ConfigSectionMissingError(Error): class ConfigSectionMissingError(Error):
""" The configuration file is missing a section """ The configuration file is missing a section

View File

@ -21,6 +21,7 @@ import socket
from .escpos import Escpos from .escpos import Escpos
from .exceptions import * from .exceptions import *
class Usb(Escpos): class Usb(Escpos):
""" USB printer """ USB printer
@ -261,6 +262,7 @@ class File(Escpos):
self.device.flush() self.device.flush()
self.device.close() self.device.close()
class Dummy(Escpos): class Dummy(Escpos):
""" Dummy printer """ Dummy printer

View File

@ -3,7 +3,7 @@
import os import os
import sys import sys
from setuptools import setup from setuptools import setup
from setuptools.command.test import test as TestCommand from setuptools.command.test import test as test_command
def read(fname): def read(fname):
@ -11,18 +11,18 @@ def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read() return open(os.path.join(os.path.dirname(__file__), fname)).read()
class Tox(TestCommand): class Tox(test_command):
"""proxy class that enables tox to be run with setup.py test""" """proxy class that enables tox to be run with setup.py test"""
user_options = [('tox-args=', 'a', "Arguments to pass to tox")] user_options = [('tox-args=', 'a', "Arguments to pass to tox")]
def initialize_options(self): def initialize_options(self):
"""initialize the user-options""" """initialize the user-options"""
TestCommand.initialize_options(self) test_command.initialize_options(self)
self.tox_args = None self.tox_args = None
def finalize_options(self): def finalize_options(self):
"""finalize user-options""" """finalize user-options"""
TestCommand.finalize_options(self) test_command.finalize_options(self)
self.test_args = [] self.test_args = []
self.test_suite = True self.test_suite = True