startup.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. Application startup utilities.
  3. Handles initial setup of required directories and configuration files.
  4. This module ensures the application environment is properly configured
  5. before the main application starts.
  6. """
  7. import os
  8. import logging
  9. logger = logging.getLogger(__name__)
  10. def ensure_base_structure(base_dir: str) -> None:
  11. """
  12. Ensure required base directory structure exists.
  13. Creates necessary subdirectories for artifacts, configs, workdir,
  14. and secrets if they don't already exist.
  15. Args:
  16. base_dir: The base directory path (typically from CBS_BASEDIR)
  17. """
  18. if not base_dir:
  19. logger.warning("Base directory not specified, skipping initialization")
  20. return
  21. subdirs = [
  22. 'artifacts',
  23. 'configs',
  24. 'workdir',
  25. 'secrets',
  26. ]
  27. for subdir in subdirs:
  28. path = os.path.join(base_dir, subdir)
  29. os.makedirs(path, exist_ok=True)
  30. logger.debug(f"Ensured directory exists: {path}")
  31. def initialize_application(base_dir: str) -> None:
  32. """
  33. Initialize the application environment.
  34. Performs all necessary setup operations including creating the required
  35. directory structure.
  36. Args:
  37. base_dir: The base directory path (typically from CBS_BASEDIR)
  38. """
  39. if not base_dir:
  40. logger.warning("CBS_BASEDIR not set, skipping initialization")
  41. return
  42. logger.info(f"Initializing application with base directory: {base_dir}")
  43. ensure_base_structure(base_dir)
  44. logger.info("Application initialization complete")