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

fix: Handle file-list in datamodel for file-transfer service. #3343

Merged
merged 1 commit into from
Oct 2, 2024
Merged
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
20 changes: 14 additions & 6 deletions src/ansys/fluent/core/services/datamodel_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,9 @@ def _get_file_purpose(self, arg):
def before_execute(self, value):
"""Executes before command execution."""
if hasattr(self, "_do_before_execute"):
self._do_before_execute(value)
return self._do_before_execute(value)
else:
return value

def after_execute(self, value):
"""Executes after command execution."""
Expand All @@ -1755,8 +1757,7 @@ def __call__(self, *args, **kwds) -> Any:
"""
for arg, value in kwds.items():
if self._get_file_purpose(arg):
self.before_execute(value)
kwds[f"{arg}"] = os.path.basename(value)
kwds[arg] = self.before_execute(value)
command = self.service.execute_command(
self.rules, convert_path_to_se_path(self.path), self.command, kwds
)
Expand Down Expand Up @@ -1824,15 +1825,22 @@ def create_instance(self) -> "PyCommandArguments":
class _InputFile:
def _do_before_execute(self, value):
try:
self.service.file_transfer_service.upload(file_name=value)
file_names = value if isinstance(value, list) else [value]
base_names = []
for file_name in file_names:
self.service.file_transfer_service.upload(file_name=file_name)
base_names.append(os.path.basename(file_name))
return base_names if isinstance(value, list) else base_names[0]
except AttributeError:
pass
return value


class _OutputFile:
def _do_after_execute(self, value):
try:
self.service.file_transfer_service.download(file_name=value)
file_names = value if isinstance(value, list) else [value]
for file_name in file_names:
self.service.file_transfer_service.download(file_name=file_name)
except AttributeError:
pass

Expand Down
21 changes: 21 additions & 0 deletions tests/test_file_transfer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,24 @@ def test_datamodel_execute():

with pytest.raises(RuntimeError):
import_geom.Execute()


def test_file_list_in_datamodel(fault_tolerant_workflow_session):
meshing = fault_tolerant_workflow_session
fmd_file = examples.download_file("exhaust_system.fmd", "pyfluent/exhaust_system")
meshing.PartManagement.AppendFmdFiles(
AssemblyParentNode=0,
FilePath=[fmd_file],
FileUnit="mm",
IgnoreSolidNamesAppend=False,
JtLOD="1",
Options={
"Line": False,
"Solid": True,
"Surface": True,
},
PartPerBody=False,
PrefixParentName=False,
RemoveEmptyParts=True,
Route="Native",
)