Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(upgrade): add a function identifying upgrade temporary directories #22

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/antares/study/version/upgrade_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@

logger = logging.getLogger(__name__)

UPGRADE_TEMPORARY_DIR_SUFFIX = ".upgrade.tmp"
UPGRADE_TEMPORARY_DIR_PREFIX = "~"


def is_temporary_upgrade_dir(path: Path) -> bool:
"""Check if a directory is a temporary upgrade directory."""
return (
path.name.startswith(UPGRADE_TEMPORARY_DIR_PREFIX)
and str(path).endswith(UPGRADE_TEMPORARY_DIR_SUFFIX)
and path.is_dir()
)


def filter_out_child_files(files: t.Collection[str]) -> t.List[str]:
"""
Expand Down Expand Up @@ -91,7 +103,9 @@ def should_denormalize(self) -> bool:
return any(meth.should_denormalize for meth in self.upgrade_methods)

def __call__(self) -> None:
with tempfile.TemporaryDirectory(suffix=".upgrade.tmp", prefix="~", dir=self.study_dir.parent) as path:
with tempfile.TemporaryDirectory(
suffix=UPGRADE_TEMPORARY_DIR_SUFFIX, prefix=UPGRADE_TEMPORARY_DIR_PREFIX, dir=self.study_dir.parent
) as path:
tmp_path = Path(path)

# Prepare the upgrade
Expand Down
Loading