Skip to content

Commit

Permalink
Merge pull request #82 from UAL-RE/80-add-additional-log-messages
Browse files Browse the repository at this point in the history
Feat: describe enhancement or feature (Issue #80)
  • Loading branch information
zoidy authored Oct 26, 2023
2 parents 0e54d57 + ef067ef commit 9953bb7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
31 changes: 23 additions & 8 deletions figshare/Article.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,8 @@ def __get_single_file_hash(self, filepath):
:param folder_name string
"""
def __save_json_in_metadata(self, version_data, folder_name):
result = False

version_no = "v" + str(version_data["version"]).zfill(2)
json_folder_path = folder_name + "/" + version_no + "/METADATA"
preservation_storage_location = self.preservation_storage_location
Expand Down Expand Up @@ -633,17 +635,23 @@ def __save_json_in_metadata(self, version_data, folder_name):
# Writing to json file
with open(filename_path, "w") as outfile:
outfile.write(json_data)
result = True
except Exception as e:
self.logs.write_log_in_file('error', f"{folder_name}: {e}", True)
return False
return True
result = False

if not result:
self.logs.write_log_in_file("info", "json not saved.", True)
return result

"""
Copying UAL_RDM folder files to storage directory in related article version folder
:param version_data dictionary
:param folder_name string
"""
def __copy_files_ual_rdm(self, version_data, folder_name):
result = False

version_no = "v" + str(version_data["version"]).zfill(2)
curation_storage_location = self.curation_storage_location
# check curation dir is reachable
Expand All @@ -667,16 +675,19 @@ def __copy_files_ual_rdm(self, version_data, folder_name):
# check preservation dir is reachable
self.check_access_of_directories(preservation_storage_location, "preservation")
try:
self.logs.write_log_in_file("info", "Copying files to preservation folder.", True)
check_path_exists = os.path.exists(complete_folder_name)
if (check_path_exists is False):
os.makedirs(complete_folder_name, exist_ok=True)
# copying files to preservation version folder
shutil.copytree(curation_dir_name, complete_folder_name, dirs_exist_ok=True)
self.logs.write_log_in_file("info", "Copied curation files to preservation folder.", True)
result = True
except Exception as e:
self.logs.write_log_in_file('error', f"{e} - {complete_folder_name} error while copying files.", True)
return False
return True
self.logs.write_log_in_file('error', f"{e} - {complete_folder_name}.", True)
result = False
if not result:
self.logs.write_log_in_file("info", "No files copied to preservation folder.", True)
return result

"""
Find matched articles from the fetched data and curation dir
Expand Down Expand Up @@ -758,7 +769,7 @@ def __can_copy_files(self, version_data):
+ "files in curation storage. Folder will be deleted.", True)
copy_files = False
else:
self.logs.write_log_in_file("info", "Curation files exist", True)
self.logs.write_log_in_file("info", "Curation files exist. Continuing execution.", True)
copy_files = True

return copy_files
Expand All @@ -770,7 +781,7 @@ def __final_process(self, check_files, copy_files, check_dir, version_data, fold
success = True
if copy_files and not check_files:
# check and create empty directories for each version
self.logs.write_log_in_file("info", "Checking and creating empty directories.", True)
self.logs.write_log_in_file("info", "Checking and creating empty directories in preservation storage.", True)
success = success & self.create_required_folders(version_data, folder_name)
# copy curation UAL_RDM files in storage UAL_RDM folder for each version
self.logs.write_log_in_file("info", "Copying curation UAL_RDM files to preservation UAL_RDM folder.", True)
Expand Down Expand Up @@ -970,13 +981,17 @@ def create_required_folders(self, version_data, folder_name):
if (ual_path_exists is False):
# create UAL_RDM directory if not exist
os.makedirs(ual_folder_name, exist_ok=True)
else:
self.logs.write_log_in_file("info", "UAL_RDM directory already exists. Folder not created", True)

# setup DATA directory
data_folder_name = preservation_storage_location + folder_name + "/" + version_no + "/DATA"
data_path_exists = os.path.exists(data_folder_name)
if (data_path_exists is False):
# create DATA directory if it does not exist
os.makedirs(data_folder_name, exist_ok=True)
else:
self.logs.write_log_in_file("info", "DATA directory already exists. Folder not created", True)
except Exception as e:
self.logs.write_log_in_file('error', f"{folder_name}: {e}", True)
return False
Expand Down
4 changes: 2 additions & 2 deletions figshare/Collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,14 @@ def __save_json_in_metadata(self, collection_id, version_data, folder_name):
json_data = json.dumps(version_data, indent=4)
filename_path = complete_path + "/" + str(collection_id) + ".json"
# Writing to json file
self.logs.write_log_in_file("info", "Saving collection data in json.", True)
with open(filename_path, "w") as outfile:
outfile.write(json_data)
self.logs.write_log_in_file("info", "Saved collection data in json.", True)
else:
storage_collection_version_dir = os.listdir(complete_path)
file_name = f"{str(collection_id)}.json"
if (len(storage_collection_version_dir) == 0 or file_name not in storage_collection_version_dir):
self.logs.write_log_in_file("info", f"{complete_path} path already exists but missing {file_name} file.")
self.logs.write_log_in_file("warning", f"{complete_path} path already exists but missing {file_name} file.")

def get_collection_api_url(self):
collections_api_url = self.api_endpoint + '/collections'
Expand Down

0 comments on commit 9953bb7

Please sign in to comment.