diff --git a/src/escpos/printer/cups.py b/src/escpos/printer/cups.py index 5f7937c..60e8468 100644 --- a/src/escpos/printer/cups.py +++ b/src/escpos/printer/cups.py @@ -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. diff --git a/src/escpos/printer/dummy.py b/src/escpos/printer/dummy.py index 297c488..36601ba 100644 --- a/src/escpos/printer/dummy.py +++ b/src/escpos/printer/dummy.py @@ -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) diff --git a/src/escpos/printer/file.py b/src/escpos/printer/file.py index d1c970c..acf4802 100644 --- a/src/escpos/printer/file.py +++ b/src/escpos/printer/file.py @@ -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. diff --git a/src/escpos/printer/lp.py b/src/escpos/printer/lp.py index d091032..980c35f 100644 --- a/src/escpos/printer/lp.py +++ b/src/escpos/printer/lp.py @@ -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. diff --git a/src/escpos/printer/network.py b/src/escpos/printer/network.py index 80ff8b1..b1673c4 100644 --- a/src/escpos/printer/network.py +++ b/src/escpos/printer/network.py @@ -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. diff --git a/src/escpos/printer/serial.py b/src/escpos/printer/serial.py index 5905feb..48fbe6d 100644 --- a/src/escpos/printer/serial.py +++ b/src/escpos/printer/serial.py @@ -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__( diff --git a/src/escpos/printer/usb.py b/src/escpos/printer/usb.py index d0f7643..03f911f 100644 --- a/src/escpos/printer/usb.py +++ b/src/escpos/printer/usb.py @@ -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, diff --git a/src/escpos/printer/win32raw.py b/src/escpos/printer/win32raw.py index d02ebf1..d28b8c2 100644 --- a/src/escpos/printer/win32raw.py +++ b/src/escpos/printer/win32raw.py @@ -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."""