|
|
@ -6,6 +6,7 @@ import json
|
|
|
|
import os.path
|
|
|
|
import os.path
|
|
|
|
import subprocess
|
|
|
|
import subprocess
|
|
|
|
import tempfile
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
import textwrap
|
|
|
|
import threading
|
|
|
|
import threading
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
@ -67,11 +68,10 @@ class Bureau(object):
|
|
|
|
self.api = {}
|
|
|
|
self.api = {}
|
|
|
|
|
|
|
|
|
|
|
|
modpath = os.path.dirname(__file__)
|
|
|
|
modpath = os.path.dirname(__file__)
|
|
|
|
phantomjs = os.path.join(modpath, "..", "lib", "phantomjs", "bin",
|
|
|
|
slimerjs = os.path.join(modpath, "..", "lib", "slimerjs", "slimerjs")
|
|
|
|
"phantomjs")
|
|
|
|
|
|
|
|
renderer = os.path.join(modpath, "..", "lib", "rasterize.js")
|
|
|
|
renderer = os.path.join(modpath, "..", "lib", "rasterize.js")
|
|
|
|
self.phantomjs = os.path.abspath(phantomjs)
|
|
|
|
self.slimerjs = os.path.abspath(slimerjs)
|
|
|
|
self.html2pdf = self.phantomjs + " " + os.path.abspath(renderer) + " "
|
|
|
|
self.html2pdf = self.slimerjs + " " + os.path.abspath(renderer) + " "
|
|
|
|
mypath = inspect.getfile(self.__class__)
|
|
|
|
mypath = inspect.getfile(self.__class__)
|
|
|
|
self.mdir = os.path.dirname(mypath)
|
|
|
|
self.mdir = os.path.dirname(mypath)
|
|
|
|
|
|
|
|
|
|
|
@ -125,7 +125,10 @@ class Bureau(object):
|
|
|
|
if len(resp) == 0:
|
|
|
|
if len(resp) == 0:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
elif resp[0] == "0":
|
|
|
|
elif resp[0] == "0":
|
|
|
|
return json.loads(resp[1:])
|
|
|
|
if len(resp) == 1:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return json.loads(resp[1:])
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# TODO: this may need some better error handling
|
|
|
|
# TODO: this may need some better error handling
|
|
|
|
return resp
|
|
|
|
return resp
|
|
|
@ -213,15 +216,16 @@ class Bureau(object):
|
|
|
|
print("rendering with: ", self.html2pdf + htmlpath + " " + pdfpath)
|
|
|
|
print("rendering with: ", self.html2pdf + htmlpath + " " + pdfpath)
|
|
|
|
subprocess.call(self.html2pdf + htmlpath + " " + pdfpath +
|
|
|
|
subprocess.call(self.html2pdf + htmlpath + " " + pdfpath +
|
|
|
|
" A4 1920px", shell=True)
|
|
|
|
" A4 1920px", shell=True)
|
|
|
|
#subprocess.call("lpr " + pdfpath, shell=True)
|
|
|
|
subprocess.call("lpr " + pdfpath, shell=True)
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: make this asynchronous
|
|
|
|
# TODO: make this asynchronous
|
|
|
|
def print_small(self, text, printer="/dev/usb/lp0"):
|
|
|
|
def print_small(self, text, printer="/dev/usb/lp0"):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
print on Thermal Line printer.
|
|
|
|
print on Thermal Line printer.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
# TODO: look this up in config
|
|
|
|
# TODO: look up device and width in config
|
|
|
|
lp = open(printer, "w")
|
|
|
|
lp = open(printer, "w")
|
|
|
|
|
|
|
|
text = textwrap.fill(text, width=32)
|
|
|
|
text += "\r\n" * 5
|
|
|
|
text += "\r\n" * 5
|
|
|
|
# text += ".d0"
|
|
|
|
# text += ".d0"
|
|
|
|
lp.write(text)
|
|
|
|
lp.write(text)
|
|
|
|