add dependency check for lp
This commit is contained in:
parent
33329867d2
commit
c58381230b
@ -8,15 +8,31 @@
|
|||||||
:license: MIT
|
:license: MIT
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import functools
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from ..escpos import Escpos
|
from ..escpos import Escpos
|
||||||
|
|
||||||
if not sys.platform.startswith("win"):
|
|
||||||
|
|
||||||
class LP(Escpos):
|
def dependency_linux_lp(func):
|
||||||
|
"""Indicate dependency on non Windows."""
|
||||||
|
|
||||||
|
@functools.wraps(func)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
"""Throw a RuntimeError if not on a non-Windows system."""
|
||||||
|
if not sys.platform.startswith("win"):
|
||||||
|
raise RuntimeError(
|
||||||
|
"This printer driver depends on LP which is not"
|
||||||
|
"available on Windows systems."
|
||||||
|
)
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
class LP(Escpos):
|
||||||
"""Simple UNIX lp command raw printing.
|
"""Simple UNIX lp command raw printing.
|
||||||
|
|
||||||
Thanks to `Oyami-Srk comment <https://github.com/python-escpos/python-escpos/pull/348#issuecomment-549558316>`_.
|
Thanks to `Oyami-Srk comment <https://github.com/python-escpos/python-escpos/pull/348#issuecomment-549558316>`_.
|
||||||
@ -41,6 +57,7 @@ if not sys.platform.startswith("win"):
|
|||||||
self.auto_flush = kwargs.get("auto_flush", True)
|
self.auto_flush = kwargs.get("auto_flush", True)
|
||||||
self.open()
|
self.open()
|
||||||
|
|
||||||
|
@dependency_linux_lp
|
||||||
def open(self):
|
def open(self):
|
||||||
"""Invoke _lp_ in a new subprocess and wait for commands."""
|
"""Invoke _lp_ in a new subprocess and wait for commands."""
|
||||||
self.lp = subprocess.Popen(
|
self.lp = subprocess.Popen(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user