ad usable static method
This commit is contained in:
parent
8c220ea7a2
commit
230900ae41
@ -26,10 +26,11 @@ except ImportError:
|
||||
|
||||
# TODO: dev build mode that let's the wrapper bypass?
|
||||
|
||||
def is_usable():
|
||||
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this component can be used due to dependencies."""
|
||||
usable = False
|
||||
if not _DEP_PYCUPS:
|
||||
if _DEP_PYCUPS:
|
||||
usable = True
|
||||
return usable
|
||||
|
||||
@ -40,7 +41,7 @@ def dependency_pycups(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
"""Throw a RuntimeError if pycups is not imported."""
|
||||
if is_usable():
|
||||
if not is_usable():
|
||||
raise RuntimeError(
|
||||
"Printing with PyCups requires the pycups library to"
|
||||
"be installed. Please refer to the documentation on"
|
||||
@ -67,6 +68,15 @@ class CupsPrinter(Escpos):
|
||||
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this printer class is usable.
|
||||
|
||||
Will return True if dependencies are available.
|
||||
Will return False if not.
|
||||
"""
|
||||
return is_usable()
|
||||
|
||||
@dependency_pycups
|
||||
def __init__(self, printer_name=None, *args, **kwargs):
|
||||
"""Class constructor for CupsPrinter.
|
||||
|
@ -11,7 +11,7 @@
|
||||
from ..escpos import Escpos
|
||||
|
||||
|
||||
def is_usable():
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this component can be used due to dependencies."""
|
||||
return True
|
||||
|
||||
@ -30,6 +30,15 @@ class Dummy(Escpos):
|
||||
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this printer class is usable.
|
||||
|
||||
Will return True if dependencies are available.
|
||||
Will return False if not.
|
||||
"""
|
||||
return is_usable()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Init with empty output list."""
|
||||
Escpos.__init__(self, *args, **kwargs)
|
||||
|
@ -11,7 +11,7 @@
|
||||
from ..escpos import Escpos
|
||||
|
||||
|
||||
def is_usable():
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this component can be used due to dependencies."""
|
||||
return True
|
||||
|
||||
@ -30,6 +30,15 @@ class File(Escpos):
|
||||
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this printer class is usable.
|
||||
|
||||
Will return True if dependencies are available.
|
||||
Will return False if not.
|
||||
"""
|
||||
return is_usable()
|
||||
|
||||
def __init__(self, devfile="/dev/usb/lp0", auto_flush=True, *args, **kwargs):
|
||||
"""Initialize file printer with device file.
|
||||
|
||||
|
@ -16,10 +16,10 @@ import sys
|
||||
from ..escpos import Escpos
|
||||
|
||||
|
||||
def is_usable():
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this component can be used due to dependencies."""
|
||||
usable = False
|
||||
if not sys.platform.startswith("win"):
|
||||
if sys.platform.startswith("win"):
|
||||
usable = True
|
||||
return usable
|
||||
|
||||
@ -30,7 +30,7 @@ def dependency_linux_lp(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
"""Throw a RuntimeError if not on a non-Windows system."""
|
||||
if is_usable():
|
||||
if not is_usable():
|
||||
raise RuntimeError(
|
||||
"This printer driver depends on LP which is not"
|
||||
"available on Windows systems."
|
||||
@ -52,6 +52,15 @@ class LP(Escpos):
|
||||
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this printer class is usable.
|
||||
|
||||
Will return True if dependencies are available.
|
||||
Will return False if not.
|
||||
"""
|
||||
return is_usable()
|
||||
|
||||
def __init__(self, printer_name: str, *args, **kwargs):
|
||||
"""LP class constructor.
|
||||
|
||||
|
@ -13,7 +13,7 @@ import socket
|
||||
from ..escpos import Escpos
|
||||
|
||||
|
||||
def is_usable():
|
||||
def is_usable()->bool:
|
||||
"""Indicate whether this component can be used due to dependencies."""
|
||||
return True
|
||||
|
||||
@ -40,6 +40,14 @@ class Network(Escpos):
|
||||
:parts: 1
|
||||
|
||||
"""
|
||||
@staticmethod
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this printer class is usable.
|
||||
|
||||
Will return True if dependencies are available.
|
||||
Will return False if not.
|
||||
"""
|
||||
return is_usable()
|
||||
|
||||
def __init__(self, host, port=9100, timeout=60, *args, **kwargs):
|
||||
"""Initialize network printer.
|
||||
|
@ -24,10 +24,10 @@ except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def is_usable():
|
||||
def is_usable()->bool:
|
||||
"""Indicate whether this component can be used due to dependencies."""
|
||||
usable = False
|
||||
if not _DEP_PYSERIAL:
|
||||
if _DEP_PYSERIAL:
|
||||
usable = True
|
||||
return usable
|
||||
|
||||
@ -38,7 +38,7 @@ def dependency_pyserial(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
"""Throw a RuntimeError if pyserial not installed."""
|
||||
if is_usable():
|
||||
if not is_usable():
|
||||
raise RuntimeError(
|
||||
"Printing with Serial requires the pyserial library to"
|
||||
"be installed. Please refer to the documentation on"
|
||||
@ -60,6 +60,14 @@ class Serial(Escpos):
|
||||
:parts: 1
|
||||
|
||||
"""
|
||||
@staticmethod
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this printer class is usable.
|
||||
|
||||
Will return True if dependencies are available.
|
||||
Will return False if not.
|
||||
"""
|
||||
return is_usable()
|
||||
|
||||
@dependency_pyserial
|
||||
def __init__(
|
||||
|
@ -24,10 +24,10 @@ except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def is_usable():
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this component can be used due to dependencies."""
|
||||
usable = False
|
||||
if not _DEP_USB:
|
||||
if _DEP_USB:
|
||||
usable = True
|
||||
return usable
|
||||
|
||||
@ -38,7 +38,7 @@ def dependency_usb(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
"""Throw a RuntimeError if usb not installed."""
|
||||
if is_usable():
|
||||
if not is_usable():
|
||||
raise RuntimeError(
|
||||
"Printing with USB connection requires a usb library to"
|
||||
"be installed. Please refer to the documentation on"
|
||||
@ -61,6 +61,15 @@ class Usb(Escpos):
|
||||
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this printer class is usable.
|
||||
|
||||
Will return True if dependencies are available.
|
||||
Will return False if not.
|
||||
"""
|
||||
return is_usable()
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
idVendor,
|
||||
|
@ -23,10 +23,10 @@ except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def is_usable():
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this component can be used due to dependencies."""
|
||||
usable = False
|
||||
if not _DEP_WIN32PRINT:
|
||||
if _DEP_WIN32PRINT:
|
||||
usable = True
|
||||
return usable
|
||||
|
||||
@ -37,7 +37,7 @@ def dependency_win32print(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
"""Throw a RuntimeError if win32print not installed."""
|
||||
if is_usable():
|
||||
if not is_usable():
|
||||
raise RuntimeError(
|
||||
"Printing with Win32Raw requires a win32print library to"
|
||||
"be installed. Please refer to the documentation on"
|
||||
@ -60,6 +60,15 @@ class Win32Raw(Escpos):
|
||||
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def is_usable() -> bool:
|
||||
"""Indicate whether this printer class is usable.
|
||||
|
||||
Will return True if dependencies are available.
|
||||
Will return False if not.
|
||||
"""
|
||||
return is_usable()
|
||||
|
||||
@dependency_win32print
|
||||
def __init__(self, printer_name=None, *args, **kwargs):
|
||||
"""Initialize default printer."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user