Directories.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import os
  2. from shutil import copytree
  3. from progress.bar import Bar
  4. class Directories:
  5. def __init__(self, path_to, server_list):
  6. self.path_to = path_to
  7. self.server_list = server_list
  8. self.create_directories_with_name_server()
  9. def create_directories_with_name_server(self):
  10. for server in self.server_list:
  11. os.makedirs(self.path_to + server.open, exist_ok=True)
  12. def get_correct_server(self, information_metadata_file):
  13. correct_server = None
  14. for server in self.server_list:
  15. if information_metadata_file.server_name in [server.open, server.bbb, server.ip]:
  16. correct_server = server
  17. break
  18. return correct_server
  19. def copy_video_bbb(self, path_from, list_information_metadata_file):
  20. bar = Bar('Copy directories', max=len(list_information_metadata_file))
  21. for information_metadata_file in list_information_metadata_file:
  22. server_to = self.get_correct_server(information_metadata_file)
  23. try:
  24. if server_to is not None:
  25. path_to = F"{self.path_to}{server_to.open}/{information_metadata_file.root}"
  26. copytree(path_from + information_metadata_file.root, path_to)
  27. except FileExistsError:
  28. pass
  29. bar.next()
  30. bar.finish()