[FIX] hw_*: enforce Python dependencies + disable if missing dependency
Prevents installing the hw_* modules at all when the python dependencies are missing. If they were already installed do not start the hardware threads to avoid wasting resources and logging errors
This commit is contained in:
parent
5275c10e70
commit
5b19ae8a59
|
@ -37,6 +37,7 @@ such as the Mettler Toledo Ariva.
|
|||
""",
|
||||
'author': 'OpenERP SA',
|
||||
'depends': ['hw_proxy'],
|
||||
'external_dependencies': {'python': ['serial']},
|
||||
'test': [
|
||||
],
|
||||
'installable': True,
|
||||
|
|
|
@ -178,28 +178,34 @@ class Scale(Thread):
|
|||
if not self.device:
|
||||
time.sleep(5)
|
||||
|
||||
s = Scale()
|
||||
|
||||
hw_proxy.drivers['scale'] = s
|
||||
scale_thread = None
|
||||
if serial:
|
||||
scale_thread = Scale()
|
||||
hw_proxy.drivers['scale'] = scale_thread
|
||||
|
||||
class ScaleDriver(hw_proxy.Proxy):
|
||||
@http.route('/hw_proxy/scale_read/', type='json', auth='none', cors='*')
|
||||
def scale_read(self):
|
||||
return {'weight':s.get_weight(), 'unit':'kg', 'info':s.get_weight_info()}
|
||||
if scale_thread:
|
||||
return {'weight': scale_thread.get_weight(), 'unit':'kg', 'info': scale_thread.get_weight_info()}
|
||||
return None
|
||||
|
||||
@http.route('/hw_proxy/scale_zero/', type='json', auth='none', cors='*')
|
||||
def scale_zero(self):
|
||||
s.set_zero()
|
||||
if scale_thread:
|
||||
scale_thread.set_zero()
|
||||
return True
|
||||
|
||||
@http.route('/hw_proxy/scale_tare/', type='json', auth='none', cors='*')
|
||||
def scale_tare(self):
|
||||
s.set_tare()
|
||||
if scale_thread:
|
||||
scale_thread.set_tare()
|
||||
return True
|
||||
|
||||
@http.route('/hw_proxy/scale_clear_tare/', type='json', auth='none', cors='*')
|
||||
def scale_clear_tare(self):
|
||||
s.clear_tare()
|
||||
if scale_thread:
|
||||
scale_thread.clear_tare()
|
||||
return True
|
||||
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ point of sale module.
|
|||
""",
|
||||
'author': 'OpenERP SA',
|
||||
'depends': ['hw_proxy'],
|
||||
'external_dependencies': {'python': ['evdev']},
|
||||
'test': [
|
||||
],
|
||||
'installable': True,
|
||||
|
|
|
@ -111,8 +111,6 @@ class Scanner(Thread):
|
|||
|
||||
def get_device(self):
|
||||
try:
|
||||
if not evdev:
|
||||
return None
|
||||
devices = [ device for device in listdir(self.input_dir)]
|
||||
keyboards = [ device for device in devices if ('kbd' in device) and ('keyboard' not in device.lower())]
|
||||
scanners = [ device for device in devices if ('barcode' in device.lower()) or ('scanner' in device.lower())]
|
||||
|
@ -135,7 +133,6 @@ class Scanner(Thread):
|
|||
been returned before. This is necessary to catch barcodes scanned while the POS is
|
||||
busy reading another barcode
|
||||
"""
|
||||
|
||||
self.lockedstart()
|
||||
|
||||
while True:
|
||||
|
@ -204,12 +201,12 @@ class Scanner(Thread):
|
|||
except Exception as e:
|
||||
self.set_status('error',str(e))
|
||||
|
||||
s = Scanner()
|
||||
|
||||
hw_proxy.drivers['scanner'] = s
|
||||
scanner_thread = None
|
||||
if evdev:
|
||||
scanner_thread = Scanner()
|
||||
hw_proxy.drivers['scanner'] = scanner_thread
|
||||
|
||||
class ScannerDriver(hw_proxy.Proxy):
|
||||
@http.route('/hw_proxy/scanner', type='json', auth='none', cors='*')
|
||||
def scanner(self):
|
||||
return s.get_barcode()
|
||||
|
||||
def scanner_thread(self):
|
||||
return scanner_thread.get_barcode() if scanner_thread else None
|
||||
|
|
Loading…
Reference in New Issue