Skip to content

Commit

Permalink
change file extension checker in XPS READER class
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspie committed Dec 4, 2023
1 parent 0e965e5 commit 0d9554d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pynxtools/dataconverter/readers/xps/file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
11 changes: 5 additions & 6 deletions pynxtools/dataconverter/readers/xps/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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:
Expand Down

0 comments on commit 0d9554d

Please sign in to comment.