Commit 0fb92b30 authored by Thomas Bernhart's avatar Thomas Bernhart
Browse files

Cleanup logging

parent 16a7f4f8
......@@ -7,24 +7,26 @@ from ch.memobase.foxml import FoxmlReader
from ch.memobase.foxml import FoxmlParsingError
def _copy_file(source_file, destination_directory, destination_filename):
def _copy_file(source_file, destination_directory, destination_filename, logger):
if not path.exists(destination_directory):
makedirs(destination_directory)
destination_path = path.join(destination_directory, destination_filename)
copy2(source_file, destination_path, follow_symlinks=False)
logger.info("Exported file '" + source_file + "' to '" + destination_path + "'")
def _normalize_document_id(document_id):
return document_id.replace("/", "_")
def _normalize_file_extension(file_extension):
def _normalize_file_extension(original_file_name):
file_ext_mapping = {
"jpg": "jpeg"
}
return file_ext_mapping.get(file_extension.lower(), file_extension)
ext = path.splitext(original_file_name)
return file_ext_mapping.get(k=ext.lower(), default=ext.lower())
def foxml_export(objectstore_path, output_path, recordsets_csv_file):
......@@ -33,7 +35,7 @@ def foxml_export(objectstore_path, output_path, recordsets_csv_file):
# configure logger:
logger = logging.getLogger("foxml_export")
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.ERROR)
logging_fh = logging.FileHandler(path.join(output_path, "foxml_export.log"))
logging_fh.setLevel(logging.INFO)
logger.addHandler(logging_fh)
......@@ -48,7 +50,7 @@ def foxml_export(objectstore_path, output_path, recordsets_csv_file):
try:
foxml_reader = FoxmlReader(foxml_path)
except FoxmlParsingError as parsing_error:
logging.warning(parsing_error)
logging.error("Error while parsing FOXML file", exc_info=parsing_error)
else:
old_record_set_id = foxml_reader.get_recordset_id()
if old_record_set_id is not None:
......@@ -63,37 +65,40 @@ def foxml_export(objectstore_path, output_path, recordsets_csv_file):
copy2(foxml_path, foxml_destination_path, follow_symlinks=False)
logger.info("Exported FOXML file '" + foxml_path + "' to '" + foxml_destination_path + "'")
else:
logger.info("Ignored FOXML file '" + foxml_path +
logger.warning("Ignored FOXML file '" + foxml_path +
"': Old recordset ID not listed in 'record_sets_ids.csv'")
else:
logger.warning("Ignored FOXML file '" + foxml_path +
"': No recordset ID found in FOXML")
logger.info("Finished FOXML export")
print("Finished FOXML export")
def media_export(record_set_path, http_files_path, rtmp_files_path):
def media_export(record_set_path, datastreamstore_path, http_files_path, rtmp_files_path):
# configure logger:
logger = logging.getLogger("media_export")
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.ERROR)
logging_fh = logging.FileHandler(path.join(record_set_path, "media_export.log"))
logging_fh.setLevel(logging.INFO)
logger.addHandler(logging_fh)
for foxml_path in listdir(record_set_path):
logger.info("Exporting media files for file: '" + foxml_path + "'")
logger.debug("Exporting media files for file: '" + foxml_path + "'")
foxml_reader = FoxmlReader(foxml_path)
document_id = foxml_reader.get_document_id()
media_file_searcher = MediaFileSearcher(foxml_reader, http_files_path, rtmp_files_path)
media_file_searcher = MediaFileSearcher(foxml_reader, datastreamstore_path, http_files_path, rtmp_files_path)
accesscopy_file = media_file_searcher.search_media_file()
if accesscopy_file is not None:
_copy_file(accesscopy_file[0], path.join(record_set_path, "media"),
_normalize_document_id(document_id) + "." + _normalize_file_extension(accesscopy_file[1]))
_normalize_document_id(document_id) + "." + _normalize_file_extension(accesscopy_file[1]), logger)
thumbnail_file = media_file_searcher.search_thumbnail_file()
if thumbnail_file is not None:
original_file_ext = path.splitext(accesscopy_file[1])[1]
_copy_file(thumbnail_file[0], path.join(record_set_path, "thumbnails"),
_normalize_document_id(document_id) + "." + _normalize_file_extension(thumbnail_file[1]))
_normalize_document_id(document_id) + "." + _normalize_file_extension(thumbnail_file[1]), logger)
print("Finished media export")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment