Files
kadastr18/priem_register/mapping.py
jze9 b5f7060a1f Приём документов → реестр + журнал
Внесение данных из файлов приёма в реестр невостребованных документов
и заполнение журнала. Дата внесения — текущая; журнал заполняется чисто
(без строк-примеров шаблона).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 03:11:18 +05:00

45 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""Поиск файлов приёма и сопоставление их с листами реестра.
Правило: файл DD.MM.YYYY_74_NN.<ext> из папки ТОk -> лист ТОk_NN.
"""
from __future__ import annotations
import datetime
from pathlib import Path
from typing import List
from .config import FILENAME_RE, PRIEM_DIR, TO_DIR_RE
from .models import SourceFile
def discover_sources(priem_dir: Path = PRIEM_DIR) -> List[SourceFile]:
priem_dir = Path(priem_dir)
if not priem_dir.is_dir():
raise FileNotFoundError("Папка приёма не найдена: %s" % priem_dir)
sources: List[SourceFile] = []
for path in sorted(priem_dir.rglob("*")):
if not path.is_file():
continue
match = FILENAME_RE.match(path.name)
if not match:
continue
dd, mm, yyyy, nn, _ext = match.groups()
to_match = TO_DIR_RE.search(str(path))
if not to_match:
raise ValueError("Не удалось определить ТО для файла: %s" % path)
try:
date = datetime.date(int(yyyy), int(mm), int(dd))
except ValueError as exc:
raise ValueError(
"Некорректная дата в имени файла %s: %s" % (path.name, exc)) from exc
sources.append(SourceFile(
path=path,
date=date,
sheet="ТО%s_%s" % (to_match.group(1), nn),
name=path.stem,
))
# порядок внесения: по листу, затем по дате (последующие записи)
sources.sort(key=lambda s: (s.sheet, s.date))
return sources