text stringlengths 1 93.6k |
|---|
def restore(device: Device, dir_path: str, root: str):
|
log.info("开始恢复...")
|
os.chdir(dir_path)
|
all_file = os.listdir(dir_path)
|
obb = False
|
for i in all_file:
|
if i.endswith(".obb"):
|
obb = True
|
break
|
if obb:
|
for i in all_file:
|
if i.endswith(".apk"):
|
install_apk(device, os.path.join(dir_path, i), [], root)
|
elif i.endswith(".obb"):
|
push = ["push", os.path.join(dir_path, i),
|
"/storage/emulated/0/Android/obb/"+os.path.split(dir_path)[-1]]
|
device.adb(push)
|
else:
|
if len(all_file) == 0:
|
sys.exit("备份文件夹为空!")
|
elif len(all_file) == 1:
|
main(root, all_file[0])
|
elif len(all_file) > 1:
|
install = ["install-multiple", "-rtd"]
|
install.extend(all_file)
|
install_multiple(device, install)
|
os.chdir(root)
|
def run_msg(cmd: Union[str, List[str]]):
|
log.debug(cmd)
|
if type(cmd) is str:
|
cmd = shlex_split(cmd)
|
run = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
if run.stderr:
|
return run, tostr(run.stderr)
|
if run.stdout:
|
return run, tostr(run.stdout)
|
return run, str()
|
def uninstall(device: Device, package_name: str, root: str):
|
dir_path = pull_apk(device, package_name, root)
|
if not dir_path:
|
sys.exit("备份文件时出现错误")
|
# adb uninstall package_name
|
# 卸载应用时尝试保留应用数据和缓存数据,但是这样处理后只能先安装相同包名的软件再正常卸载才能清除数据!!
|
log.info("开始卸载...")
|
run = device.shell(["pm", "uninstall", "-k", package_name])[0]
|
try:
|
if run.returncode:
|
restore(device, dir_path, root)
|
except Exception:
|
log.exception('Failed in uninstall->restore.')
|
sys.exit(f"恢复时出现未知错误!请尝试手动操作并反馈该问题!旧版安装包路径:{dir_path}")
|
return run
|
def unpack(file: str) -> str:
|
"""解压文件"""
|
unpack_path = get_unpack_path(file)
|
log.info("文件越大,解压越慢,请耐心等待...")
|
shutil.unpack_archive(file, unpack_path, "zip")
|
return unpack_path
|
if __name__ == "__main__":
|
argv = sys.argv
|
if len(argv) < 2 or (len(argv) == 2 and '-l' in argv):
|
print("缺少参数!")
|
print("xapkInstaller <filepath or dirpath>")
|
print("例如:")
|
print(" xapkInstaller abc.aab")
|
print(" xapkInstaller abc.apk")
|
print(" xapkInstaller ./abc/")
|
print(" xapkInstaller abc.apkm abc.apks abc.xapk ./abc/")
|
pause()
|
if '-l' in argv:
|
argv.remove('-l')
|
else:
|
logging.disable(logging.DEBUG)
|
logging.disable(logging.INFO)
|
logging.disable(logging.WARNING)
|
'''
|
logging.disable(logging.ERROR)
|
logging.disable(logging.CRITICAL)
|
'''
|
rootdir = os.path.split(argv[0])[0]
|
if not rootdir:
|
rootdir = os.getcwd()
|
_len_ = len(argv[1:])
|
success = 0
|
try:
|
for _i, _one in enumerate(argv[1:]):
|
log.info(f"正在安装第{_i+1}/{_len_}个...")
|
log.info(str(_one)+' start')
|
if main(rootdir, _one):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.