#NEWLINE# def soffice( self ) : #NEWLINE# #INDENT# '\n        Executes LibreOffice as a subprocess\n        ' #NEWLINE# if ( not os . path . exists ( setting_libreoffice_path . value ) ) : #NEWLINE# #INDENT# raise OfficeConversionError ( ( _ ( 'LibreOffice not installed or not found at path: %s' ) % setting_libreoffice_path . value ) ) #NEWLINE# #UNINDENT# ( new_file_object , input_filepath ) = tempfile . mkstemp ( ) #NEWLINE# self . file_object . seek ( 0 ) #NEWLINE# os . write ( new_file_object , self . file_object . read ( ) ) #NEWLINE# self . file_object . seek ( 0 ) #NEWLINE# os . lseek ( new_file_object , 0 , os . SEEK_SET ) #NEWLINE# os . close ( new_file_object ) #NEWLINE# libreoffice_filter = None #NEWLINE# if ( self . mime_type == 'text/plain' ) : #NEWLINE# #INDENT# libreoffice_filter = 'Text (encoded):UTF8,LF,,,' #NEWLINE# #UNINDENT# args = ( input_filepath , '--outdir' , setting_temporary_directory . value ) #NEWLINE# kwargs = { #NEWLINE# #INDENT# '_env' : { #NEWLINE# #INDENT# 'HOME' : setting_temporary_directory . value , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# if libreoffice_filter : #NEWLINE# #INDENT# kwargs . update ( { #NEWLINE# #INDENT# 'infilter' : libreoffice_filter , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# LIBREOFFICE ( * args , ** kwargs ) #NEWLINE# #UNINDENT# except sh . ErrorReturnCode as exception : #NEWLINE# #INDENT# raise OfficeConversionError ( exception ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# fs_cleanup ( input_filepath ) #NEWLINE# #UNINDENT# ( filename , extension ) = os . path . splitext ( os . path . basename ( input_filepath ) ) #NEWLINE# logger . debug ( 'filename: %s' , filename ) #NEWLINE# logger . debug ( 'extension: %s' , extension ) #NEWLINE# converted_output = os . path . join ( setting_temporary_directory . value , os . path . extsep . join ( ( filename , 'pdf' ) ) ) #NEWLINE# logger . debug ( 'converted_output: %s' , converted_output ) #NEWLINE# with open ( converted_output ) as converted_file_object : #NEWLINE# #INDENT# while True : #NEWLINE# #INDENT# data = converted_file_object . read ( CHUNK_SIZE ) #NEWLINE# if ( not data ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# ( yield data ) #NEWLINE# #UNINDENT# #UNINDENT# fs_cleanup ( input_filepath )