Просмотр исходного кода

Modified to remove hardcoded values and taken various paramters from configuration file

sachinmanawadi271 7 лет назад
Родитель
Сommit
1127a19015
5 измененных файлов с 65 добавлено и 44 удалено
  1. 21 19
      BussinessLogic.py
  2. 2 3
      app.py
  3. 7 9
      automate.py
  4. 31 13
      conf.py
  5. 4 0
      configuration.xml

+ 21 - 19
BussinessLogic.py

@@ -1,6 +1,5 @@
-from conf import PathConfig
+from conf import Config
 from pywinauto.application import Application
-import autoit
 import time
 import os
 import datetime
@@ -9,39 +8,42 @@ import time
 class business_logic:
 
     def convert_files(self,file):
-        Path = PathConfig( )
-        #app = application.Application()
+        _config = Config()
         backslash = "\\"
-        #FolderPaths = Path.getPath()
-        app_path = Path.Moved_Path+backslash+file
+        app_path = _config.Moved_Path+backslash+file
         print(app_path)
         os.startfile(app_path)
         time.sleep(50)
         print("Sleep End!!!")
         app = Application().connect(path=r"C:\Program Files\TechSmith\Camtasia 9\CamtasiaStudio.exe")
         #for TRIAL
-        app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Finish').Click()
+        if _config.Trial == 'YES':
+            app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Finish').Click()
         #end for TRIAL
         hwndwrappercamtasiastudioexebbedcaecbaeffaf = app[u'Camtasia 9']
         #remark
-        hwndwrappercamtasiastudioexebbedcaecbaeffaf.ClickInput(coords=(200, 20))
+        hwndwrappercamtasiastudioexebbedcaecbaeffaf.ClickInput(coords=(_config.Share_Btn_X, _config.Share_Btn_Y))
         hwndwrappercamtasiastudioexebbedcaecbaeffaf.TypeKeys("{DOWN}")
         hwndwrappercamtasiastudioexebbedcaecbaeffaf.TypeKeys("{ENTER}")
         time.sleep(10)
         print("Sleep End!!!")
         #for TRIAL
-        hwndwrappercamtasiastudioexebbedcaecbaeffaf.ClickInput(coords=(400, 600))
+        if _config.Trial == 'YES':
+            hwndwrappercamtasiastudioexebbedcaecbaeffaf.ClickInput(coords=(_config.Water_Mark_Btn_X, _config.Water_Mark_Btn_Y))
         #end for TRIAL
-        time.sleep(2)
-        app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Next').Click()
-        time.sleep(2)
-        app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Next').Click()
-        time.sleep(2)
-        app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Next').Click()
-        time.sleep(2)
-        app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Next').Click()
-        time.sleep(2)
-        app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Next').Click()
+        for i in range(_config.Dialogs):
+        #for no_dialogs in _config.Dialogs:
+            time.sleep(2)
+            app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Next').Click()
+
+        #time.sleep(2)
+        #app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Next').Click()
+        #time.sleep(2)
+        #app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Next').Click()
+        #time.sleep(2)
+        #app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Next').Click()
+        #time.sleep(2)
+        #app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(best_match='Next').Click()
 
         #app.Window_(best_match='Dialog', top_level_only=True).PrintControlIdentifiers()
         app.Window_(best_match='Dialog', top_level_only=True).ChildWindow(title="Untitled Project",class_name="Edit").SetText(time.time())

+ 2 - 3
app.py

@@ -1,14 +1,13 @@
 from automate import Automate
 from BussinessLogic import business_logic
-from conf import PathConfig
-from MACROS import MACROS
+from conf import Config
 Files=[]
 
 Auto = Automate()
 #Initializes from the configuration file
 Auto.Init()
 
-Path = PathConfig( )
+Path = Config( )
 #Get the folder paths to copy from src to dest
 #src_folder = Path.get_Original_Path()
 #dest_folder = Path.get_Moved_Path()

+ 7 - 9
automate.py

@@ -1,24 +1,22 @@
-from conf import PathConfig
+from conf import Config
 import os
 import shutil
 
 
 class Automate:
-    'Initialization Class for Automation'
-
-
+    #Initialization Class for Automation
     def Init(self):
-        Path = PathConfig( )
-        Path.SetPath()
+        __configuration__ = Config()
+        __configuration__.read_config()
 
     def GetFiles(self, paths):
         files = []
-        for file in os.listdir( paths ):
-            files.append( file )
+        for file in os.listdir(paths):
+            files.append(file)
         return files
 
     def copyFiles(self, src_folder,dest_folder):
-        for file in os.listdir( src_folder ):
+        for file in os.listdir(src_folder):
             print ("File being moved -----> " + file)
             full_file_name = os.path.join( src_folder, file )
             if os.path.isfile(full_file_name):

+ 31 - 13
conf.py

@@ -1,37 +1,55 @@
 import xml.etree.ElementTree as ET
 
-class PathConfig:
+class Config:
     'Configuration Class for File Paths'
     Original_Path = ""
     Moved_Path = ""
+    Dialogs = 0
+    Trial = ""
+    Share_Btn_X = 0
+    Share_Btn_Y = 0
+    Water_Mark_Btn_X = 0
+    Water_Mark_Btn_Y = 0
 
     #def __init__(self):
     #    self.Original_Path = ''
     #    self.Moved_Path = ''
 
-    def SetPath(self):
+    def read_config(self):
         tree = ET.parse('configuration.xml')
         root = tree.getroot()
         #Get the folder path where the files are present
         path = root.find('Path')
         #PathConfig.filePaths.append(path.get('path1'))
-        PathConfig.Original_Path = path.get('path1')
+        Config.Original_Path = path.get('path1')
         #Get the folder path where files are to be moved
         move_path = root.find('MovePath')
-        PathConfig.Moved_Path = move_path.get('path2')
-        #PathConfig.filePaths.append(move_path.get('path2'))
-
-
-        #for path in root:
-            #PathConfig.filePaths.append(path.get('path1'))
-            #PathConfig.filePaths.append(path.get('path2'))
-            #print(path.get('path'))
+        Config.Moved_Path = move_path.get('path2')
+        #Get the no. of dialogs screens during coversion
+        no_screens = root.find('No_Screens')
+        Config.Dialogs = no_screens.get('dialog')
+        Config.Dialogs = int(Config.Dialogs)
+        #Get if Camtasia has Trial license
+        trial = root.find('TRIAL')
+        Config.Trial = trial.get('trial')
+        #Get the co-ordinates of the share button
+        share_btn = root.find('Share_BTN_COOR')
+        Config.Share_Btn_X = share_btn.get('x')
+        Config.Share_Btn_X = int(Config.Share_Btn_X)
+        Config.Share_Btn_Y = share_btn.get('y')
+        Config.Share_Btn_Y = int(Config.Share_Btn_Y)
+        #Get the co-ordinates Watermark
+        watermark_btn = root.find('WATER_MARK_COOR')
+        Config.Water_Mark_Btn_X = watermark_btn.get('x')
+        Config.Water_Mark_Btn_X = int(Config.Water_Mark_Btn_X)
+        Config.Water_Mark_Btn_Y = watermark_btn.get('y')
+        Config.Water_Mark_Btn_Y = int(Config.Water_Mark_Btn_Y)
 
 
 
     def get_Moved_Path(self):
-        return PathConfig.Moved_Path
+        return Config.Moved_Path
 
     def get_Original_Path(self):
-        return PathConfig.Original_Path
+        return Config.Original_Path
 

+ 4 - 0
configuration.xml

@@ -2,4 +2,8 @@
 <RootPath>
     <Path path1="E:\testserver"> </Path>
     <MovePath path2="E:\testservercopy"> </MovePath>
+    <No_Screens dialog="5"> </No_Screens>
+    <TRIAL trial="YES"> </TRIAL>
+    <Share_BTN_COOR x="200" y="20"> </Share_BTN_COOR>
+    <WATER_MARK_COOR x="400" y="600"></WATER_MARK_COOR>
 </RootPath>