# Path: lib/process.py
# def get_simple_cmd_output(cmd, stderr=STDOUT):
#     """Execute a simple external command and get its output.
# 
#     The command contains no pipes. Error messages are
#     redirected to the standard output by default.
#     """
#     args = shlex.split(cmd)
#     return Popen(args, stdout=PIPE, stderr=stderr).communicate()[0].decode("utf8")


import config as cfg
from lib.process import get_simple_cmd_output
#!/usr/bin/env python3

"""
OCR with the Tesseract engine from Google
this is a wrapper around pytesser (http://code.google.com/p/pytesser/)
"""



def image_file_to_string(fname):
    """Convert an image file to text using OCR."""
    cmd = "{tesseract} {fname} stdout".format(
        tesseract=cfg.TESSERACT,
        fname=fname
    )

# Path: lib/process.py
# def get_simple_cmd_output(cmd, stderr=STDOUT):
#     """Execute a simple external command and get its output.
# 
#     The command contains no pipes. Error messages are
#     redirected to the standard output by default.
#     """
#     args = shlex.split(cmd)
#     return Popen(args, stdout=PIPE, stderr=stderr).communicate()[0].decode("utf8")


# Path: lib/ocr.py
import config as cfg
from lib.process import get_simple_cmd_output

#!/usr/bin/env python3

"""
OCR with the Tesseract engine from Google
this is a wrapper around pytesser (http://code.google.com/p/pytesser/)
"""



def image_file_to_string(fname):
    """Convert an image file to text using OCR."""
    cmd = "{tesseract} {fname} stdout".format(
        tesseract=cfg.TESSERACT,
        fname=fname
    )

    return get_simple_cmd_output(cmd).rstrip('\n')