def __call__(self, progress): """ """ debug_print('BarcodePlugin.__call__') if InliteEngine.available(): engine = InliteEngine(datamatrix=True) elif LibDMTXEngine.available(): engine = LibDMTXEngine() else: raise InselectError('No barcode decoding engine available') progress('Loading full-res image') image_array = self.document.scanned.array items = self.document.items for index, item, crop in izip(count(), items, self.document.crops): msg = u'Reading barcodes in box {0} of {1}'.format(1 + index, len(items)) progress(msg) barcodes = self._decode_barcodes(engine, crop, progress) if barcodes: debug_print('Crop [{0}] - found [{1}]'.format(index, barcodes)) # TODO LH This mapping to come from metadata config? item['fields']['catalogNumber'] = barcodes else: debug_print('Crop [{0}] - no barcodes'.format(index)) self.items = items debug_print('BarcodePlugin.__call__ exiting. [{0}] boxes'.format(len(items)))
def libdmtx_available(): "Returns True if the libdmtx engine is available" try: from gouda.engines import LibDMTXEngine except ImportError: return False else: return LibDMTXEngine.available()
def load_engine(): """Returns an instance of the user's choice of barcode reading engine """ try: from gouda.engines import InliteEngine, LibDMTXEngine, ZbarEngine except ImportError: raise InselectError('Barcode decoding is not available') else: settings = current_settings() engine = settings['engine'] if 'libdmtx' == engine: return LibDMTXEngine() elif 'zbar' == engine: return ZbarEngine() elif 'inlite' == engine: return InliteEngine(settings['inlite-format']) else: raise ValueError( 'Unrecognised barcode reader [{0}]'.format(engine))
@unittest.skipUnless(InliteEngine.available(), 'InliteEngine unavailable') class TestInliteEngine(TestEngine): def test_1d(self): self._test_1d(InliteEngine(format='1d'), type='Unknown') def test_dm(self): self._test_dm(InliteEngine(format='datamatrix')) def test_qr(self): self._test_qr(InliteEngine(format='qrcode')) def test_pdf417(self): self._test_pdf417(InliteEngine(format='pdf417')) @unittest.skipUnless(LibDMTXEngine.available(), 'LibDMTXEngine unavailable') class TestLibDMTXEngine(TestEngine): def test_dm(self): self._test_dm(LibDMTXEngine()) @unittest.skipUnless(SoftekEngine.available(), 'SoftekEngine unavailable') class TestSoftekEngine(TestEngine): # Evaluation SDK replaces the last three characters of the # decoded value with '???', so this test needs to do some extra work. @unittest.skipIf(sys.platform.startswith('win'), "Windows SoftekEngine not able to decode self.CODE128") def test_1d(self): res = SoftekEngine(datamatrix=False)(self.CODE128) self.assertEqual(1, len(res))
def libdmtx_available(): "Returns True if the libdmtx engine is available" return LibDMTXEngine is not None and LibDMTXEngine.available()