diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8468c3f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +# v0.1.4 +- #1 Expose available engines diff --git a/README.md b/README.md index da6f9b4..21e98fe 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,7 @@ apps respectively, provided with the SDK. conda install --channel https://conda.binstar.org/weiyan zbar #### Windows 32-bit -Install the latest relerase of +Install the latest release of [zbar](https://github.com/NaturalHistoryMuseum/zbar-python-patched/): pip install https://github.com/NaturalHistoryMuseum/zbar-python-patched/releases/download/v0.10/zbar-0.10-cp27-none-win32.whl diff --git a/gouda/__init__.py b/gouda/__init__.py index 8ce9b36..7525d19 100644 --- a/gouda/__init__.py +++ b/gouda/__init__.py @@ -1 +1 @@ -__version__ = '0.1.3' +__version__ = '0.1.4' diff --git a/gouda/bin/decode_barcode.py b/gouda/bin/decode_barcode.py index 1cdda33..51e153d 100755 --- a/gouda/bin/decode_barcode.py +++ b/gouda/bin/decode_barcode.py @@ -16,9 +16,7 @@ import gouda import gouda.util -from gouda.engines import (AccusoftEngine, DataSymbolEngine, DTKEngine, - InliteEngine, LibDMTXEngine, StecosEngine, - SoftekEngine, ZbarEngine, ZxingEngine) +from gouda.engine.options import engine_options from gouda.gouda_error import GoudaError from gouda.util import expand_wildcard, read_image from gouda.strategies.roi.roi import roi @@ -129,52 +127,6 @@ def result(self, path, result): print(' Renamed to [{0}]'.format(dest)) -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 - - if __name__=='__main__': # TODO ROI candidate area max and/or min? # TODO Give area min and max as percentage of total image area? @@ -186,10 +138,10 @@ def engine_choices(): parser.add_argument('--action', '-a', choices=['basic', 'terse', 'csv', 'rename'], default='basic') parser.add_argument('--greyscale', '-g', action='store_true') - choices = engine_choices() - if not choices: + options = engine_options() + if not options: raise GoudaError('No engines are available') - parser.add_argument('engine', choices=sorted(choices.keys())) + parser.add_argument('engine', choices=sorted(options.keys())) parser.add_argument('image', nargs='+', help='path to an image or directory') parser.add_argument('-v', '--version', action='version', @@ -199,7 +151,7 @@ def engine_choices(): gouda.util.DEBUG_PRINT = args.debug - engine = choices[args.engine]() + engine = options[args.engine]() if 'csv'==args.action: visitor = CSVReportVisitor(args.engine, args.greyscale) diff --git a/gouda/engines/options.py b/gouda/engines/options.py new file mode 100644 index 0000000..3131725 --- /dev/null +++ b/gouda/engines/options.py @@ -0,0 +1,56 @@ +from gouda.engines import (AccusoftEngine, DataSymbolEngine, DTKEngine, + InliteEngine, LibDMTXEngine, StecosEngine, + SoftekEngine, ZbarEngine, ZxingEngine) + + +def engine_options(): + """Returns a dict mapping textual descriptions to functions that return an + engine. + """ + options = { + 'libdmtx': LibDMTXEngine, + 'zbar': ZbarEngine, + 'zxing': ZxingEngine, + } + + options = {k: v for k, v in options.iteritems() if v.available()} + + if AccusoftEngine.available(): + options.update({ + 'accusoft-1d': partial(AccusoftEngine, datamatrix=False), + 'accusoft-dm': partial(AccusoftEngine, datamatrix=True), + }) + + if DataSymbolEngine.available(): + options.update({ + 'datasymbol-1d': partial(DataSymbolEngine, datamatrix=False), + 'datasymbol-dm': partial(DataSymbolEngine, datamatrix=True), + }) + + if DTKEngine.available(): + options.update({ + 'dtk-1d': partial(DTKEngine, datamatrix=False), + 'dtk-dm': partial(DTKEngine, datamatrix=True), + }) + + if InliteEngine.available(): + options.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(): + options.update({ + 'stecos-1d': partial(StecosEngine, datamatrix=False), + 'stecos-dm': partial(StecosEngine, datamatrix=True), + }) + + if SoftekEngine.available(): + options.update({ + 'softek-1d': partial(SoftekEngine, datamatrix=False), + 'softek-dm': partial(SoftekEngine, datamatrix=True), + }) + + return options