Source code for ska_sdp_e2e_batch_continuum_imaging.pipelines.common

import os
from configparser import ConfigParser
from pathlib import Path


[docs] def read_file(filepath: str | Path) -> str: """ Reads the contents of a file and returns it as a string. Parameters ---------- filepath : str or Path The path to the file to be read. Returns ------- str The contents of the file as a string. """ with open(filepath, mode="r", encoding="utf-8") as file: return file.read()
[docs] def write_file(content, filepath: str | Path): """ Writes the given content to a file at the specified filepath. Parameters ---------- content : str The content to be written to the file. filepath : str or Path The path to the file where the content will be written. """ with open(filepath, mode="w", encoding="utf-8") as file: file.write(content)
[docs] def write_ini_config(config: ConfigParser, filepath: str | Path): """ Writes the given config to a ini file at the specified filepath. Parameters ---------- config : Configparser An Configparser object with config. filepath: str or Path The path to the file where the content will be written. """ with open(filepath, mode="w", encoding="utf-8") as file: config.write(file)
[docs] def create_directories(paths: list[Path | str]): """ Create directories for the given list of paths. Parameters ---------- paths : list of Path or str A list containing directory paths to create. Each element can be a string or a pathlib.Path object. """ for path in paths: os.makedirs(path, exist_ok=True)