in ees_network_drive/files.py [0:0]
def fetch_file_content(self, service_name, file_details, smb_connection):
"""This method is used to fetch content from Network Drives file
:param service_name: name of the drive
:param file_details: dictionary containing file details
:param smb_connection: connection object
"""
file_obj = tempfile.NamedTemporaryFile()
try:
smb_connection.retrieveFile(service_name, file_details.get('file_path'), file_obj)
file_obj.seek(0)
try:
extracted_content = extract(file_obj.read())
file_obj.close()
return extracted_content
except TikaException as exception:
self.logger.exception(
f"Error while extracting contents from file {file_details.get('file_name')} via Tika Parser. \
Error {exception}")
except Exception as exception:
if isinstance(exception, OSError) and exception.errno == errno.ENOSPC:
self.logger.exception(
f"We reached the memory limit for extracting the file: {file_details.get('file_name')}. \
Skipping the contents of this file. Error: {exception}"
)
else:
self.logger.exception(
f"Cannot read the contents of the file {file_details.get('file_name')} . Error {exception}")
file_obj.close()