From 0d9554d8acf346fab47a7163b1b33efebb516e51 Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Mon, 4 Dec 2023 12:16:57 +0100 Subject: [PATCH] change file extension checker in XPS READER class --- pynxtools/dataconverter/readers/xps/file_parser.py | 3 ++- pynxtools/dataconverter/readers/xps/reader.py | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pynxtools/dataconverter/readers/xps/file_parser.py b/pynxtools/dataconverter/readers/xps/file_parser.py index b02d15a2a..ff5190b94 100644 --- a/pynxtools/dataconverter/readers/xps/file_parser.py +++ b/pynxtools/dataconverter/readers/xps/file_parser.py @@ -39,7 +39,8 @@ class XpsDataFileParser: """Class intended for receiving any type of XPS data file.""" - __prmt_file_ext__ = ["sle", "slh", "txt", "vms", "xml", "xy"] + __prmt_file_ext__ = ["sle", "txt", "vms", "xml", "xy"] + __prmt_metadata_file_ext__ = ["slh"] __vendors__ = ["specs", "scienta", "kratos", "unkwown"] __prmt_vndr_cls: Dict[str, Dict] = { "sle": {"specs": SleMapperSpecs}, diff --git a/pynxtools/dataconverter/readers/xps/reader.py b/pynxtools/dataconverter/readers/xps/reader.py index fe8dfcb0f..03f6e5707 100644 --- a/pynxtools/dataconverter/readers/xps/reader.py +++ b/pynxtools/dataconverter/readers/xps/reader.py @@ -18,7 +18,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import os from pathlib import Path from typing import Any, Dict, Set, List from typing import Tuple @@ -347,9 +346,9 @@ def read( config_file: Path = reader_dir.joinpath("config/template.json") for file in file_paths: - file_ext = os.path.splitext(file)[1] + file_ext = file.rsplit(".")[-1] - if file_ext in [".yaml", ".yml"]: + if file_ext in ["yaml", "yml"]: with open(file, mode="r", encoding="utf-8") as eln: eln_data_dict = flatten_and_replace( FlattenSettings( @@ -373,14 +372,14 @@ def read( xps_data_dict[key] = concatenate_values(value1, value2) config_file = reader_dir.joinpath(f"config/{config_file}") - elif file_ext in [".slh"]: + elif file_ext in XpsDataFileParser.__prmt_metadata_file_ext__: data_dict = XpsDataFileParser([file]).get_dict(**kwargs) xps_data_dict = {**xps_data_dict, **data_dict} # This code is not very robust. - elif file_ext == ".json": - if "config_file" in file: + elif file_ext == "json": + if "config" in file: config_file = Path(file) with open(config_file, encoding="utf-8", mode="r") as cfile: