def _get_data(self, config_file: str) -> dict: with open(config_file) as config_handle: try: data = toml.loads(config_handle.read()) except toml.TomlDecodeError as e: raise BadConfigException("Could not parse SauronX config file.", e) data["local"]["storage"]["directory_format"] = fix_path( data["local"]["storage"]["directory_format"] ) return data
def parse_path_format(self, fmt: str, path: str, dt: datetime) -> str: return ( fix_path(fmt) .replace("${path}", path) .replace("${number}", str(self.sauron_number)) .replace("${sauron}", str(self.sauron_name)) .replace("${date}", dt.strftime("%Y-%m-%d")) .replace("${time}", dt.strftime("%H-%M-%S")) .replace("${datetime}", dt.strftime("%Y-%m-%d_%H-%M-%S")) .replace("${timestamp}", stamp(dt)) )
def temp_dir(self) -> str: if not pexists(self.storage["root_temp_dir"]): warn( "Root temp directory {} does not exist; will be created".format( self.storage["root_temp_dir"] ) ) make_dirs(self.storage["root_temp_dir"]) return fix_path( pjoin( self._parse_dir_format(self.storage["root_temp_dir"]), "sauronx.tmp-" + plain_timestamp_started_with_millis, ) )
def _parse_dir_format(self, fmt: str) -> str: return ( fix_path(fmt) .replace("${number}", str(self.sauron_number)) .replace("${sauron}", str(self.sauron_name)) )
datetime_started_raw, fix_path, iso_timestamp_started, plain_timestamp_started, plain_timestamp_started_with_millis, sauronx_version, stamp, ) from .paths import SubmissionPathCollection if "SAURONX_CONFIG_PATH" not in os.environ: raise MissingEnvironmentVariableException( "Environment variable $SAURONX_CONFIG_PATH is not set; set this to the correct config.toml file" ) config_file_path = fix_path(os.environ["SAURONX_CONFIG_PATH"]) if not pexists(config_file_path): raise NoSuchPathException("SAURONX_CONFIG_PATH file {} does not exist".format(config_file_path)) if not pfile(config_file_path): raise PathIsNotFileException( "SAURONX_CONFIG_PATH file {} is not a file".format(config_file_path) ) # TODO require this to be inside sauronx/config sauronx_home = os.environ["SAURONX_HOME"] class FrameRoi: def __init__(self, x0: int, y0: int, x1: int, y1: int) -> None: self.x0 = x0 self.y0 = y0 self.x1 = x1