/
Flipper
/
Marginal
Обзор
Документация
Войти
/
Flipper
/
Marginal
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
CI/CD
Аналитика
Безопасность
master
src/Enviformer.py
113 строк
4 KB
Alex
Marginal v1.0.0 RELEASE
11 янв 2026, 18:02
11 янв 2026, 18:02
5e1eff8
Код
Авторство
О чём код?
import os import utils class Envformer: """ Validates and manages the application's directory structure. Ensures required directories exist and can create missing ones. Note: File is named Enviformer.py but class is named Envformer """ def __init__(self): """ Initialize Envformer with base path and required directory structure. """ self.basePath = utils.getBasePath() # List of directories that must exist for the application to function self.mustDirs = [ "config", "exports", "profiles", "locker", "resources", "resources\\themes", "resources\\locales", "resources\\graphStyles" ] # Validate directory structure on initialization self.initCheckResults = self.checkInitDirs() def checkInitDirs(self): """ Validate that all required directories exist at application startup. Creates any missing directories. Returns: dict -> Statistics about directory validation. """ resultDefault = self.validateDirs(self.mustDirs, True) return resultDefault def validateDirs( self, dirs: list, createMissing: bool = False, func: callable = None ): """ Validate that specified directories exist in the application structure. Args: dirs (list): List of directory paths (relative to base path) to validate. createMissing (bool): If True, create directories that don't exist. func (callable): Optional callback function to execute for missing directories instead of creating them. Returns: dict -> Statistics dictionary with the following structure: - basePath (str): The base application path - dirsChecked (int): Number of directories checked - dirsExisted (int): Number of directories that already existed - dirsCreated (int): Number of directories created (only when createMissing=True) - dirsCreationSuccess (int): Number of successfully created directories - errors (list): List of error messages encountered during validation """ stats = { "basePath": self.basePath, "dirsChecked": 0, "dirsExisted": 0, "dirsCreated": 0, "dirsCreationSuccess": 0, "errors": [] } for dirName in dirs: # Generate full path from base path and relative directory name dirPath = utils.generateFullPath(self.basePath, dirName) stats["dirsChecked"] += 1 exists = os.path.exists(dirPath) if exists: stats["dirsExisted"] += 1 elif createMissing: # Attempt to create missing directory try: os.makedirs(dirPath, exist_ok=True) if os.path.exists(dirPath): stats["dirsCreated"] += 1 stats["dirsCreationSuccess"] += 1 else: stats["errors"].append(f"Failed to create: {dirPath}") except Exception as e: stats["errors"].append(f"Error creating {dirPath}: {str(e)}") elif func: # Execute callback function for custom handling of missing directory try: func(dirPath) except Exception as e: stats["errors"].append( f"Error calling provided function for {dirPath}: {str(e)}" ) # Clean up statistics for better readability if stats["dirsChecked"] == stats["dirsExisted"]: stats["dirsCreationSuccess"] = "N/A" if stats["errors"] == list(): stats["errors"] = "None" return stats