add errors
This commit is contained in:
@@ -93,6 +93,72 @@ def save_and_unpack_dashboard(
|
||||
logger.error(f"Ошибка обработки дашборда: {str(e)}", exc_info=True)
|
||||
raise RuntimeError(f"Failed to unpack dashboard: {str(e)}") from e
|
||||
|
||||
def print_directory(root_dir):
|
||||
if not os.path.isdir(root_dir):
|
||||
print(f"Error: '{root_dir}' is not a valid directory")
|
||||
return
|
||||
|
||||
# Печатаем корневую директорию
|
||||
print(f"{root_dir}/")
|
||||
|
||||
# Получаем список элементов в корневой директории
|
||||
with os.scandir(root_dir) as entries:
|
||||
for entry in entries:
|
||||
# Определяем отступ и форматирование
|
||||
line = " ├── " if entry.name != sorted(os.listdir(root_dir))[-1] else " └── "
|
||||
suffix = "/" if entry.is_dir() else ""
|
||||
print(f"{line}{entry.name}{suffix}")
|
||||
|
||||
def validate_directory_structure(root_dir):
|
||||
# Проверяем корневую папку
|
||||
root_items = os.listdir(root_dir)
|
||||
if len(root_items) != 1:
|
||||
return False
|
||||
|
||||
subdir_name = root_items[0]
|
||||
subdir_path = os.path.join(root_dir, subdir_name)
|
||||
if not os.path.isdir(subdir_path):
|
||||
return False
|
||||
|
||||
# Проверяем вложенную папку
|
||||
subdir_items = os.listdir(subdir_path)
|
||||
|
||||
# Проверяем наличие metadata.yaml
|
||||
if 'metadata.yaml' not in subdir_items:
|
||||
return False
|
||||
if not os.path.isfile(os.path.join(subdir_path, 'metadata.yaml')):
|
||||
return False
|
||||
|
||||
# Проверяем допустимые папки
|
||||
allowed_folders = {'databases', 'datasets', 'charts', 'dashboards'}
|
||||
found_folders = set()
|
||||
|
||||
for item in subdir_items:
|
||||
item_path = os.path.join(subdir_path, item)
|
||||
|
||||
# Пропускаем файл метаданных
|
||||
if item == 'metadata.yaml':
|
||||
continue
|
||||
|
||||
# Проверяем что элемент является папкой
|
||||
if not os.path.isdir(item_path):
|
||||
return False
|
||||
|
||||
# Проверяем допустимость имени папки
|
||||
if item not in allowed_folders:
|
||||
return False
|
||||
|
||||
# Проверяем уникальность папки
|
||||
if item in found_folders:
|
||||
return False
|
||||
found_folders.add(item)
|
||||
|
||||
# Проверяем количество папок
|
||||
if not 1 <= len(found_folders) <= 4:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def create_dashboard_export(zip_name, source_paths,
|
||||
exclude_extensions=None,
|
||||
compress_type=zipfile.ZIP_DEFLATED,
|
||||
@@ -107,6 +173,12 @@ def create_dashboard_export(zip_name, source_paths,
|
||||
compress_type: Тип сжатия (по умолчанию ZIP_DEFLATED)
|
||||
"""
|
||||
logger = logger or SupersetLogger(name="fileio", console=False)
|
||||
|
||||
for path in source_paths:
|
||||
if not validate_directory_structure(path):
|
||||
logger.error(f"Некорректная структура директории: {path} [1]")
|
||||
logger.error(print_directory(path))
|
||||
|
||||
logger.info(f"Упаковываем дашборд {source_paths} в {zip_name}")
|
||||
try:
|
||||
exclude_ext = [ext.lower() for ext in exclude_extensions] if exclude_extensions else []
|
||||
|
||||
Reference in New Issue
Block a user