common.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """common definitions."""
  2. import os
  3. import shutil
  4. def check_shell(cmd):
  5. """shell successful."""
  6. res = os.system(cmd)
  7. assert res == 0
  8. def cli_count_folders_and_check_contents(file_path):
  9. """" count cli files."""
  10. if os.path.exists(file_path):
  11. for files in os.listdir(file_path):
  12. folder_count = os.path.getsize(os.path.join(file_path, files))
  13. assert folder_count > 0
  14. assert len(os.listdir(file_path)) > 5
  15. def sdk_count_folders_and_check_contents(file_path):
  16. """count folders."""
  17. if os.path.exists(file_path):
  18. file_count = os.path.getsize(file_path)
  19. assert file_count > 0
  20. else:
  21. exit(1)
  22. def delete_file(path):
  23. """delete file."""
  24. if not os.path.exists(path):
  25. if os.path.isfile(path):
  26. try:
  27. os.remove(path)
  28. print(f"File '{path}' deleted.")
  29. except TypeError as e:
  30. print(f"Error deleting file '{path}': {e}")
  31. elif os.path.isdir(path):
  32. try:
  33. shutil.rmtree(path)
  34. print(f"Directory '{path}' and its contents deleted.")
  35. except TypeError as e:
  36. print(f"Error deleting directory '{path}': {e}")