#NEWLINE# def ready( self ) : #NEWLINE# #INDENT# super ( OCRApp , self ) . ready ( ) #NEWLINE# APIEndPoint ( app = self , version_string = '1' ) #NEWLINE# Document . add_to_class ( 'submit_for_ocr' , document_ocr_submit ) #NEWLINE# DocumentVersion . add_to_class ( 'submit_for_ocr' , document_version_ocr_submit ) #NEWLINE# ModelPermission . register ( model = Document , permissions = ( permission_ocr_document , permission_ocr_content_view ) ) #NEWLINE# SourceColumn ( source = DocumentVersionOCRError , label = _ ( 'Document' ) , func = ( lambda context : document_link ( context [ 'object' ] . document_version . document ) ) ) #NEWLINE# SourceColumn ( source = DocumentVersionOCRError , label = _ ( 'Added' ) , attribute = 'datetime_submitted' ) #NEWLINE# SourceColumn ( source = DocumentVersionOCRError , label = _ ( 'Result' ) , attribute = 'result' ) #NEWLINE# app . conf . CELERY_QUEUES . append ( Queue ( 'ocr' , Exchange ( 'ocr' ) , routing_key = 'ocr' ) ) #NEWLINE# app . conf . CELERY_ROUTES . update ( { #NEWLINE# #INDENT# 'ocr.tasks.task_do_ocr' : { #NEWLINE# #INDENT# 'queue' : 'ocr' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# document_search . add_model_field ( field = 'versions__pages__ocr_content__content' , label = _ ( 'Content' ) ) #NEWLINE# menu_facet . bind_links ( links = ( link_document_content , ) , sources = ( Document , ) ) #NEWLINE# menu_multi_item . bind_links ( links = ( link_document_submit_multiple , ) , sources = ( Document , ) ) #NEWLINE# menu_object . bind_links ( links = ( link_document_submit , ) , sources = ( Document , ) ) #NEWLINE# menu_object . bind_links ( links = ( link_document_type_ocr_settings , ) , sources = ( DocumentType , ) ) #NEWLINE# menu_secondary . bind_links ( links = ( link_entry_list , ) , sources = ( 'ocr:entry_list' , 'ocr:entry_delete_multiple' , 'ocr:entry_re_queue_multiple' , DocumentVersionOCRError ) ) #NEWLINE# menu_tools . bind_links ( links = ( link_document_submit_all , link_document_type_submit , link_entry_list ) ) #NEWLINE# post_save . connect ( initialize_new_ocr_settings , dispatch_uid = 'initialize_new_ocr_settings' , sender = DocumentType ) #NEWLINE# post_version_upload . connect ( post_version_upload_ocr , dispatch_uid = 'post_version_upload_ocr' , sender = DocumentVersion ) #NEWLINE# namespace = PropertyNamespace ( 'ocr' , _ ( 'OCR' ) ) #NEWLINE# try : #NEWLINE# #INDENT# pdftotext = sh . Command ( setting_pdftotext_path . value ) #NEWLINE# #UNINDENT# except sh . CommandNotFound : #NEWLINE# #INDENT# namespace . add_property ( 'pdftotext' , _ ( 'pdftotext version' ) , _ ( 'not found' ) , report = True ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# namespace . add_property ( 'pdftotext' , _ ( 'pdftotext version' ) , _ ( 'error getting version' ) , report = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# namespace . add_property ( 'pdftotext' , _ ( 'pdftotext version' ) , pdftotext ( '-v' ) . stderr , report = True ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# tesseract = sh . Command ( setting_tesseract_path . value ) #NEWLINE# #UNINDENT# except sh . CommandNotFound : #NEWLINE# #INDENT# namespace . add_property ( 'tesseract' , _ ( 'tesseract version' ) , _ ( 'not found' ) , report = True ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# namespace . add_property ( 'tesseract' , _ ( 'tesseract version' ) , _ ( 'error getting version' ) , report = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# namespace . add_property ( 'tesseract' , _ ( 'tesseract version' ) , tesseract ( '-v' ) . stderr , report = True )