from __future__ import annotations import re from datetime import datetime FILE_NAME_PATTERNS = ( re.compile(r"^SKO115FZ_\d{2}_[A-Za-zА-Яа-я0-9]{9}_\d{8}_(?:[ХX]\d{5}|\d{6})\.xml$"), ) DEFAULT_OUTPUT_DIR_NAME = "Out" REPORT_FILE_TEMPLATE = "report_{date_key}_{run_number}.xlsx" PROTOCOL_FILE_TEMPLATE = "protocol_{date_key}_{run_number}.xlsx" PROCESS_LOG_FILE_TEMPLATE = "process_{date_key}_{run_number}.log" def validate_file_name(file_name: str) -> bool: return any(pattern.match(file_name) for pattern in FILE_NAME_PATTERNS) def build_date_parts(now: datetime | None = None) -> tuple[str, str, str, str]: current = now or datetime.now() year = str(current.year) month = str(current.month) day = str(current.day) date_key = current.strftime("%Y%m%d") return year, month, day, date_key def build_report_file_name(date_key: str, run_number: int) -> str: return REPORT_FILE_TEMPLATE.format(date_key=date_key, run_number=run_number) def build_protocol_file_name(date_key: str, run_number: int) -> str: return PROTOCOL_FILE_TEMPLATE.format(date_key=date_key, run_number=run_number) def build_process_log_file_name(date_key: str, run_number: int) -> str: return PROCESS_LOG_FILE_TEMPLATE.format(date_key=date_key, run_number=run_number)