From 8cfbdaf0d022dea822e76f1b93bf6a672f5ac07d Mon Sep 17 00:00:00 2001 From: Jim Barlow Date: Sun, 19 Jan 2014 19:06:19 -0800 Subject: [PATCH] Fix a silly typo, and other minor cleanup --- src/leptonica.py | 18 +++++++++--------- src/ocrPage.sh | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/leptonica.py b/src/leptonica.py index f49cf097..10e69f48 100644 --- a/src/leptonica.py +++ b/src/leptonica.py @@ -81,7 +81,7 @@ lept.getLeptonicaVersion.argtypes = [] lept.getLeptonicaVersion.restype = C.c_char_p -class Leptonica(object): +class LeptonicaErrorTrap(object): """Context manager to trap errors reported by Leptonica. Leptonica's error return codes are unreliable to the point of being @@ -102,17 +102,17 @@ class Leptonica(object): os.dup2(self.tmpfile.fileno(), sys.stderr.fileno()) return - def __exit__(self, type, value, traceback): + def __exit__(self, exc_type, exc_value, traceback): # Restore old stderr os.dup2(self.old_stderr_fileno, sys.stderr.fileno()) # Get data from tmpfile (in with block to ensure it is closed) with self.tmpfile as tmpfile: - tmpfile.seek(0) + tmpfile.seek(0) # Cursor will be at end, so move back to beginning leptonica_output = tmpfile.read().decode(errors='replace') # If there are Python errors, let them bubble up - if type: + if exc_type: stderr(leptonica_output) return False @@ -142,13 +142,13 @@ def pixRead(filename): fails then the object will wrap a C null pointer. """ - with Leptonica(): + with LeptonicaErrorTrap(): return lept.pixRead(filename.encode(sys.getfilesystemencoding())) def pixScale(pix, scalex, scaley): """Returns the pix object rescaled according to the proportions given.""" - with Leptonica(): + with LeptonicaErrorTrap(): return lept.pixScale(pix, scalex, scaley) @@ -162,7 +162,7 @@ def pixDeskew(pix, reduction_factor=0): for skew angle """ - with Leptonica(): + with LeptonicaErrorTrap(): return lept.pixDeskew(pix, reduction_factor) @@ -173,7 +173,7 @@ def pixWriteImpliedFormat(filename, pix, jpeg_quality=0, jpeg_progressive=0): jpeg_ progressive -- (iff JPEG; 0 for baseline seq., 1 for progressive) """ - with Leptonica(): + with LeptonicaErrorTrap(): lept.pixWriteImpliedFormat( filename.encode(sys.getfilesystemencoding()), pix, jpeg_quality, jpeg_progressive) @@ -186,7 +186,7 @@ def pixDestroy(pix): the address of the pointer. """ - with Leptonica(): + with LeptonicaErrorTrap(): lept.pixDestroy(C.byref(pix)) diff --git a/src/ocrPage.sh b/src/ocrPage.sh index 8e61c246..6f9f1612 100755 --- a/src/ocrPage.sh +++ b/src/ocrPage.sh @@ -166,7 +166,7 @@ widthCurImg=$(($dpi*$widthPDF/72)) heightCurImg=$(($dpi*$heightPDF/72)) if [ "$PREPROCESS_DESKEW" -eq "1" ]; then [ $VERBOSITY -ge $LOG_DEBUG ] && echo "Page $page: Deskewing image" - ! python2 $SRC/deskew.py -r $dpi "$curImgPixmap" "$curImgPixmapDeskewed" && exit $? + ! python2 $SRC/leptonica.py deskew -r $dpi "$curImgPixmap" "$curImgPixmapDeskewed" && exit $? else ln -s `basename "$curImgPixmap"` "$curImgPixmapDeskewed" fi