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

Detect binout files automatically #1277

Merged
merged 7 commits into from
Nov 21, 2023
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
18 changes: 14 additions & 4 deletions src/ansys/dpf/core/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,25 @@ def set_result_file_path(self, filepath, key=""):
['/tmp/file.rst']

"""
# Handle the case of files without extension, such as the LS-DYNA d3plot file
if os.path.splitext(filepath)[1] == "":
if "d3plot" in os.path.basename(filepath):
key = "d3plot"
# Handle no key given and no file extension
if key == "" and os.path.splitext(filepath)[1] == "":
key = self.guess_result_key(str(filepath))
if key == "":
self._api.data_sources_set_result_file_path_utf8(self, str(filepath))
else:
self._api.data_sources_set_result_file_path_with_key_utf8(self, str(filepath), key)

@staticmethod
def guess_result_key(filepath: str) -> str:
"""Guess result key for files without a file extension."""
result_keys = ["d3plot", "binout"]
base_name = os.path.basename(filepath)
# Handle files without extension
for result_key in result_keys:
if result_key in base_name:
return result_key
return ""

def set_domain_result_file_path(self, path, domain_id):
"""Add a result file path by domain.

Expand Down
6 changes: 5 additions & 1 deletion tests/test_datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ def test_addfilepathspecifiedresult_data_sources(allkindofcomplexity, server_typ
data_sources.add_file_path_for_specified_result(allkindofcomplexity, "d3plot")


def test_setresultpath_data_sources_no_extension(d3plot_beam, server_type):
def test_setresultpath_data_sources_no_extension(d3plot_beam, binout_glstat, server_type):
data_sources = dpf.core.DataSources(server=server_type)
data_sources.set_result_file_path(d3plot_beam)
assert data_sources.result_key == "d3plot"
data_sources = dpf.core.DataSources(server=server_type)
data_sources.set_result_file_path(binout_glstat)
assert data_sources.result_key == "binout"


def test_addupstream_data_sources(allkindofcomplexity, server_type):
Expand Down