Skip to content

Commit

Permalink
[#1] Expose available engines
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawrence Hudson committed Mar 1, 2016
1 parent 8c52106 commit 69cc0c2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 54 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# v0.1.4
- #1 Expose available engines
2 changes: 1 addition & 1 deletion gouda/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.3'
__version__ = '0.1.4'
58 changes: 5 additions & 53 deletions gouda/bin/decode_barcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand All @@ -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',
Expand All @@ -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)
Expand Down
56 changes: 56 additions & 0 deletions gouda/engines/options.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 69cc0c2

Please sign in to comment.