def _get_device_ids(): """get tizen deivce list of ids""" result = [] exit_code, ret = shell_command("sdb start-server") exit_code, ret = shell_command("sdb devices") for line in ret: if str.find(line, "\tdevice") != -1: result.append(line.split("\t")[0]) return result
def get_device_info(self): """get tizen deivce inforamtion""" device_info = {} resolution_str = "" screen_size_str = "" device_model_str = "" device_name_str = "" build_id_str = "" os_version_str = "" # get resolution and screen size exit_code, ret = shell_command( "sdb -s %s shell xrandr" % self.deviceid) pattern = re.compile("connected (\d+)x(\d+).* (\d+mm) x (\d+mm)") for line in ret: match = pattern.search(line) if match: resolution_str = "%s x %s" % (match.group(1), match.group(2)) screen_size_str = "%s x %s" % (match.group(3), match.group(4)) # get architecture exit_code, ret = shell_command( "sdb -s %s shell uname -m" % self.deviceid) if len(ret) > 0: device_model_str = ret[0] # get hostname exit_code, ret = shell_command( "sdb -s %s shell uname -n" % self.deviceid) if len(ret) > 0: device_name_str = ret[0] # get os version exit_code, ret = shell_command( "sdb -s %s shell cat /etc/issue" % self.deviceid) for line in ret: if len(line) > 1: os_version_str = "%s %s" % (os_version_str, line) # get build id exit_code, ret = shell_command( "sdb -s %s shell cat /etc/os-release" % self.deviceid) for line in ret: if line.find("BUILD_ID=") != -1: build_id_str = line.split('=')[1].strip('\"\r\n') os_version_str = os_version_str[0:-1] device_info["device_id"] = self.deviceid device_info["resolution"] = resolution_str device_info["screen_size"] = screen_size_str device_info["device_model"] = device_model_str device_info["device_name"] = device_name_str device_info["os_version"] = os_version_str device_info["build_id"] = build_id_str return device_info
def kill_app(self, wgt_name): if self._wrt: cmdline = WRT_STOP_STR % (wgt_name) exit_code, ret = shell_command(cmdline) elif self._xwalk: cmd = APP_QUERY_STR % (wgt_name) exit_code, ret = shell_command(cmd) for line in ret: cmd = APP_KILL_STR % (line.strip('\r\n')) exit_code, ret = shell_command(cmd) return True
def launch_stub(self, stub_app, stub_port="8000", debug_opt=""): wgt_name = "testkit.stub/.TestkitStub" pkg_name = wgt_name.split('/')[0] cmdline = APP_STOP % (self.deviceid, pkg_name) exit_code, ret = shell_command(cmdline) cmdline = APP_START % (self.deviceid, wgt_name) debug_ext = " -e debug on" if debug_opt != "" else " -e debug off" port_ext = " -e port " + stub_port exit_code, ret = shell_command(cmdline + port_ext + debug_ext) time.sleep(2) return True
def kill_stub(self): #add this function to avoid webdriver issue, [email protected],2015.01.15 wgt_name = "testkit.stub/.TestkitStub" pkg_name = wgt_name.split('/')[0] cmdline = APP_STOP % (self.deviceid, pkg_name) exit_code, ret = shell_command(cmdline) cmd = "adb -s %s shell ps aux | grep testkit | grep -v grep| awk '{ print $2}'" ext_code, ret = shell_command(cmd) if exit_code ==0 and len(ret) > 0: cmd = "adb -s %s shell kill -9 %s" %(self.deviceid, ret[0].strip()) exit_code,ret = shell_command(cmd)
def start_debug(self, dlogfile): global debug_flag, metux debug_flag = True metux = threading.Lock() logcat_cmd = LOGCAT_CLEAR % self.deviceid exit_code, ret = shell_command(logcat_cmd) dmesg_cmd = DMESG_CLEAR % self.deviceid exit_code, ret = shell_command(logcat_cmd) logcat_cmd = LOGCAT_START % self.deviceid dmesg_cmd = DMESG_START % self.deviceid threading.Thread(target=debug_trace, args=(logcat_cmd, dlogfile+'.logcat')).start() threading.Thread(target=debug_trace, args=(dmesg_cmd, dlogfile+'.dmesg')).start()
def uninstall_package(self, pkgname): """install a package on android device: push package and install with shell command """ cmd = APK_UNINSTALL % (self.deviceid, pkgname) exit_code, ret = shell_command(cmd) return ret
def get_server_url(self, remote_port="8000"): """forward request a host tcp port to targe tcp port""" if remote_port is None: return None os.environ['no_proxy'] = LOCAL_HOST_NS host = LOCAL_HOST_NS inner_port = 9000 time_out = 2 bflag = False while True: sock_inner = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock_inner.settimeout(time_out) try: sock_inner.bind((host, inner_port)) sock_inner.close() bflag = False except socket.error as error: if error.errno == 98 or error.errno == 13: bflag = True if bflag: inner_port += 1 else: break host_port = str(inner_port) cmd = "adb -s %s forward tcp:%s tcp:%s" % \ (self.deviceid, host_port, remote_port) exit_code, ret = shell_command(cmd) url_forward = "http://%s:%s" % (host, host_port) return url_forward
def install_package(self, pkgpath): """ install a package on tizen device """ cmd = "rpm -ivh %s" % pkgpath exit_code, ret = shell_command(cmd) return ret
def _get_xwalk_app(self, test_suite, test_set, fuzzy_match, auto_iu): test_app_id = "" if auto_iu: test_wgt = test_set test_wgt_path = XWALK_LOCATION % (DEEPIN_USER, test_suite, test_wgt) if not self.install_app(test_wgt_path): LOGGER.info("[ failed to install widget \"%s\" in target ]" % test_wgt) return None else: test_wgt = test_suite arr = test_wgt.split('-') for item in arr: test_app_id += item test_wgt = test_app_id # check if widget installed already cmd = XWALK_QUERY_STR % (test_wgt) exit_code, ret = shell_command(cmd) if exit_code == -1: return None # for line in ret: # test_app_id = line.strip('\r\n') if test_app_id is None: LOGGER.info("[ test widget \"%s\" not found in target ]" % test_wgt) return None return test_app_id
def kill_stub(self): #add this function to avoid webdriver issue if stub exists running on device,[email protected] cmdline = APP_QUERY_STR % (self.deviceid, 'testkit-stub') exit_code, ret = shell_command(cmdline) if exit_code == 0 and len(ret) > 0: cmdline = "kill -9 %s" % ret[0] exit_code, ret = self.shell_cmd(cmdline)
def kill_stub(self): #add this function to avoid webdriver issue if stub runnning on device, [email protected] cmdline = APP_QUERY_STR % (self.deviceid, "testkit-stub") exit_code, ret_lines = shell_command(cmdline) if exit_code ==0 and len(ret_lines) > 0: cmdline = "kill -9 %s" %ret_lines[0] ret_lines = self._ssh.ssh_command(cmdline)
def install_package(self, pkgname): """ install a package on tizenivi device """ cmd = RPM_UNINSTALL % (self.deviceid, pkgname) exit_code, ret = shell_command(cmd) return ret
def install_package(self, pkgname): """ install a package on tizenpc device """ cmd = RPM_UNINSTALL % pkgname exit_code, ret = shell_command(cmd) return ret
def _get_xwalk_app(self, test_suite, test_set, fuzzy_match, auto_iu): test_app_id = None if auto_iu: test_wgt = test_set test_wgt_path = XWALK_LOCATION % (test_suite, test_wgt) if not self.install_app(test_wgt_path): LOGGER.info("[ failed to install widget \"%s\" in target ]" % test_wgt) return None else: test_wgt = test_suite # check if widget installed already cmd = XWALK_QUERY_STR % (self.deviceid, test_wgt) exit_code, ret = shell_command(cmd) if exit_code == -1: return None for line in ret: test_app_id = line.strip('\r\n') if test_app_id is None: LOGGER.info("[ test widget \"%s\" not found in target ]" % test_wgt) return None return test_app_id
def kill_stub(self): #add this function to avoid webdriver issue if stub exists running on device,[email protected] cmdline = APP_QUERY_STR % (self.deviceid, 'testkit-stub') exit_code, ret = shell_command(cmdline) if exit_code == 0 and len(ret) >0: cmdline = "kill -9 %s" %ret[0] exit_code, ret = self.shell_cmd(cmdline)
def install_package(self, pkgpath): """ install a package on tizenpc device """ cmd = RPM_INSTALL % pkgpath exit_code, ret = shell_command(cmd) return ret
def install_package(self, pkgpath): """ install a package on tizen device """ cmd = "dpkg -i %s" % pkgpath exit_code, ret = shell_command(cmd) return ret
def install_package(self, pkgpath): """install a package on tizen device: push package and install with shell command """ cmd = RPM_INSTALL % (self.deviceid, pkgpath) exit_code, ret = shell_command(cmd) return ret
def _get_wrt_app(self, test_suite, test_set, fuzzy_match, auto_iu): test_app_id = None if auto_iu: test_wgt = test_set test_wgt_path = WRT_LOCATION % (test_suite, test_wgt) if not self.install_app(test_wgt_path): LOGGER.info("[ failed to install widget \"%s\" in target ]" % test_wgt) return None else: test_wgt = test_suite # check if widget installed already cmd = WRT_QUERY_STR % (test_wgt) exit_code, ret = shell_command(cmd) if exit_code == -1: return None for line in ret: items = line.split(':') if len(items) < 1: continue if (fuzzy_match and items[0].find(test_wgt) != -1) or items[0] == test_wgt: test_app_id = items[1].strip('\r\n') break if test_app_id is None: LOGGER.info("[ test widget \"%s\" not found in target ]" % test_wgt) return None return test_app_id
def _get_xwalk_app(self, test_suite, test_set, fuzzy_match, auto_iu): test_app_id = None if auto_iu: test_wgt = test_set test_wgt_path = XWALK_LOCATION % (TIZEN_USER, test_suite, test_wgt) if not self.install_app(test_wgt_path): LOGGER.info("[ failed to install widget \"%s\" in target ]" % test_wgt) return None else: test_wgt = test_suite # check if widget installed already cmd = XWALK_QUERY_STR % (self.deviceid,TIZEN_USER, self.port, test_wgt) exit_code, ret = shell_command(cmd) if exit_code == -1: return None for line in ret: test_app_id = line.strip('\r\n') if test_app_id is None: LOGGER.info("[ test widget \"%s\" not found in target ]" % test_wgt) return None return test_app_id
def install_package(self, pkgpath): """ install a package on tizenivi device """ cmd = RPM_INSTALL % (self.deviceid, pkgpath) exit_code, ret = shell_command(cmd) return ret
def _get_wrt_app(self, test_suite, test_set, fuzzy_match, auto_iu): test_app_id = None if auto_iu: test_wgt = test_set test_wgt_path = WRT_LOCATION % (test_suite, test_wgt) if not self.install_app(test_wgt_path): LOGGER.info("[ failed to install widget \"%s\" in target ]" % test_wgt) return None else: test_wgt = test_suite # check if widget installed already cmd = WRT_QUERY_STR % (self.deviceid, test_wgt) exit_code, ret = shell_command(cmd) if exit_code == -1: return None for line in ret: items = line.split(':') if len(items) < 1: continue if (fuzzy_match and items[0].find(test_wgt) != -1) or items[0] == test_wgt: test_app_id = items[1].strip('\r\n') break if test_app_id is None: LOGGER.info("[ test widget \"%s\" not found in target ]" % test_wgt) return None return test_app_id
def uninstall_package(self, pkgname): """install a package on tizen device: push package and install with shell command """ cmd = RPM_UNINSTALL % (self.deviceid, pkgname) exit_code, ret = shell_command(cmd) return ret
def install_package(self, pkgpath): """install a package on android device: push package and install with shell command """ cmd = APK_INSTALL % (self.deviceid, pkgpath) exit_code, ret = shell_command(cmd) return ret
def get_server_url(self, remote_port="8000"): """forward request a host tcp port to targe tcp port""" if remote_port is None: return None os.environ['no_proxy'] = LOCAL_HOST_NS host = LOCAL_HOST_NS inner_port = 9000 time_out = 2 bflag = False while True: sock_inner = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock_inner.settimeout(time_out) try: sock_inner.bind((host, inner_port)) sock_inner.close() bflag = False except socket.error as error: if error.errno == 98 or error.errno == 13: bflag = True if bflag: inner_port += 1 else: break host_port = str(inner_port) cmd = "sdb -s %s forward tcp:%s tcp:%s" % \ (self.deviceid, host_port, remote_port) exit_code, ret = shell_command(cmd) url_forward = "http://%s:%s" % (host, host_port) return url_forward
def _get_device_ids(): """get android deivce list of ids""" result = [] exit_code, ret = shell_command("adb devices") for line in ret: if str.find(line, "\tdevice") != -1: result.append(line.split("\t")[0]) return result
def start_debug(self, dlogfile): global debug_flag, metux debug_flag = True metux = threading.Lock() cmdline = DLOG_CLEAR % self.deviceid exit_code, ret = shell_command(cmdline) cmdline = DLOG_WRT % self.deviceid threading.Thread(target=debug_trace, args=(cmdline, dlogfile+'.dlog')).start()
def install_app(self, wgt_path="", timeout=90): if self._wrt: cmd = WRT_INSTALL_STR % (wgt_path) elif self._xwalk: cmd = XWALK_INSTALL_STR % (wgt_path) else: return True exit_code, ret = shell_command(cmd, timeout) if exit_code == -1: cmd = APP_QUERY_STR % (wgt_path) exit_code, ret = shell_command(cmd) for line in ret: cmd = APP_KILL_STR % (line.strip('\r\n')) exit_code, ret = shell_command(cmd) return False else: return True
def install_app(self, wgt_path="", timeout=90): if self._wrt: cmd = WRT_INSTALL_STR % (self.deviceid, wgt_path) elif self._xwalk: cmd = XWALK_INSTALL_STR % (self.deviceid, wgt_path) else: return True exit_code, ret = shell_command(cmd, timeout) if exit_code == -1: cmd = APP_QUERY_STR % (self.deviceid, wgt_path) exit_code, ret = shell_command(cmd) for line in ret: cmd = APP_KILL_STR % (self.deviceid, line.strip('\r\n')) exit_code, ret = shell_command(cmd) return False else: return True
def uninstall_app(self, wgt_name): if self._wrt: cmd = WRT_UNINSTL_STR % (wgt_name) elif self._xwalk: cmd = XWALK_UNINSTL_STR % (wgt_name) else: return True exit_code, ret = shell_command(cmd) return True
def start_debug(self, dlogfile): global debug_flag, metux debug_flag = True metux = threading.Lock() cmdline = DLOG_CLEAR % self.deviceid exit_code, ret = shell_command(cmdline) cmdline = DLOG_WRT % self.deviceid threading.Thread(target=debug_trace, args=(cmdline, dlogfile + '.dlog')).start()
def uninstall_app(self, wgt_name): if self._wrt: cmd = WRT_UNINSTL_STR % (self.deviceid, wgt_name) elif self._xwalk: cmd = XWALK_UNINSTL_STR % (self.deviceid, TIZEN_USER, self.port, wgt_name) else: return True exit_code, ret = shell_command(cmd) return True
def download_file(self, remote_path, local_path): """download file""" local_path_dir = os.path.dirname(local_path) if not os.path.exists(local_path_dir): os.makedirs(local_path_dir) cmd = "scp %s:%s %s" % (self.deviceid, remote_path, local_path) exit_code, ret = shell_command(cmd) if not os.path.exists(local_path): return False return True
def launch_app(self, wgt_name, extension=None): blauched = False if wgt_name.find('xwalk') != -1: timecnt = 0 blauched = False pkg_name, actv_name = wgt_name.split('/') actv_name = actv_name.strip('.') origin_active_name = actv_name cmdline = APP_STOP % (self.deviceid, pkg_name) exit_code, ret = shell_command(cmdline) # cmdline = APP_START % (self.deviceid, wgt_name) # exit_code, ret = shell_command(cmdline) if self.launcher == "CordovaLauncher": # remove Activity to retry actv_name = actv_name.replace('Activity', '') LOGGER.info("[ Try to launch app: %s ]" % (pkg_name + '/.' + actv_name)) cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name) exit_code, ret = shell_command(cmdline) else: # use capitalize to retry actv_name = actv_name.replace('Activity', '') tmps = actv_name.split('_') actv_name = ''.join([it.capitalize() for it in tmps if it]) LOGGER.info("[ Try to launch app: %s ]" % (pkg_name + '/.' + actv_name + 'Activity')) cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name + 'Activity') exit_code, ret = shell_command(cmdline) if len(ret) > 1: # remove Activity LOGGER.info("[ Retry to launch app: %s ]" % (pkg_name + '/.' + actv_name)) cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name) exit_code, ret = shell_command(cmdline) if len(ret) > 1: actv_name = origin_active_name.capitalize().replace( "activity", "Activity") LOGGER.info("[ Try to launch app: %s ]" % (pkg_name + '/.' + actv_name)) cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name) exit_code, ret = shell_command(cmdline) blauched = True time.sleep(3) else: cmdline = APP_NONBLOCK_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmdline) time.sleep(3) cmd = APP_QUERY_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmd) if ret and len(ret): blauched = True return blauched
def install_app(self, wgt_path="", timeout=90): if self._wrt: cmd = WRT_INSTALL_STR % (self.deviceid, wgt_path) elif self._xwalk: if len(wgt_path)>0: ext = wgt_path.split('.')[1] cmd = XWALK_INSTALL_STR % (self.deviceid,TIZEN_USER, self.port,ext, wgt_path) else: return True exit_code, ret = shell_command(cmd, timeout) if exit_code == -1: cmd = APP_QUERY_STR % (self.deviceid, wgt_path) exit_code, ret = shell_command(cmd) for line in ret: cmd = APP_KILL_STR % (self.deviceid, line.strip('\r\n')) exit_code, ret = shell_command(cmd) return False else: return True
def get_user_id(self): if TIZEN_USER == 'app': self.port = '5000' else: cmdline = XWALK_QUERY_ID % (self.deviceid, TIZEN_USER) exit_code, ret = shell_command(cmdline) if exit_code == -1: LOGGER.info("[ can not get user id ]") if len(ret) > 0: self.port = ret[0].strip('\r\n')
def _get_user_id(self): if TIZEN_USER.lower() == 'app': self.port = '5000' else: cmdline = XWALK_QUERY_ID % (self.deviceid, TIZEN_USER) exit_code, ret = shell_command(cmdline) if exit_code == -1: LOGGER.info("[ can not get user id ]") if len(ret) > 0 : self.port = ret[0].strip('\r\n')
def download_file(self, remote_path, local_path): """download file from device""" cmd = "adb -s %s pull %s %s" % (self.deviceid, remote_path, local_path) exit_code, ret = shell_command(cmd) if exit_code != 0: error = ret[0].strip('\r\n') if len(ret) else "sdb shell timeout" LOGGER.info("[ Download file \"%s\" failed, error: %s ]" % (remote_path, error)) return False else: return True
def upload_file(self, remote_path, local_path): """upload file to device""" cmd = "sdb -s %s push %s %s" % (self.deviceid, local_path, remote_path) exit_code, ret = shell_command(cmd) if exit_code != 0: error = ret[0].strip('\r\n') if len(ret) else "sdb shell timeout" LOGGER.info("[ Upload file \"%s\" failed," " get error: %s ]" % (local_path, error)) return False else: return True
def launch_stub(self, stub_app, stub_port="8000", debug_opt=""): # self.kill_stub() wgt_name = "testkit.stub/.TestkitStub" # pkg_name = wgt_name.split('/')[0] # cmdline = APP_STOP % (self.deviceid, pkg_name) # exit_code, ret = shell_command(cmdline) cmdline = APP_START % (self.deviceid, wgt_name) debug_ext = " -e debug on" if debug_opt != "" else " -e debug off" port_ext = " -e port " + stub_port exit_code, ret = shell_command(cmdline + port_ext + debug_ext) time.sleep(2) return True
def launch_app(self, wgt_name): blauched = False if self._wrt: timecnt = 0 cmdline = WRT_STOP_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmdline) cmdline = WRT_START_STR % (self.deviceid, wgt_name) while timecnt < 3: exit_code, ret_out, ret_err = shell_command_ext(cmdline, 30) if exit_code == "0": blauched = True break timecnt += 1 time.sleep(3) elif self._xwalk: cmd = APP_QUERY_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmd) for line in ret: cmd = APP_KILL_STR % (self.deviceid, line.strip('\r\n')) exit_code, ret = shell_command(cmd) cmdline = XWALK_START_STR % (self.deviceid, TIZEN_USER, self.port, XWALK_MAIN, wgt_name) exit_code, ret = shell_command(cmdline) time.sleep(3) blauched = True else: cmdline = APP_NONBLOCK_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmdline) time.sleep(3) cmd = APP_QUERY_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmd) if ret and len(ret): blauched = True return blauched
def launch_app(self, wgt_name): blauched = False if self._wrt: timecnt = 0 cmdline = WRT_STOP_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmdline) cmdline = WRT_START_STR % (self.deviceid, wgt_name) while timecnt < 3: exit_code, ret_out, ret_err = shell_command_ext(cmdline, 30) if exit_code == "0": blauched = True break timecnt += 1 time.sleep(3) elif self._xwalk: cmd = APP_QUERY_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmd) for line in ret: cmd = APP_KILL_STR % (self.deviceid, line.strip('\r\n')) exit_code, ret = shell_command(cmd) cmdline = XWALK_START_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmdline) time.sleep(3) blauched = True else: cmdline = APP_NONBLOCK_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmdline) time.sleep(3) cmd = APP_QUERY_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmd) if ret and len(ret): blauched = True return blauched
def launch_app(self, wgt_name, extension=None): blauched = False if wgt_name.find('xwalk') != -1: timecnt = 0 blauched = False pkg_name, actv_name = wgt_name.split('/') actv_name = actv_name.strip('.') origin_active_name = actv_name cmdline = APP_STOP % (self.deviceid, pkg_name) exit_code, ret = shell_command(cmdline) # cmdline = APP_START % (self.deviceid, wgt_name) # exit_code, ret = shell_command(cmdline) if self.launcher == "CordovaLauncher" : # remove Activity to retry actv_name = actv_name.replace('Activity', '') LOGGER.info("[ Try to launch app: %s ]" % (pkg_name + '/.' + actv_name)) cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name) exit_code, ret = shell_command(cmdline) else: # use capitalize to retry actv_name = actv_name.replace('Activity', '') tmps = actv_name.split('_') actv_name = ''.join([it.capitalize() for it in tmps if it]) LOGGER.info("[ Try to launch app: %s ]" % (pkg_name + '/.' + actv_name + 'Activity')) cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name + 'Activity') exit_code, ret = shell_command(cmdline) if len(ret) > 1: # remove Activity LOGGER.info("[ Retry to launch app: %s ]" % (pkg_name + '/.' + actv_name)) cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name) exit_code, ret = shell_command(cmdline) if len(ret) > 1: actv_name = origin_active_name.capitalize().replace("activity", "Activity") LOGGER.info("[ Try to launch app: %s ]" % (pkg_name + '/.' + actv_name)) cmdline = APP_START % (self.deviceid, pkg_name + '/.' + actv_name) exit_code, ret = shell_command(cmdline) blauched = True time.sleep(3) else: cmdline = APP_NONBLOCK_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmdline) time.sleep(3) cmd = APP_QUERY_STR % (self.deviceid, wgt_name) exit_code, ret = shell_command(cmd) if ret and len(ret): blauched = True return blauched
def launch_app(self, wgt_name, extension=None): cmd = EXPORT_DEEPIN %(DEEPIN_USER) shell_command(cmd) blauched = False if self._wrt: timecnt = 0 cmdline = WRT_STOP_STR % (wgt_name) exit_code, ret = shell_command(cmdline) cmdline = WRT_START_STR % (wgt_name) while timecnt < 3: exit_code, ret_out, ret_err = shell_command_ext(cmdline, 30) if exit_code == "0": blauched = True break timecnt += 1 time.sleep(3) elif self._xwalk: cmd = APP_QUERY_STR % (wgt_name) exit_code, ret = shell_command(cmd) for line in ret: cmd = APP_KILL_STR % (line.strip('\r\n')) exit_code, ret = shell_command(cmd) execute_file = commands.getoutput("which %s" % wgt_name) real_file = REALPATH(execute_file) parent_dir = DIRNAME(real_file) manifest_file = JOIN(parent_dir, "www/manifest.json") cmdline = "xwalk %s &" % manifest_file if os.environ.has_key("DEEPIN_CODEC_LIB"): cmdline = "xwalk %s --proprietary-codec-lib-path=%s &" % (manifest_file, os.environ["DEEPIN_CODEC_LIB"]) exit_code, ret = shell_command(cmdline) time.sleep(3) blauched = True else: cmdline = APP_NONBLOCK_STR % (wgt_name) exit_code, ret = shell_command(cmdline) time.sleep(3) cmd = APP_QUERY_STR % (wgt_name) exit_code, ret = shell_command(cmd) if ret and len(ret): blauched = True return blauched
def download_file(self, remote_path, local_path): """download file from device""" local_path_dir = os.path.dirname(local_path) if not os.path.exists(local_path_dir): os.makedirs(local_path_dir) filename = os.path.basename(remote_path) cmd = "sdb -s %s pull %s %s" % ( self.deviceid, remote_path, local_path_dir) exit_code, ret = shell_command(cmd) if exit_code != 0: error = ret[0].strip('\r\n') if len(ret) else "sdb shell timeout" LOGGER.info("[ Download file \"%s\" failed, error: %s ]" % (remote_path, error)) return False else: src_path = os.path.join(local_path_dir, filename) if src_path != local_path: shutil.move(src_path, local_path) return True
def download_file(self, remote_path, local_path): """download file from device""" local_path_dir = os.path.dirname(local_path) if not os.path.exists(local_path_dir): os.makedirs(local_path_dir) filename = os.path.basename(remote_path) cmd = "sdb -s %s pull %s %s" % (self.deviceid, remote_path, local_path_dir) exit_code, ret = shell_command(cmd) if exit_code != 0: error = ret[0].strip('\r\n') if len(ret) else "sdb shell timeout" LOGGER.info("[ Download file \"%s\" failed, error: %s ]" % (remote_path, error)) return False else: src_path = os.path.join(local_path_dir, filename) if src_path != local_path: shutil.move(src_path, local_path) return True
def get_installed_package(self): """get list of installed package from device""" cmd = RPM_LIST % self.deviceid exit_code, ret = shell_command(cmd) return ret
def check_process(self, process_name): exit_code, ret = shell_command(APP_QUERY_STR % (self.deviceid, process_name)) return len(ret)
def shell_cmd(self, cmd="", timeout=15): cmdline = SDB_COMMAND % (self.deviceid, cmd) #print "cmdline : " , cmdline return shell_command(cmdline, timeout)
def get_installed_package(self): """get list of installed package from device""" cmd = "dpkg -l | awk '{ print $2 }'" exit_code, ret = shell_command(cmd) return ret