Skip to content

Commit

Permalink
fix: Handle file-list in datamodel for file-transfer service. (#3343)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkundu1 authored Oct 2, 2024
1 parent b15c482 commit b0da2ea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
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",
)

0 comments on commit b0da2ea

Please sign in to comment.