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 inlite_available(): "Returns True if the Inlite engine is available" try: from gouda.engines import InliteEngine except ImportError: return False else: return InliteEngine.available()
def engine_choices(): """Returns a dict mapping command-line options to functions that return an engine """ choices = {'libdmtx': LibDMTXEngine, 'zbar': ZbarEngine, 'zxing': ZxingEngine, } choices = {k:v for k,v in choices.iteritems() if v.available()} if AccusoftEngine.available(): choices.update({'accusoft-1d': partial(AccusoftEngine, datamatrix=False), 'accusoft-dm': partial(AccusoftEngine, datamatrix=True), }) if DataSymbolEngine.available(): choices.update({'datasymbol-1d': partial(DataSymbolEngine, datamatrix=False), 'datasymbol-dm': partial(DataSymbolEngine, datamatrix=True), }) if DTKEngine.available(): choices.update({'dtk-1d': partial(DTKEngine, datamatrix=False), 'dtk-dm': partial(DTKEngine, datamatrix=True), }) if InliteEngine.available(): choices.update({'inlite-1d': partial(InliteEngine, format='1d'), 'inlite-dm': partial(InliteEngine, format='datamatrix'), 'inlite-pdf417': partial(InliteEngine, format='pdf417'), 'inlite-qrcode': partial(InliteEngine, format='qrcode'), }) if StecosEngine.available(): choices.update({'stecos-1d' : partial(StecosEngine, datamatrix=False), 'stecos-dm' : partial(StecosEngine, datamatrix=True), }) if SoftekEngine.available(): choices.update({'softek-1d': partial(SoftekEngine, datamatrix=False), 'softek-dm': partial(SoftekEngine, datamatrix=True), }) return choices
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))
res = DataSymbolEngine(datamatrix=False)(self.CODE128) self.assertEqual(1, len(res)) self.assertEqual('Code 128', res[0].type) self.assertIn(res[0].data, ('StegosauDEMO', 'Stegosaurus')) @unittest.skipUnless(DTKEngine.available(), 'DTKEngine unavailable') class TestDTKEngine(TestEngine): def test_1d(self): self._test_1d(DTKEngine(datamatrix=False), type='Code 128') def test_dm(self): self._test_dm(DTKEngine(datamatrix=True)) @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')
def inlite_available(): "Returns True if the Inlite engine is available" return InliteEngine is not None and InliteEngine.available()