Files
vaiola/modelspace/Repository.py
Bacruru Sakaguchi 9e5e214944 initial commit
2025-09-12 17:10:13 +07:00

58 lines
2.0 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.

import uuid
from dataclasses import dataclass
from pathlib import Path
from modelspace.ModelPackage import ModelPackage
from pythonapp.Libs.ConfigDataClass import Config
@dataclass
class RepoConfig(Config):
"""Конфигурация репозитория с сидом"""
seed: str = "" # UUID сида
class Repository:
def __init__(self, path: str):
self.path = Path(path)
# Создаем директорию если она не существует
self.path.mkdir(parents=True, exist_ok=True)
self.config_file = self.path / "repo.json"
# Создаем конфигурацию
self.config = RepoConfig(
filename=str(self.config_file),
autosave=True
)
# Проверяем и устанавливаем сид
if not self.config.seed:
self._generate_and_save_seed()
# Создаем поддиректорию model-packages если она не существует
self.model_packages_path = self.path / "model-packages"
self.model_packages_path.mkdir(exist_ok=True)
def _generate_and_save_seed(self) -> None:
"""Генерирует новый UUID и сохраняет его в конфиг"""
self.config.seed = str(uuid.uuid4())
self.config.save() # Сохраняем сразу после генерации
@property
def seed(self) -> str:
"""Возвращает текущий сид"""
return self.config.seed
def add_model_package_interactive(self) -> ModelPackage:
"""Добавляет новый пакет модели интерактивно"""
# Генерируем новый UUID
package_uuid = str(uuid.uuid4())
# Создаем путь к новому пакету
package_path = self.model_packages_path / package_uuid
# Вызываем интерактивное создание пакета
package = ModelPackage.interactive(str(package_path), package_uuid)
return package