Skip to content

Commit 9953bb7

Browse files
authored
Merge pull request #82 from UAL-RE/80-add-additional-log-messages
Feat: describe enhancement or feature (Issue #80)
2 parents 0e54d57 + ef067ef commit 9953bb7

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

figshare/Article.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ def __get_single_file_hash(self, filepath):
600600
:param folder_name string
601601
"""
602602
def __save_json_in_metadata(self, version_data, folder_name):
603+
result = False
604+
603605
version_no = "v" + str(version_data["version"]).zfill(2)
604606
json_folder_path = folder_name + "/" + version_no + "/METADATA"
605607
preservation_storage_location = self.preservation_storage_location
@@ -633,17 +635,23 @@ def __save_json_in_metadata(self, version_data, folder_name):
633635
# Writing to json file
634636
with open(filename_path, "w") as outfile:
635637
outfile.write(json_data)
638+
result = True
636639
except Exception as e:
637640
self.logs.write_log_in_file('error', f"{folder_name}: {e}", True)
638-
return False
639-
return True
641+
result = False
642+
643+
if not result:
644+
self.logs.write_log_in_file("info", "json not saved.", True)
645+
return result
640646

641647
"""
642648
Copying UAL_RDM folder files to storage directory in related article version folder
643649
:param version_data dictionary
644650
:param folder_name string
645651
"""
646652
def __copy_files_ual_rdm(self, version_data, folder_name):
653+
result = False
654+
647655
version_no = "v" + str(version_data["version"]).zfill(2)
648656
curation_storage_location = self.curation_storage_location
649657
# check curation dir is reachable
@@ -667,16 +675,19 @@ def __copy_files_ual_rdm(self, version_data, folder_name):
667675
# check preservation dir is reachable
668676
self.check_access_of_directories(preservation_storage_location, "preservation")
669677
try:
670-
self.logs.write_log_in_file("info", "Copying files to preservation folder.", True)
671678
check_path_exists = os.path.exists(complete_folder_name)
672679
if (check_path_exists is False):
673680
os.makedirs(complete_folder_name, exist_ok=True)
674681
# copying files to preservation version folder
675682
shutil.copytree(curation_dir_name, complete_folder_name, dirs_exist_ok=True)
683+
self.logs.write_log_in_file("info", "Copied curation files to preservation folder.", True)
684+
result = True
676685
except Exception as e:
677-
self.logs.write_log_in_file('error', f"{e} - {complete_folder_name} error while copying files.", True)
678-
return False
679-
return True
686+
self.logs.write_log_in_file('error', f"{e} - {complete_folder_name}.", True)
687+
result = False
688+
if not result:
689+
self.logs.write_log_in_file("info", "No files copied to preservation folder.", True)
690+
return result
680691

681692
"""
682693
Find matched articles from the fetched data and curation dir
@@ -758,7 +769,7 @@ def __can_copy_files(self, version_data):
758769
+ "files in curation storage. Folder will be deleted.", True)
759770
copy_files = False
760771
else:
761-
self.logs.write_log_in_file("info", "Curation files exist", True)
772+
self.logs.write_log_in_file("info", "Curation files exist. Continuing execution.", True)
762773
copy_files = True
763774

764775
return copy_files
@@ -770,7 +781,7 @@ def __final_process(self, check_files, copy_files, check_dir, version_data, fold
770781
success = True
771782
if copy_files and not check_files:
772783
# check and create empty directories for each version
773-
self.logs.write_log_in_file("info", "Checking and creating empty directories.", True)
784+
self.logs.write_log_in_file("info", "Checking and creating empty directories in preservation storage.", True)
774785
success = success & self.create_required_folders(version_data, folder_name)
775786
# copy curation UAL_RDM files in storage UAL_RDM folder for each version
776787
self.logs.write_log_in_file("info", "Copying curation UAL_RDM files to preservation UAL_RDM folder.", True)
@@ -970,13 +981,17 @@ def create_required_folders(self, version_data, folder_name):
970981
if (ual_path_exists is False):
971982
# create UAL_RDM directory if not exist
972983
os.makedirs(ual_folder_name, exist_ok=True)
984+
else:
985+
self.logs.write_log_in_file("info", "UAL_RDM directory already exists. Folder not created", True)
973986

974987
# setup DATA directory
975988
data_folder_name = preservation_storage_location + folder_name + "/" + version_no + "/DATA"
976989
data_path_exists = os.path.exists(data_folder_name)
977990
if (data_path_exists is False):
978991
# create DATA directory if it does not exist
979992
os.makedirs(data_folder_name, exist_ok=True)
993+
else:
994+
self.logs.write_log_in_file("info", "DATA directory already exists. Folder not created", True)
980995
except Exception as e:
981996
self.logs.write_log_in_file('error', f"{folder_name}: {e}", True)
982997
return False

figshare/Collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,14 @@ def __save_json_in_metadata(self, collection_id, version_data, folder_name):
279279
json_data = json.dumps(version_data, indent=4)
280280
filename_path = complete_path + "/" + str(collection_id) + ".json"
281281
# Writing to json file
282-
self.logs.write_log_in_file("info", "Saving collection data in json.", True)
283282
with open(filename_path, "w") as outfile:
284283
outfile.write(json_data)
284+
self.logs.write_log_in_file("info", "Saved collection data in json.", True)
285285
else:
286286
storage_collection_version_dir = os.listdir(complete_path)
287287
file_name = f"{str(collection_id)}.json"
288288
if (len(storage_collection_version_dir) == 0 or file_name not in storage_collection_version_dir):
289-
self.logs.write_log_in_file("info", f"{complete_path} path already exists but missing {file_name} file.")
289+
self.logs.write_log_in_file("warning", f"{complete_path} path already exists but missing {file_name} file.")
290290

291291
def get_collection_api_url(self):
292292
collections_api_url = self.api_endpoint + '/collections'

0 commit comments

Comments
 (0)