def adb_cmd_capture_msg_ext(self, cmdstr, time_out=None, callbk=None): """ Lightweight wrapper for adb command call. Return adb command line's message output parameter cmdstr is the command line string run in adb shell """ adbcmdstr = "%s shell %s" % (self.adb_prefix, cmdstr) LOG.debug('Execute adb command: %s' % adbcmdstr) _, out, _ = shell_command_ext(adbcmdstr, timeout=time_out, callbk=callbk) return out.strip('\r\n')
def dump_package(self, apk_path): assert os.path.isfile(apk_path), "%s is not a file" % (apk_path) class InfoParser(object): def __init__(self, msg): match = re.search(r"package:.* name='(.+?)'", msg, re.IGNORECASE) assert match, "Can't parse package name" self.packageName = match.group(1) match = re.search(r"package:.* versionCode='(.+?)'", msg, re.IGNORECASE) assert match, "Can't parse package versionCode" self.versionCode = match.group(1) match = re.search(r"package:.* versionName='(.+?)'", msg, re.IGNORECASE) assert match, "Can't parse package versionName" self.versionName = match.group(1) match = re.search(r"\nsdkversion:'(.+?)'", msg, re.IGNORECASE) assert match, "Can't parse package sdkversion" self.sdkVersion = match.group(1) match = re.search(r"targetSdkVersion:'(.+?)'", msg, re.IGNORECASE) assert match, "Can't parse package targetSdkVersion" self.targetSdkVersion = match.group(1) def __str__(self): attrs = vars(self) return ', '.join("%s: %s" % (k, v) for k, v in attrs.items()) cmd = "aapt dump badging %s" % (apk_path) LOG.debug('Execute command: %s' % cmd) ret, msg, errmsg = shell_command_ext(cmd) assert ret == 0, 'Failed dump package reason: %s' % (errmsg) return InfoParser(msg)
def shell_command(self, cmd): print 'Execute command: %s' % cmd exit_code, stdout_log, stderr_log = shell_command_ext(cmd) message = stdout_log + stderr_log print 'Result exit:%s\n%s' % (exit_code, message) return exit_code, message