Fix a silly typo, and other minor cleanup

This commit is contained in:
Jim Barlow
2014-01-19 19:06:19 -08:00
parent 6703434976
commit 8cfbdaf0d0
2 changed files with 10 additions and 10 deletions
+9 -9
View File
@@ -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))
+1 -1
View File
@@ -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