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程序设计有所帮助。

相关文章

wxpython学习笔记(推荐查看)

一、简介 wxPython是Python编程语言的一个GUI工具箱。他使得Python程序员能够轻松的创建具有健壮、功能强大的图形用户界面的程序。它是Python语言对流行的wxWid...

Django自定义分页与bootstrap分页结合

Django自定义分页与bootstrap分页结合

django中有自带的分页模块Paginator,想Paginator提供对象的列表,就可以提供每一页上对象的方法。 这里的话不讲解Paginator,而是自定义一个分页类来完成需求:...

Python基于OpenCV库Adaboost实现人脸识别功能详解

Python基于OpenCV库Adaboost实现人脸识别功能详解

本文实例讲述了Python基于OpenCV库Adaboost实现人脸识别功能。分享给大家供大家参考,具体如下: 以前用Matlab写神经网络的面部眼镜识别算法,研究算法逻辑,采集大量训练...

Python MySQLdb模块连接操作mysql数据库实例

mysql是一个优秀的开源数据库,它现在的应用非常的广泛,因此很有必要简单的介绍一下用python操作mysql数据库的方法。python操作数据库需要安装一个第三方的模块,在http:...

浅谈Python黑帽子取代netcat

浅谈Python黑帽子取代netcat

按照各位大佬的博客来,端口连接的命令始终连接不上。 后来问了同学,在开了监听之后: 使用书上的代码连接不能成功,连接的命令改成:nc www.baidu.com 80(同理 监听本地就...