Source code for fm_weck.file_util
# This file is part of fm-weck: executing fm-tools in containerized environments.
# https://gitlab.com/sosy-lab/software/fm-weck
#
# SPDX-FileCopyrightText: 2024 Dirk Beyer <https://www.sosy-lab.org>
#
# SPDX-License-Identifier: Apache-2.0
from pathlib import Path
import httpx
URL = "https://gitlab.com/sosy-lab/benchmarking/sv-benchmarks/-/raw/main/"
# replacement strings
WINDOWS_LINE_ENDING = b"\r\n"
UNIX_LINE_ENDING = b"\n"
[docs]
def copy_ensuring_unix_line_endings(src: Path, dst: Path) -> None:
with open(src, "rb") as src_file:
content = src_file.read()
# Windows ➡ Unix
content = content.replace(WINDOWS_LINE_ENDING, UNIX_LINE_ENDING)
with open(dst, "wb") as dst_file:
dst_file.write(content)
[docs]
def ensure_linux_style(path: str) -> str:
"""Ensure that the given path uses Linux-style forward slashes."""
return path.replace("\\", "/")
[docs]
def get_bench_file(config, file_name: str) -> Path:
response = httpx.get(URL + file_name, timeout=30.0)
response.raise_for_status()
full_file_path = config.cache_location / "benchmark_files" / file_name
full_file_path.parent.mkdir(parents=True, exist_ok=True)
full_file_path.write_text(response.text, encoding="utf-8")
return full_file_path