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 3

引言 如今 Python 成为机器学习和大量使用数据操作的科学领域的主流语言; 它拥有各种深度学习框架和完善的数据处理和可视化工具。但是,Python 生态系统在 Python2 和 P...

Django学习笔记之为Model添加Action

在使用Django自带的admin后台的时候,他提供了一些默认的指令可以对数据进行操作, 比如批量删除,修改等 同样的我们也可以添加自己的指令。 |- Django版本:1.8 |- P...

浅谈Python黑帽子取代netcat

浅谈Python黑帽子取代netcat

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

Python单链表简单实现代码

本文实例讲述了Python单链表简单实现代码。分享给大家供大家参考,具体如下: 用Python模拟一下单链表,比较简单,初学者可以参考参考 #coding:utf-8 class N...

python多线程案例之多任务copy文件完整实例

python多线程案例之多任务copy文件完整实例

本文实例讲述了python多线程案例之多任务copy文件。分享给大家供大家参考,具体如下: import os import multiprocessing def copy_fil...