FileUtils.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from glob import glob
  2. import os
  3. expected_subfolders = sorted(["Motion", "Lapse", "Full"])
  4. def list_folders(path: str) -> list:
  5. """Returns the names of all immediate child folders of path.
  6. Args:
  7. path (str): path to search
  8. Returns:
  9. list: list of all child folder names
  10. """
  11. return [name for name in os.listdir(path) if os.path.isdir(os.path.join(path, name))]
  12. def list_jpegs_recursive(path: str) -> list:
  13. """Recursively lists all jpeg files in path.
  14. Args:
  15. path (str): path to search
  16. Returns:
  17. list: list of all jpeg files
  18. """
  19. return [name for name in glob(os.path.join(path, "**/*.jpg"), recursive=True) if os.path.isfile(os.path.join(path, name))]
  20. def verify_expected_subfolders(session_path: str):
  21. """Assert that the given session folder contains exactly the three subfolders Motion, Lapse, Full.
  22. Args:
  23. session_path (str): session folder path
  24. """
  25. subfolders = list_folders(session_path)
  26. assert sorted(subfolders) == expected_subfolders