232 lines
7.6 KiB
Python
232 lines
7.6 KiB
Python
"""Каталоги конфигураций проекта и типы объектов метаданных 1С."""
|
|
|
|
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",
|
|
}
|
|
|
|
# Папка EDT → канонический тип (английский идентификатор выгрузки).
|
|
OBJECT_TYPE_FOLDERS: dict[str, str] = {
|
|
"AccumulationRegisters": "AccumulationRegister",
|
|
"BusinessProcesses": "BusinessProcess",
|
|
"Catalogs": "Catalog",
|
|
"ChartsOfAccounts": "ChartOfAccounts",
|
|
"ChartsOfCalculationTypes": "ChartOfCalculationTypes",
|
|
"ChartsOfCharacteristicTypes": "ChartOfCharacteristicTypes",
|
|
"CommandGroups": "CommandGroup",
|
|
"CommonAttributes": "CommonAttribute",
|
|
"CommonCommands": "CommonCommand",
|
|
"CommonForms": "CommonForm",
|
|
"CommonModules": "CommonModule",
|
|
"CommonPictures": "CommonPicture",
|
|
"CommonTemplates": "CommonTemplate",
|
|
"Constants": "Constant",
|
|
"DataProcessors": "DataProcessor",
|
|
"DefinedTypes": "DefinedType",
|
|
"DocumentJournals": "DocumentJournal",
|
|
"DocumentNumerators": "DocumentNumerator",
|
|
"Documents": "Document",
|
|
"Enums": "Enum",
|
|
"EventSubscriptions": "EventSubscription",
|
|
"ExchangePlans": "ExchangePlan",
|
|
"FilterCriteria": "FilterCriterion",
|
|
"FunctionalOptions": "FunctionalOption",
|
|
"FunctionalOptionsParameters": "FunctionalOptionsParameter",
|
|
"HTTPServices": "HTTPService",
|
|
"InformationRegisters": "InformationRegister",
|
|
"IntegrationServices": "IntegrationService",
|
|
"Reports": "Report",
|
|
"Roles": "Role",
|
|
"ScheduledJobs": "ScheduledJob",
|
|
"SessionParameters": "SessionParameter",
|
|
"SettingsStorages": "SettingsStorage",
|
|
"StyleItems": "StyleItem",
|
|
"Subsystems": "Subsystem",
|
|
"Tasks": "Task",
|
|
"WebServices": "WebService",
|
|
"WSReferences": "WSReference",
|
|
"XDTOPackages": "XDTOPackage",
|
|
"Bots": "Bot",
|
|
"ExternalDataSources": "ExternalDataSource",
|
|
"Languages": "Language",
|
|
}
|
|
|
|
# Алиасы типов для --types (русский / короткий / мн.ч.).
|
|
TYPE_ALIASES: dict[str, str] = {
|
|
"catalog": "Catalog",
|
|
"catalogs": "Catalog",
|
|
"справочник": "Catalog",
|
|
"справочники": "Catalog",
|
|
"document": "Document",
|
|
"documents": "Document",
|
|
"документ": "Document",
|
|
"документы": "Document",
|
|
"informationregister": "InformationRegister",
|
|
"informationregisters": "InformationRegister",
|
|
"регистрсведений": "InformationRegister",
|
|
"регистрысведений": "InformationRegister",
|
|
"рс": "InformationRegister",
|
|
"accumulationregister": "AccumulationRegister",
|
|
"accumulationregisters": "AccumulationRegister",
|
|
"регистрнакопления": "AccumulationRegister",
|
|
"регистрынакопления": "AccumulationRegister",
|
|
"рн": "AccumulationRegister",
|
|
"constant": "Constant",
|
|
"constants": "Constant",
|
|
"константа": "Constant",
|
|
"константы": "Constant",
|
|
"enum": "Enum",
|
|
"enums": "Enum",
|
|
"перечисление": "Enum",
|
|
"перечисления": "Enum",
|
|
"commonmodule": "CommonModule",
|
|
"commonmodules": "CommonModule",
|
|
"общиймодуль": "CommonModule",
|
|
"общиемодули": "CommonModule",
|
|
"dataprocessor": "DataProcessor",
|
|
"dataprocessors": "DataProcessor",
|
|
"обработка": "DataProcessor",
|
|
"обработки": "DataProcessor",
|
|
"report": "Report",
|
|
"reports": "Report",
|
|
"отчет": "Report",
|
|
"отчеты": "Report",
|
|
"exchangeplan": "ExchangePlan",
|
|
"exchangeplans": "ExchangePlan",
|
|
"планыобмена": "ExchangePlan",
|
|
"definedtype": "DefinedType",
|
|
"definedtypes": "DefinedType",
|
|
"определяемыетипы": "DefinedType",
|
|
"chartofcharacteristictypes": "ChartOfCharacteristicTypes",
|
|
"пвх": "ChartOfCharacteristicTypes",
|
|
"role": "Role",
|
|
"roles": "Role",
|
|
"роль": "Role",
|
|
"роли": "Role",
|
|
"subsystem": "Subsystem",
|
|
"subsystems": "Subsystem",
|
|
"подсистема": "Subsystem",
|
|
"подсистемы": "Subsystem",
|
|
"httpservice": "HTTPService",
|
|
"httpservices": "HTTPService",
|
|
"documentjournal": "DocumentJournal",
|
|
"documentjournals": "DocumentJournal",
|
|
"журналыдокументов": "DocumentJournal",
|
|
"task": "Task",
|
|
"tasks": "Task",
|
|
"задача": "Task",
|
|
"задачи": "Task",
|
|
"businessprocess": "BusinessProcess",
|
|
"businessprocesses": "BusinessProcess",
|
|
"бизнеспроцесс": "BusinessProcess",
|
|
"бизнеспроцессы": "BusinessProcess",
|
|
"модуль": "CommonModule",
|
|
"модули": "CommonModule",
|
|
"bsl": "CommonModule",
|
|
}
|
|
|
|
# Типы с разбором реквизитов / измерений / ссылок.
|
|
FIELD_RICH_TYPES: frozenset[str] = frozenset(
|
|
{
|
|
"Catalog",
|
|
"Document",
|
|
"InformationRegister",
|
|
"AccumulationRegister",
|
|
"ChartOfCharacteristicTypes",
|
|
"ChartOfAccounts",
|
|
"ChartOfCalculationTypes",
|
|
"ExchangePlan",
|
|
"BusinessProcess",
|
|
"Task",
|
|
"DocumentJournal",
|
|
"Constant",
|
|
"DefinedType",
|
|
"CommonAttribute",
|
|
"Enum",
|
|
}
|
|
)
|
|
|
|
# Типы, которые по умолчанию пропускаем (шум / картинки).
|
|
DEFAULT_SKIP_TYPES: frozenset[str] = frozenset(
|
|
{
|
|
"CommonPicture",
|
|
"StyleItem",
|
|
"XDTOPackage",
|
|
"CommonTemplate",
|
|
"Language",
|
|
"Bot",
|
|
}
|
|
)
|
|
|
|
FOLDER_BY_TYPE: dict[str, str] = {v: k for k, v in OBJECT_TYPE_FOLDERS.items()}
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ConfigPaths:
|
|
name: str
|
|
root: Path
|
|
src: Path
|
|
|
|
|
|
def project_root_from_here() -> Path:
|
|
"""tools/index/index1c → корень проекта."""
|
|
return Path(__file__).resolve().parents[3]
|
|
|
|
|
|
def resolve_config_name(name: str) -> str:
|
|
key = name.strip()
|
|
return CONFIG_ALIASES.get(key, CONFIG_ALIASES.get(key.lower(), key))
|
|
|
|
|
|
def resolve_object_type(name: str) -> str:
|
|
raw = name.strip()
|
|
if raw in FOLDER_BY_TYPE:
|
|
return raw
|
|
if raw in OBJECT_TYPE_FOLDERS:
|
|
return OBJECT_TYPE_FOLDERS[raw]
|
|
compact = raw.replace(" ", "").replace("_", "").replace("-", "").casefold()
|
|
if compact in TYPE_ALIASES:
|
|
return TYPE_ALIASES[compact]
|
|
for folder, otype in OBJECT_TYPE_FOLDERS.items():
|
|
if folder.casefold() == raw.casefold() or otype.casefold() == raw.casefold():
|
|
return otype
|
|
raise ValueError(f"Неизвестный тип объекта метаданных: {name!r}")
|
|
|
|
|
|
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)
|
|
found: list[ConfigPaths] = []
|
|
for name in wanted:
|
|
root = project_root / name
|
|
src = root / "src"
|
|
if src.is_dir():
|
|
found.append(ConfigPaths(name=name, root=root, src=src))
|
|
return found
|
|
|
|
|
|
def cache_dir(project_root: Path) -> Path:
|
|
return project_root / "cache" / "1c_meta"
|