79 lines
2.7 KiB
Python
79 lines
2.7 KiB
Python
"""
|
|
Seed Data Path Utilities
|
|
Provides functions to locate seed data files for demo data creation
|
|
"""
|
|
|
|
from pathlib import Path
|
|
import os
|
|
|
|
|
|
def get_seed_data_path(profile: str, filename: str, child_profile: str = None) -> Path:
|
|
"""
|
|
Get the path to a seed data file, searching in multiple locations.
|
|
|
|
Args:
|
|
profile: Demo profile (professional/enterprise)
|
|
filename: Seed data filename
|
|
child_profile: Optional child profile for enterprise demos
|
|
|
|
Returns:
|
|
Path to the seed data file
|
|
|
|
Raises:
|
|
FileNotFoundError: If seed data file cannot be found in any location
|
|
"""
|
|
# Search locations in order of priority
|
|
search_locations = []
|
|
|
|
# 1. First check in shared/demo/fixtures (new location)
|
|
if child_profile:
|
|
# Enterprise child profile
|
|
search_locations.append(
|
|
Path(__file__).parent.parent / "demo" / "fixtures" / profile / child_profile / filename
|
|
)
|
|
else:
|
|
# Regular profile
|
|
search_locations.append(
|
|
Path(__file__).parent.parent / "demo" / "fixtures" / profile / filename
|
|
)
|
|
|
|
# 2. Check in infrastructure/seed-data (old location)
|
|
if child_profile:
|
|
search_locations.append(
|
|
Path(__file__).parent.parent.parent / "infrastructure" / "seed-data" / profile / "children" / f"{child_profile}.json"
|
|
)
|
|
else:
|
|
search_locations.append(
|
|
Path(__file__).parent.parent.parent / "infrastructure" / "seed-data" / profile / filename
|
|
)
|
|
|
|
# 3. Check in infrastructure/seed-data with alternative paths
|
|
if profile == "enterprise" and not child_profile:
|
|
search_locations.append(
|
|
Path(__file__).parent.parent.parent / "infrastructure" / "seed-data" / profile / "parent" / filename
|
|
)
|
|
# Also check the shared/demo/fixtures/enterprise/parent directory
|
|
search_locations.append(
|
|
Path(__file__).parent.parent / "demo" / "fixtures" / profile / "parent" / filename
|
|
)
|
|
|
|
# Find the first existing file
|
|
for file_path in search_locations:
|
|
if file_path.exists():
|
|
return file_path
|
|
|
|
# If no file found, raise an error with all searched locations
|
|
searched_paths = "\n".join([str(p) for p in search_locations])
|
|
raise FileNotFoundError(
|
|
f"Seed data file not found: {filename}\n"
|
|
f"Profile: {profile}\n"
|
|
f"Child profile: {child_profile}\n"
|
|
f"Searched locations:\n{searched_paths}"
|
|
)
|
|
|
|
|
|
def get_demo_fixture_path(profile: str, filename: str, child_profile: str = None) -> Path:
|
|
"""
|
|
Alternative function name for backward compatibility
|
|
"""
|
|
return get_seed_data_path(profile, filename, child_profile) |