python使用7z解压apk包的方法

yipeiwu_com5年前Python基础

本文实例讲述了python使用7z解压apk包的方法。分享给大家供大家参考。具体如下:

这段代码通过shell调用7z对apk包进行解压缩

def run_shell(command, mayFreeze=False):
 def check_retcode(retcode, cmd):
 if 0 != retcode:
 print >> sys.stderr, 'err executing ' + cmd + ':', retcode
 sys.exit(retcode)
 def read_close(f):
 f.seek(0)
 d = f.read()
 f.close()
 return d
 #print >> sys.stderr, '-- Executing', command
 if mayFreeze:
 tempout, temperr = tempfile.TemporaryFile(), tempfile.TemporaryFile()
 #open(os.devnull, 'w')
 p = subprocess.Popen(command, stdout=tempout, stderr=temperr)
 p.wait()
 output, errout = read_close(tempout), read_close(temperr)
 else:
 p=subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
 output = p.stdout.read()
 p.wait()
 errout = p.stderr.read()
 p.stdout.close()
 p.stderr.close()
 #check_retcode(p.returncode, command)
 return (output.strip(), errout.strip())
#z7 is the full path to 7z.exe
#at times you have to encode the command into GBK/UTF8
run_shell(u'{0} -y -o"{1}" {2} x "{3}"'.format(z7, tempdir, icon, apk))
shutil.copy(u'{0}/{1}'.format(tempdir,os.path.basename(icon)),dst_path)

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python素数检测实例分析

本文实例讲述了Python素数检测的方法。分享给大家供大家参考。具体如下: 该程序实现了素数检测器功能,如果结果是true,则是素数,如果结果是false,则不是素数。 def fn...

python实现植物大战僵尸游戏实例代码

python实现植物大战僵尸游戏实例代码

开发思路 完整项目地址:https://github.com/371854496/... 觉得还OK的话,点下Star,作者不易,thank you! 实现方法 1.引入需要的模...

详解python中 os._exit() 和 sys.exit(), exit(0)和exit(1) 的用法和区别

详解python中 os._exit() 和 sys.exit(), exit(0)和exit(1) 的用法和区别 os._exit() 和 sys.exit() os._exit()...

pycharm使用matplotlib.pyplot不显示图形的解决方法

如下案例,可以正常保存图像,但是plt.show()不能正常显示图像,这里是使用pandas模块读取csv文件: # coding=utf-8 import pandas as pd...

python3调用windows dos命令的例子

最近游戏项目在多个国家上线,每个国家都对应两份儿svn目录(一份是本地策划目录,一份是线上目录)。于是乎维护变得很烦躁。需要先更新本地策划svn目录,然后把更新的文件拷贝到对应的线上目录...