From 5b19ae8a5965fa3234725709b946b9bfb6930254 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 8 May 2015 12:49:19 +0200 Subject: [PATCH] [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 --- addons/hw_scale/__openerp__.py | 1 + addons/hw_scale/controllers/main.py | 20 +++++++++++++------- addons/hw_scanner/__openerp__.py | 1 + addons/hw_scanner/controllers/main.py | 15 ++++++--------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/addons/hw_scale/__openerp__.py b/addons/hw_scale/__openerp__.py index 98085771452..63542fa88d0 100644 --- a/addons/hw_scale/__openerp__.py +++ b/addons/hw_scale/__openerp__.py @@ -37,6 +37,7 @@ such as the Mettler Toledo Ariva. """, 'author': 'OpenERP SA', 'depends': ['hw_proxy'], + 'external_dependencies': {'python': ['serial']}, 'test': [ ], 'installable': True, diff --git a/addons/hw_scale/controllers/main.py b/addons/hw_scale/controllers/main.py index fcfa6ede536..0c39ffcde9d 100644 --- a/addons/hw_scale/controllers/main.py +++ b/addons/hw_scale/controllers/main.py @@ -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 diff --git a/addons/hw_scanner/__openerp__.py b/addons/hw_scanner/__openerp__.py index fa8bb9daccb..b24532c4a3f 100644 --- a/addons/hw_scanner/__openerp__.py +++ b/addons/hw_scanner/__openerp__.py @@ -38,6 +38,7 @@ point of sale module. """, 'author': 'OpenERP SA', 'depends': ['hw_proxy'], + 'external_dependencies': {'python': ['evdev']}, 'test': [ ], 'installable': True, diff --git a/addons/hw_scanner/controllers/main.py b/addons/hw_scanner/controllers/main.py index 057674c1ca1..0ae08d7d36b 100644 --- a/addons/hw_scanner/controllers/main.py +++ b/addons/hw_scanner/controllers/main.py @@ -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