24
24
25
25
from . import default
26
26
from .default import getlocal
27
- from .toplevel import (checks , ABINARY2 , AINT2 , AINT3 , BOOL , DARKSEG , GRAYSCALE ,
27
+ from .toplevel import (checks , LOG , ABINARY2 , AINT2 , AINT3 , BOOL , DARKSEG , GRAYSCALE ,
28
28
LIGHTSEG , LINESEG , PAGESEG )
29
29
from . import chars
30
30
from . import ligatures
35
35
36
36
pickle_mode = 2
37
37
38
-
39
38
################################################################
40
39
# text normalization
41
40
################################################################
@@ -187,7 +186,8 @@ def write_image_gray(fname,image,normalize=0,verbose=0):
187
186
type, its values are clipped to the range [0,1],
188
187
multiplied by 255 and converted to unsigned bytes. Otherwise,
189
188
the image must be of type unsigned byte."""
190
- if verbose : print ("# writing" , fname )
189
+ if verbose :
190
+ LOG .info ("# writing '%s'" , fname )
191
191
if isfloatarray (image ):
192
192
image = array (255 * clip (image ,0.0 ,1.0 ),'B' )
193
193
assert image .dtype == dtype ('B' ),"array has wrong dtype: %s" % image .dtype
@@ -210,7 +210,8 @@ def write_image_binary(fname,image,verbose=0):
210
210
"""Write a binary image to disk. This verifies first that the given image
211
211
is, in fact, binary. The image may be of any type, but must consist of only
212
212
two values."""
213
- if verbose : print ("# writing" , fname )
213
+ if verbose :
214
+ LOG .info ("# writing '%s'" , fname )
214
215
assert image .ndim == 2
215
216
image = array (255 * (image > midrange (image )),'B' )
216
217
im = array2pil (image )
@@ -440,8 +441,8 @@ def load_object(fname,zip=0,nofind=0,verbose=0):
440
441
class names that have changed."""
441
442
if not nofind :
442
443
fname = ocropus_find_file (fname )
443
- # if verbose:
444
- # print ("# loading object", fname)
444
+ if verbose :
445
+ LOG . info ("# loading object '%s' " , fname )
445
446
if zip == 0 and fname .endswith (".gz" ):
446
447
zip = 1
447
448
if zip > 0 :
@@ -720,16 +721,12 @@ def caller():
720
721
721
722
def die (message ,* args ):
722
723
"""Die with an error message."""
723
- message = message % args
724
- message = caller ()+ " FATAL " + message + "\n "
725
- sys .stderr .write (message )
724
+ LOG .critical (caller () + ' ' + message , args )
726
725
sys .exit (1 )
727
726
728
727
def warn (message ,* args ):
729
728
"""Give a warning message."""
730
- message = message % args
731
- message = caller ()+ " WARNING " + message + "\n "
732
- sys .stderr .write (message )
729
+ LOG .warning (caller () + ' ' + message , args )
733
730
734
731
already_warned = {}
735
732
@@ -738,9 +735,7 @@ def warn_once(message,*args):
738
735
c = caller ()
739
736
if c in already_warned : return
740
737
already_warned [c ] = 1
741
- message = message % args
742
- message = c + " WARNING " + message + "\n "
743
- sys .stderr .write (message )
738
+ LOG .warning (c + ' ' + message , args )
744
739
745
740
def quick_check_page_components (page_bin ,dpi ):
746
741
"""Quickly check whether the components of page_bin are
0 commit comments