automate.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from conf import Config
  2. import os
  3. import shutil
  4. from logger import log
  5. class Automate:
  6. #Initialization Class for Automation
  7. log = log()
  8. def Init(self):
  9. __configuration__ = Config()
  10. status = __configuration__.read_config()
  11. if status == 0:
  12. return 0
  13. return 1
  14. def GetFiles(self, paths):
  15. files = []
  16. for file in os.listdir(paths):
  17. files.append(file)
  18. return files
  19. def copyFiles(self, src_folder,dest_folder,added):
  20. if src_folder == "" or dest_folder == "":
  21. log.logger.error('Source or Destination Folder does not exists')
  22. return 0
  23. if not os.listdir(src_folder):
  24. log.logger.error('No files found in src folder')
  25. return 0
  26. #for file in os.listdir(src_folder):
  27. for file in added:
  28. print ("File being moved -----> " + file)
  29. full_file_name = os.path.join( src_folder, file )
  30. if os.path.isfile(full_file_name):
  31. try:
  32. shutil.copy( full_file_name, dest_folder )
  33. except shutil.Error as e:
  34. log.logger.error('Could not copy the files %s',e)
  35. return 0
  36. return 1