Release 0.3.2: YAML config, default_baseconfs, autodiscover.
Конфиг утилиты переведён на YAML; default_baseconfs для reindex без -b; автопоиск config.local.yml/.yaml/.json; обобщённая документация. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+47
-26
@@ -5,28 +5,10 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
# Папки выгрузок относительно корня проекта (есть src/).
|
||||
DEFAULT_CONFIGS: tuple[str, ...] = (
|
||||
"crm3-26",
|
||||
"crm3-26.rhana",
|
||||
"crm3-dev",
|
||||
"crm3-dev.rhana",
|
||||
"crm3-dev.docs",
|
||||
"ws-rhana",
|
||||
"bu-corp",
|
||||
"bu-corp.rhana",
|
||||
"diadoc.ext.rhana",
|
||||
)
|
||||
|
||||
# Алиасы имён конфигураций 1С для CLI (--baseconf / -b).
|
||||
CONFIG_ALIASES: dict[str, str] = {
|
||||
"crm3_26": "crm3-26",
|
||||
"crm3_old": "crm3-dev",
|
||||
"crm3-old": "crm3-dev",
|
||||
"crm3_dev": "crm3-dev",
|
||||
"target": "crm3-26",
|
||||
"source": "crm3-dev",
|
||||
}
|
||||
# Алиасы имён конфигураций 1С для CLI (--baseconf / -b), задаются через --config
|
||||
# (поле baseconf_aliases в YAML). См. config.example.yml.
|
||||
_RUNTIME_ALIASES: dict[str, str] = {}
|
||||
_RUNTIME_DEFAULT_BASECONFS: list[str] = []
|
||||
|
||||
# Папка EDT → канонический тип (английский идентификатор выгрузки).
|
||||
OBJECT_TYPE_FOLDERS: dict[str, str] = {
|
||||
@@ -192,13 +174,52 @@ class ConfigPaths:
|
||||
|
||||
|
||||
def project_root_from_here() -> Path:
|
||||
"""tools/index/index1c → корень проекта."""
|
||||
return Path(__file__).resolve().parents[3]
|
||||
"""Корень проекта: каталог с index_1c.py и VERSION."""
|
||||
here = Path(__file__).resolve().parent
|
||||
for candidate in (here.parent, here.parent.parent, here.parent.parent.parent):
|
||||
if (candidate / "index_1c.py").is_file() and (candidate / "VERSION").is_file():
|
||||
return candidate
|
||||
return here.parent
|
||||
|
||||
|
||||
def set_config_aliases(aliases: dict[str, str] | None) -> None:
|
||||
"""Задать алиасы baseconf из файла --config (baseconf_aliases)."""
|
||||
global _RUNTIME_ALIASES
|
||||
_RUNTIME_ALIASES = {str(k): str(v) for k, v in (aliases or {}).items()}
|
||||
|
||||
|
||||
def get_config_aliases() -> dict[str, str]:
|
||||
return dict(_RUNTIME_ALIASES)
|
||||
|
||||
|
||||
def set_default_baseconfs(names: list[str] | None) -> None:
|
||||
"""Задать default_baseconfs из файла --config (YAML)."""
|
||||
global _RUNTIME_DEFAULT_BASECONFS
|
||||
_RUNTIME_DEFAULT_BASECONFS = [str(x) for x in (names or []) if str(x).strip()]
|
||||
|
||||
|
||||
def get_default_baseconfs() -> list[str]:
|
||||
"""Список baseconf по умолчанию для reindex без -b."""
|
||||
return list(_RUNTIME_DEFAULT_BASECONFS)
|
||||
|
||||
|
||||
def resolve_config_name(name: str) -> str:
|
||||
key = name.strip()
|
||||
return CONFIG_ALIASES.get(key, CONFIG_ALIASES.get(key.lower(), key))
|
||||
aliases = get_config_aliases()
|
||||
return aliases.get(key, aliases.get(key.lower(), key))
|
||||
|
||||
|
||||
def list_config_dirs(project_root: Path) -> list[str]:
|
||||
"""Все каталоги с выгрузкой 1С (<name>/src/) в корне проекта."""
|
||||
if not project_root.is_dir():
|
||||
return []
|
||||
found: list[str] = []
|
||||
for child in sorted(project_root.iterdir()):
|
||||
if not child.is_dir() or child.name.startswith("."):
|
||||
continue
|
||||
if (child / "src").is_dir():
|
||||
found.append(child.name)
|
||||
return found
|
||||
|
||||
|
||||
def resolve_object_type(name: str) -> str:
|
||||
@@ -217,7 +238,7 @@ def resolve_object_type(name: str) -> str:
|
||||
|
||||
|
||||
def discover_configs(project_root: Path, names: list[str] | None = None) -> list[ConfigPaths]:
|
||||
wanted = [resolve_config_name(n) for n in names] if names else list(DEFAULT_CONFIGS)
|
||||
wanted = [resolve_config_name(n) for n in names] if names else list_config_dirs(project_root)
|
||||
found: list[ConfigPaths] = []
|
||||
for name in wanted:
|
||||
root = project_root / name
|
||||
|
||||
Reference in New Issue
Block a user