def set_conf(self, conFile=monkeyConfFile): deviceString = "" if os.path.exists(conFile): with open(conFile, "r") as f: lines = f.readlines() for line in lines: if "deviceList" in line: deviceString = line break with open(conFile, "w") as f: f.write("") if deviceString != "": with open(conFile, "a+") as f: f.write("[Monkey]" + "\n") f.write(deviceString) # self._set_eventPercent(conFile) self._set_eventType(conFile) if self._set_times(conFile) == 1: common.showDialog( "Message", static.dialogSetTime + ", " + static.dialogTimeLong) if conFile != monkeyConfFile: os.remove(conFile) return 1 else: # if conFile == monkeyConfFile: # common.showDialog("Message", static.dialogStorDefaultConf) # else: # common.showDialog("Message", static.dialogStoreNewFile) return 0
def storOrNot(self): with open(monkeyConfFile, 'r') as f: lines = f.read() try: if str(lines.split("--throttle = ")[1].split("\n")[0]) != self.etSet.item(0, 1).text(): common.showDialog("Message", static.dialogNotSave) return True if int(self.etPercent.item(0, 1).text()) != 0: if str(lines.split("touch = ")[1].split("\n")[0]) != self.etPercent.item(0, 1).text(): common.showDialog("Message", static.dialogNotSave) return True if int(self.etPercent.item(1, 1).text()) != 0: if str(lines.split("motion = ")[1].split("\n")[0]) != self.etPercent.item(1, 1).text(): common.showDialog("Message", static.dialogNotSave) return True if "times" in lines: hours = self.timeLong.text() secsTime = int(float(hours) * 60 * 60) dlay = int(self.etSet.item(0, 1).text()) times = str(secsTime * 1000 / (dlay * 2)) if str(lines.split("times = ")[1].split("\n")[0]) != times: common.showDialog("Message", static.dialogNotSave) return True else: common.showDialog("Message", static.dialogNotSave) except Exception as e: common.Log.error(e.message) return True return False
def check(self): resultFile = os.path.join(DIR, "Result", self.logfile.currentText(), "Result.html") if os.path.exists(resultFile): self.getResult = result.ThreadGetResult() self.getResult.setup(resultFile) self.getResult.start() else: common.showDialog("information", static.dialogNoHtml)
def start(self): self.set_conf() global deviceList if self.storOrNot(): return # self.set_conf(monkeyConfFile) common.exitFlag = False common.monkeyLogClose = False try: if self.device.item(0, 1).text() == "Connected": try: if float(self.timeLong.text()) > 0: time_data = time.strftime('%Y%m%d%H%M%S', time.localtime()) self.result_path = os.path.join( os.getcwd(), 'Result', time_data) try: self.startButton.setIcon(QIcon(static.runPNG)) # deviceobj = device.Device(app_type) # deviceList = deviceobj.get_android_devices() self._set_device() cf = ConfigParser.ConfigParser() cf.read(monkeyConfFile) deviceList = yaml.load( cf.get('Monkey', 'deviceList')) flag = 1 self.run = runner.Runner(self.result_path, flag) self.run.start(deviceList) self.startTime = datetime.datetime.now() except Exception as e: common.Log.error(e.message) common.Log.error("run error") common.Log.info("start to run monkey") try: self.log_show() except: common.Log.error("log show error") self.logfile.insertItem(0, time_data) self.logfile.setCurrentIndex(0) else: common.showDialog("Message", static.dialogTimeLong) except: common.showDialog("Message", static.dialogNoTime) else: common.showDialog("Message", static.dialogUnready) except: common.showDialog("Message", static.dialogNoDevice)
def about(self): common.showDialog(static.menuAbout, static.dialogAbout)