def zbar_available(): "Returns True if the zbar engine is available" try: from gouda.engines import ZbarEngine except ImportError: return False else: return ZbarEngine.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))
# Evaluation SDK replaces the second character of the decoded # value with a random character, so this test needs to do some extra work. def test_1d(self): res = StecosEngine(datamatrix=False)(self.CODE128) self.assertEqual(1, len(res)) self.assertEqual('Code 128', res[0].type) self.assertEqual('egosaurus', res[0].data[2:]) def test_dm(self): res = StecosEngine(datamatrix=True)(self.DATAMATRIX) self.assertEqual(1, len(res)) self.assertEqual('Data Matrix', res[0].type) self.assertEqual('iceratops', res[0].data[2:]) @unittest.skipUnless(ZbarEngine.available(), 'ZbarEngine unavailable') class TestZbarEngine(TestEngine): def test_1d(self): self._test_1d(ZbarEngine()) def test_qr(self): self._test_qr(ZbarEngine(), type='QRCODE') @unittest.skipUnless(ZxingEngine.available(), 'ZxingEngine unavailable') class TestZxingEngine(TestEngine): def test_dm(self): self._test_dm(ZxingEngine()) if __name__=='__main__': unittest.main()
def zbar_available(): "Returns True if the zbar engine is available" return ZbarEngine is not None and ZbarEngine.available()