Skip to content

Commit

Permalink
feat(archive-api): replace "get_archive_path" using "find/create_arch…
Browse files Browse the repository at this point in the history
…ive_path"
  • Loading branch information
mabw-rte committed May 27, 2024
1 parent c406835 commit 60259df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions antarest/study/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ def delete_study(self, uuid: str, children: bool, params: RequestParameters) ->
self.storage_service.get_storage(study).delete(study)
else:
if isinstance(study, RawStudy):
os.unlink(self.storage_service.raw_study_service.get_archive_path(study))
os.unlink(self.storage_service.raw_study_service.find_archive_path(study))

logger.info("study %s deleted by user %s", uuid, params.get_user_id())

Expand Down Expand Up @@ -1956,7 +1956,7 @@ def unarchive_task(notifier: TaskUpdateNotifier) -> TaskResult:
self.storage_service.raw_study_service.unarchive(study_to_archive)
study_to_archive.archived = False

os.unlink(self.storage_service.raw_study_service.get_archive_path(study_to_archive))
os.unlink(self.storage_service.raw_study_service.find_archive_path(study_to_archive))
self.repository.save(study_to_archive)
self.event_bus.push(
Event(
Expand Down
25 changes: 19 additions & 6 deletions antarest/study/storage/rawstudy/raw_study_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def exists(self, study: RawStudy) -> bool:
Returns: true if study presents in disk, false else.
"""
if study.archived:
archive_path = self.get_archive_path(study)
archive_path = self.find_archive_path(study)
return archive_path.is_file()

path = self.get_study_path(study)
Expand Down Expand Up @@ -373,7 +373,7 @@ def set_reference_output(self, study: RawStudy, output_id: str, status: bool) ->
remove_from_cache(self.cache, study.id)

def archive(self, study: RawStudy) -> Path:
archive_path = self.get_archive_path(study)
archive_path = self.create_archive_path(study)
new_study_path = self.export_study(study, archive_path)
shutil.rmtree(study.path)
remove_from_cache(cache=self.cache, root_id=study.id)
Expand All @@ -391,12 +391,12 @@ def unarchive(self, study: RawStudy) -> None:
Raises:
BadArchiveContent: If the archive is corrupted or in an unknown format.
"""
with open(self.get_archive_path(study), mode="rb") as fh:
with open(self.find_archive_path(study), mode="rb") as fh:
self.import_study(study, fh)

def get_archive_path(self, study: RawStudy) -> Path:
def find_archive_path(self, study: RawStudy) -> Path:
"""
Get archive path of a study.
Fetch for archive path of a study if it exists else raise an incorrectly archived study.
Args:
study: The study to get the archive path for.
Expand All @@ -409,6 +409,19 @@ def get_archive_path(self, study: RawStudy) -> Path:
path = archive_dir.joinpath(f"{study.id}{suffix}")
if path.is_file():
return path
raise FileNotFoundError(f"Study {study.id} archiving process is corrupted (no archive file found).")

def create_archive_path(self, study: RawStudy) -> Path:
"""
Create archive path of a study.
Args:
study: The study to get the archive path for.
Returns:
The full path of the archive file (7z).
"""
archive_dir: Path = self.config.storage.archive_dir
return archive_dir.joinpath(f"{study.id}.7z")

def get_study_path(self, metadata: Study) -> Path:
Expand All @@ -421,7 +434,7 @@ def get_study_path(self, metadata: Study) -> Path:
"""
if metadata.archived:
return self.get_archive_path(metadata)
return self.find_archive_path(metadata)
return Path(metadata.path)

def initialize_additional_data(self, raw_study: RawStudy) -> bool:
Expand Down

0 comments on commit 60259df

Please sign in to comment.