From 22f806e81e9f3e0b2f179aed173254796a5af252 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Fri, 28 Aug 2020 17:28:03 +0200 Subject: [PATCH] Warn on import problems. If there is a problem with files matching the capture globs but not matching the file name regexp patterns, these routines will emit a message to stderr and skip the non-matching file. --- bin/import_final_p111.py | 6 ++++++ bin/import_final_p190.py | 6 ++++++ bin/import_raw_p111.py | 6 ++++++ bin/import_raw_p190.py | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/bin/import_final_p111.py b/bin/import_final_p111.py index 30142a4..b740dcf 100755 --- a/bin/import_final_p111.py +++ b/bin/import_final_p111.py @@ -51,6 +51,12 @@ if __name__ == '__main__': print("Importing") match = rx.match(os.path.basename(filepath)) + if not match: + error_message = f"File path not match the expected format! ({filepath} ~ {pattern['regex']})" + print(error_message, file=sys.stderr) + print("This file will be ignored!") + continue + file_info = dict(zip(pattern["captures"], match.groups())) p111_data = p111.from_file(filepath) diff --git a/bin/import_final_p190.py b/bin/import_final_p190.py index 8a7475a..900c8d3 100755 --- a/bin/import_final_p190.py +++ b/bin/import_final_p190.py @@ -51,6 +51,12 @@ if __name__ == '__main__': print("Importing") match = rx.match(os.path.basename(filepath)) + if not match: + error_message = f"File path not match the expected format! ({filepath} ~ {pattern['regex']})" + print(error_message, file=sys.stderr) + print("This file will be ignored!") + continue + file_info = dict(zip(pattern["captures"], match.groups())) p190_data = p190.from_file(filepath, with_objrefs=True) diff --git a/bin/import_raw_p111.py b/bin/import_raw_p111.py index 9abc494..3902b81 100755 --- a/bin/import_raw_p111.py +++ b/bin/import_raw_p111.py @@ -51,6 +51,12 @@ if __name__ == '__main__': print("Importing") match = rx.match(os.path.basename(filepath)) + if not match: + error_message = f"File path not match the expected format! ({filepath} ~ {pattern['regex']})" + print(error_message, file=sys.stderr) + print("This file will be ignored!") + continue + file_info = dict(zip(pattern["captures"], match.groups())) p111_data = p111.from_file(filepath) diff --git a/bin/import_raw_p190.py b/bin/import_raw_p190.py index 7665fef..116b611 100755 --- a/bin/import_raw_p190.py +++ b/bin/import_raw_p190.py @@ -51,6 +51,12 @@ if __name__ == '__main__': print("Importing") match = rx.match(os.path.basename(filepath)) + if not match: + error_message = f"File path not match the expected format! ({filepath} ~ {pattern['regex']})" + print(error_message, file=sys.stderr) + print("This file will be ignored!") + continue + file_info = dict(zip(pattern["captures"], match.groups())) p190_data = p190.from_file(filepath, with_objrefs=True)