def doScreenCap(self, deviceModel=None, callBack=None): screenPath = '/sdcard/screenshot_' if deviceModel: screenPath += deviceModel + "_" screenPath += str(DateUtil().getCurrentTimeStamp()) + ".png" destPath = "d:" + os.sep + "adbTools" + os.sep FileUtil.mkdirNotExist(destPath) cmd = str('%s -s %s shell /system/bin/screencap -p %s ' % (adbCmd, self.getCurrentSerialNo(), screenPath)) result = self._runSysCmd.run(cmd, should_process=False).stdout.read() if 'not found' in result: if callBack: callBack(_fromUtf8("未获取到设备, 请检查USB连接~")) return result cmd2 = str('%s -s %s pull %s %s' % (adbCmd, self.getCurrentSerialNo(), screenPath, destPath)) callBack(_fromUtf8("正在截屏操作, 请稍后..")) result = self._runSysCmd.run(cmd2, should_process=False).stdout.read() if "file pulled" in result: # os.startfile('d:\\adbTools') self._runSysCmd.run(['explorer.exe', destPath]) if callBack: strTmp = "已完成截屏, 保存地址为: %s" % (destPath + FileUtil.getFileName(screenPath)) callBack(_fromUtf8(strTmp)) return result
def unRegisterBootUp(self): if FileUtil.getFileName(self.exePath) == "python.exe": return try: key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, self.bootUpkey, 0, win32con.KEY_ALL_ACCESS) # self.name 是值的名称 win32api.RegDeleteValue(key, self.name) win32api.RegCloseKey(key) print 'unRegister boot success!' except: print 'unRegister boot up key error !'
def registerBootUp(self): if FileUtil.getFileName(self.exePath) == "python.exe": return try: key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, self.bootUpkey, 0, win32con.KEY_ALL_ACCESS) win32api.RegSetValueEx(key, self.name, 0, win32con.REG_SZ, self.exePath) win32api.RegCloseKey(key) print 'register boot success!' except: print 'register boot up key error !'
def doStopScreenRecord(self, callBack=None): if not self._lastScreenRecordPath: if callBack: callBack(_fromUtf8("请先进行录屏操作~")) return None recordPath = self._lastScreenRecordPath destPath = "d:" + os.sep + "adbTools" + os.sep FileUtil.mkdirNotExist(destPath) recordPidCmd = str('%s -s %s shell ps | %s screenrecord' % (adbCmd, self.getCurrentSerialNo(), findCmd)) recordPidResult = self._runSysCmd.run( recordPidCmd, should_process=False).stdout.read() # print 'recordRe: ', recordPidResult if 'not found' in recordPidResult: if callBack: callBack(_fromUtf8("未获取到设备, 请检查USB连接~")) return recordPidResult reRecordPidStr = r'[0-9]+' recordPid = re.findall(reRecordPidStr, recordPidResult)[0] # print 'recordPid: ', recordPid killScreenRecordCmd = str( '%s -s %s shell kill -2 %s' % (adbCmd, self.getCurrentSerialNo(), recordPid)) self._runSysCmd.run(killScreenRecordCmd, should_process=False).stdout.read() cmd = str('%s -s %s pull %s %s' % (adbCmd, self.getCurrentSerialNo(), recordPath, destPath)) result = self._runSysCmd.run(cmd, should_process=False).stdout.read() if "file pulled" in result: # os.startfile('d:\\adbTools') self._runSysCmd.run(['explorer.exe', destPath]) if callBack: strTmp = "已完成录屏, 保存地址为: %s" % ( destPath + FileUtil.getFileName(self._lastScreenRecordPath)) callBack(_fromUtf8(strTmp)) return result