Skip to content

Update archive project name #6401

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions src/ansys/aedt/core/application/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
from ansys.aedt.core.generic.constants import AEDT_UNITS
from ansys.aedt.core.generic.constants import unit_system
from ansys.aedt.core.generic.data_handlers import variation_string_to_dict
from ansys.aedt.core.generic.file_utils import available_file_name
from ansys.aedt.core.generic.file_utils import check_and_download_file
from ansys.aedt.core.generic.file_utils import generate_unique_name
from ansys.aedt.core.generic.file_utils import is_project_locked
Expand Down Expand Up @@ -1255,9 +1256,9 @@ def oproject(self, proj_name=None):
settings.remote_rpc_session and settings.remote_rpc_session.filemanager.pathexists(proj_name)
):
if ".aedtz" in proj_name:
name = self._generate_unique_project_name()
path = os.path.dirname(proj_name)
self.odesktop.RestoreProjectArchive(proj_name, os.path.join(path, name), True, True)
p = Path(proj_name).parent
save_to_file = available_file_name(p.with_suffix(".aedt"))
self.odesktop.RestoreProjectArchive(str(save_to_file.name), str(p), True, True)
time.sleep(0.5)
proj_name = name[:-5]
self._oproject = self.desktop_class.active_project(proj_name)
Expand Down
27 changes: 27 additions & 0 deletions src/ansys/aedt/core/generic/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,33 @@ def generate_unique_project_name(
return str(prj)


@pyaedt_function_handler()
def available_file_name(full_file_name: Union[str, Path]) -> Path:
"""Provide a file name that doesn't exist.

If the input file name exists, increment the base
name and return a valid ``Path`` object with an updated name.

Parameters
----------
full_file_name : str or :class:`pathlib.Path`
File to be saved.

Returns
-------
class:`pathlib.Path`
Valid file name with increment suffix `"_n.ext"`. If the file doesn't
exist, the original file name will be returned as a ``Path`` object.
"""
p = Path(full_file_name)
candidate = p
n = 1
while candidate.exists():
candidate = candidate.with_name(f"{p.stem}_{n}{p.suffix}")
n += 1
return candidate


@pyaedt_function_handler(startpath="path", filepattern="file_pattern")
def recursive_glob(path: Union[str, Path], file_pattern: str):
"""Get a list of files matching a pattern, searching recursively from a start path.
Expand Down
Loading