[IMP] hw_escpos: print a status receipt on printer connection with ip address for easier configuration & debugging. Also setting the driver thread in daemon mode to avoid hanging the tests on the runbot
bzr revid: fva@openerp.com-20140210133109-xll1ijjdhbgpj1kr
This commit is contained in:
parent
356010c357
commit
d930115bd3
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import commands
|
||||||
import logging
|
import logging
|
||||||
import simplejson
|
import simplejson
|
||||||
import os
|
import os
|
||||||
|
@ -52,6 +53,7 @@ class EscposDriver(Thread):
|
||||||
def lockedstart(self):
|
def lockedstart(self):
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
if not self.isAlive():
|
if not self.isAlive():
|
||||||
|
self.daemon = True
|
||||||
self.start()
|
self.start()
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
|
@ -112,6 +114,8 @@ class EscposDriver(Thread):
|
||||||
elif task == 'cashbox':
|
elif task == 'cashbox':
|
||||||
if timestamp >= time.time() - 12:
|
if timestamp >= time.time() - 12:
|
||||||
self.open_cashbox(printer)
|
self.open_cashbox(printer)
|
||||||
|
elif task == 'printstatus':
|
||||||
|
self.print_status(printer)
|
||||||
elif task == 'status':
|
elif task == 'status':
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -123,6 +127,28 @@ class EscposDriver(Thread):
|
||||||
self.lockedstart()
|
self.lockedstart()
|
||||||
self.queue.put((time.time(),task,data))
|
self.queue.put((time.time(),task,data))
|
||||||
|
|
||||||
|
def print_status(self,eprint):
|
||||||
|
localips = ['0.0.0.0','127.0.0.1','127.0.1.1']
|
||||||
|
ips = [ c.split(':')[1].split(' ')[0] for c in commands.getoutput("/sbin/ifconfig").split('\n') if 'inet addr' in c ]
|
||||||
|
ips = [ ip for ip in ips if ip not in localips ]
|
||||||
|
eprint.text('\n\n')
|
||||||
|
eprint.set(align='center',type='b',height=2,width=2)
|
||||||
|
eprint.text('PosBox Status\n')
|
||||||
|
eprint.text('\n')
|
||||||
|
eprint.set(align='center')
|
||||||
|
|
||||||
|
if len(ips) == 0:
|
||||||
|
eprint.text('ERROR: Could not connect to LAN\n\nPlease check that the PosBox is correc-\ntly connected with a network cable,\n that the LAN is setup with DHCP, and\nthat network addresses are available')
|
||||||
|
elif len(ips) == 1:
|
||||||
|
eprint.text('IP Address\n'+ips[0]+'\n')
|
||||||
|
else:
|
||||||
|
eprint.text('IP Addresses\n')
|
||||||
|
for ip in ips:
|
||||||
|
eprint.text(ip+'\n')
|
||||||
|
|
||||||
|
eprint.text('\n\n')
|
||||||
|
eprint.cut()
|
||||||
|
|
||||||
def print_receipt_body(self,eprint,receipt):
|
def print_receipt_body(self,eprint,receipt):
|
||||||
|
|
||||||
def check(string):
|
def check(string):
|
||||||
|
@ -140,7 +166,6 @@ class EscposDriver(Thread):
|
||||||
else:
|
else:
|
||||||
return str(amount)
|
return str(amount)
|
||||||
|
|
||||||
|
|
||||||
def printline(left, right='', width=40, ratio=0.5, indent=0):
|
def printline(left, right='', width=40, ratio=0.5, indent=0):
|
||||||
lwidth = int(width * ratio)
|
lwidth = int(width * ratio)
|
||||||
rwidth = width - lwidth
|
rwidth = width - lwidth
|
||||||
|
@ -252,6 +277,8 @@ class EscposDriver(Thread):
|
||||||
driver = EscposDriver()
|
driver = EscposDriver()
|
||||||
|
|
||||||
hw_proxy.drivers['escpos'] = driver
|
hw_proxy.drivers['escpos'] = driver
|
||||||
|
|
||||||
|
driver.push_task('printstatus')
|
||||||
|
|
||||||
class EscposProxy(hw_proxy.Proxy):
|
class EscposProxy(hw_proxy.Proxy):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue