First, Python and Monkey script scripts are combined to achieve the modification. Content in script scripts
1 #Coding:utf-82 " "3 push script into the indoor machine and run4 5 " "6 ImportOS7 ImportRe8 Importsubprocess9 Ten #Execute Script One defRun_monkey (path): Afilelist=os.listdir (path) - forFileNameinchfilelist: -Filepath=Os.path.join (path,filename) theCmd="adb remount" -P=subprocess. Popen (cmd,shell=True) - p.wait () - ifp.returncode!=0: + return-1 -Cmd="ADB push"+filepath+"sdcard/" +P=subprocess. Popen (cmd,shell=True) A p.wait () at ifp.returncode!=0: - return-1 -Tarpath=os.path.join (R"sdcard/", filename) -Cmd="adb shell monkey-f"+tarpath+"- v 1" -P=subprocess. Popen (cmd,shell=True) - p.wait () in ifp.returncode!=0: - return-1 to + #Modify the contents of a script - defModify_monkey (PATH,REPSTR): thefilelist=os.listdir (path) * forFileNameinchfilelist: $Filepath=Os.path.join (path,filename)Panax Notoginsengcontect="" -With open (filepath,encoding='Utf-8') as file: thetext=File.read () +Pattern=re.compile (R"capturedispatchstring (. *)") ARepstr="capturedispatchstring ({})". Format (REPSTR) thecontect=re.sub (Pattern,repstr,text) +With open (filepath,mode='W', encoding='Utf-8') as file: - file.write (contect) $ if __name__=="__main__": $Path=r"C:\Users\Administrator\Desktop\pythoncmd\runscript" -times=500 - forIinchRange (times): the Modify_monkey (Path,str (i)) - Run_monkey (path)Wuyi Print("execution Complete") the
Ii. automation of Push. APK and. So files
1 #Coding:utf-82 " "3 push script into the indoor machine and run4 5 " "6 ImportOS7 ImportRe8 Importsubprocess9 Ten #Execute Script One defpush_apk (path): Afilelist=os.listdir (path) -Cmd="adb remount" -P=subprocess. Popen (cmd,shell=True) the p.wait () - ifp.returncode!=0: - return-1 - forFileNameinchfilelist: +Filepath=Os.path.join (path,filename) -filename,extension=os.path.splitext (filename) + ifextension==". apk": A #print (". apk") atCmd="ADB push"+filepath+"/system/app" -P=subprocess. Popen (cmd,shell=True) - p.wait () - ifp.returncode!=0: - return-1 - ifextension==". so": in #print (". So") -Cmd="ADB push"+filepath+"/system/lib" toP=subprocess. Popen (cmd,shell=True) + p.wait () - ifp.returncode!=0: the return-1 *Cmd="adb reboot" $P=subprocess. Popen (cmd,shell=True)Panax Notoginseng p.wait () - ifp.returncode!=0: the return-1 + A if __name__=="__main__": thePath=r"C:\Users\Administrator\Desktop\pythoncmd\pushapk" + push_apk (path) - Print("execution complete, restarting") $
Test: Python invokes the cmd command to automate the push package