Camtasia_UIAUtomation.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #This file contains the basic workflow of Camtasia UI Automation
  2. from helper import Automate
  3. from Render_video import render_video
  4. from conf import Config
  5. from logger import log
  6. import sys
  7. import os, time
  8. #Initialization
  9. #Creates an instane of logger class.
  10. log = log()
  11. #Creates an instane of Automate class.
  12. #which contains the helper functions.
  13. Auto = Automate()
  14. #Reads the configuration.xml to get configuration parameters
  15. Auto.readConfig()
  16. log.logger.info('Automate initialized')
  17. #Creates an instance of render_video class.
  18. #Which is done by pywinauto library
  19. bi = render_video()
  20. #Get the files already present in the watch directory
  21. if os.path.exists(Auto.__configuration__.Original_Path):
  22. before = dict([(f, None) for f in os.listdir(Auto.__configuration__.Original_Path)])
  23. log.logger.info("Already existing files:")
  24. log.logger.info(before)
  25. else:
  26. log.logger.error("-------> Trec file path is invalid. Recheck the configuration.xml, and RESTART THE APP ----->")
  27. sys.exit() #Exits the automation app if configuration is not correct
  28. #Infinite loop to watch file changes in the WatchFolder
  29. while 1:
  30. fileNames = []
  31. #Checking wether files currently present are already rendered successfully.
  32. with open("SuccessfullyRenderedFiles.txt") as file:
  33. for line in file:
  34. line = line.strip()
  35. fileNames.append(line)
  36. differenceList= list(set(before.keys())-set(fileNames))
  37. differenceJSON =dict([(f, None) for f in differenceList])
  38. #Check new added files after Polling_time
  39. time.sleep (Auto.__configuration__.Polling_time)
  40. #Get the new added trec files
  41. if os.path.exists(Auto.__configuration__.Original_Path):
  42. after = dict ([(f, None) for f in os.listdir (Auto.__configuration__.Original_Path)])
  43. added = [f for f in after if not f in before]
  44. added+=differenceJSON
  45. # print " addedJSON"+added
  46. else:
  47. log.logger.info("Trec file path does not exists!")
  48. sys.exit()
  49. if added:
  50. log.logger.info("Files added:")
  51. log.logger.info(added)
  52. for file in added:
  53. log.logger.info(file)
  54. rendered_file_name = bi.convert_files(file)
  55. if rendered_file_name :
  56. log.logger.info('Rendering Successful')
  57. backslash = "\\"
  58. full_path_of_rendered_file = Auto.__configuration__.Saved_Path+backslash+rendered_file_name
  59. rendered_html_file = rendered_file_name+".html"
  60. if os.path.exists(full_path_of_rendered_file):
  61. status = Auto.renameFile(full_path_of_rendered_file,rendered_html_file)
  62. #If the file is renamed successfully, then we are adding it to the SuccessfullyRenderedFiles.txt
  63. if status == 1:
  64. renderedFileList= open("SuccessfullyRenderedFiles.txt","a+")
  65. # print rendered_file_name
  66. renderedFileList.write("%s.trec\n" % rendered_file_name)
  67. renderedFileList.close()
  68. log.logger.info("Renaming Successful!")
  69. else:
  70. log.logger.info("Renaming not Successful!")
  71. else:
  72. log.logger.info("Rendered file does not exists!")
  73. sys.exit()
  74. else:
  75. log.logger.info('Rendering not successful')
  76. before = after