You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cleanup.py 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env python3
  2. import shutil
  3. import sys
  4. from pathlib import Path
  5. from common import Logger
  6. def cleanup() -> None:
  7. """Clean up all configuration files and reports created during setup and stress testing."""
  8. log = Logger("Cleanup")
  9. log.header("Stress Test Cleanup")
  10. config_dir = Path(__file__).parent / "setup" / "config"
  11. reports_dir = Path(__file__).parent / "reports"
  12. dirs_to_clean = []
  13. if config_dir.exists():
  14. dirs_to_clean.append(config_dir)
  15. if reports_dir.exists():
  16. dirs_to_clean.append(reports_dir)
  17. if not dirs_to_clean:
  18. log.success("No directories to clean. Everything is already clean.")
  19. return
  20. log.info("Cleaning up stress test data...")
  21. log.info("This will remove:")
  22. for dir_path in dirs_to_clean:
  23. log.list_item(str(dir_path))
  24. # List files that will be deleted
  25. log.separator()
  26. if config_dir.exists():
  27. config_files = list(config_dir.glob("*.json"))
  28. if config_files:
  29. log.info("Config files to be removed:")
  30. for file in config_files:
  31. log.list_item(file.name)
  32. if reports_dir.exists():
  33. report_files = list(reports_dir.glob("*"))
  34. if report_files:
  35. log.info("Report files to be removed:")
  36. for file in report_files:
  37. log.list_item(file.name)
  38. # Ask for confirmation if running interactively
  39. if sys.stdin.isatty():
  40. log.separator()
  41. log.warning("This action cannot be undone!")
  42. confirmation = input("Are you sure you want to remove all config and report files? (yes/no): ")
  43. if confirmation.lower() not in ["yes", "y"]:
  44. log.error("Cleanup cancelled.")
  45. return
  46. try:
  47. # Remove directories and all their contents
  48. for dir_path in dirs_to_clean:
  49. shutil.rmtree(dir_path)
  50. log.success(f"{dir_path.name} directory removed successfully!")
  51. log.separator()
  52. log.info("To run the setup again, execute:")
  53. log.list_item("python setup_all.py")
  54. log.info("Or run scripts individually in this order:")
  55. log.list_item("python setup/mock_openai_server.py (in a separate terminal)")
  56. log.list_item("python setup/setup_admin.py")
  57. log.list_item("python setup/login_admin.py")
  58. log.list_item("python setup/install_openai_plugin.py")
  59. log.list_item("python setup/configure_openai_plugin.py")
  60. log.list_item("python setup/import_workflow_app.py")
  61. log.list_item("python setup/create_api_key.py")
  62. log.list_item("python setup/publish_workflow.py")
  63. log.list_item("python setup/run_workflow.py")
  64. except PermissionError as e:
  65. log.error(f"Permission denied: {e}")
  66. log.info("Try running with appropriate permissions.")
  67. except Exception as e:
  68. log.error(f"An error occurred during cleanup: {e}")
  69. if __name__ == "__main__":
  70. cleanup()