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

yipeiwu_com6年前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 for Informatics 第11章之正则表达式(二)

注:以下文章原文来自于Dr Charles Severance 的 《Python for Informatics》 11.1 正则表达式的字符匹配   我们可以用许多其它的特殊字符...

初探TensorFLow从文件读取图片的四种方式

本文记录一下TensorFLow的几种图片读取方法,官方文档有较为全面的介绍。 1.使用gfile读图片,decode输出是Tensor,eval后是ndarray import...

docker django无法访问redis容器的解决方法

docker django无法访问redis容器的解决方法

docker-compose.yal文件中: redis: image: redis container_name: xdemo.redis ports: - 6...

使用Python进行新浪微博的mid和url互相转换实例(10进制和62进制互算)

不过,status中包含了一个mid字段,通过mid,我们实际上是可以通过计算得到url的。 在开始计算之前有必要说明一下,什么是base62编码。它实际上就是十进制和62位进制的互换。...

python使用RNN实现文本分类

python使用RNN实现文本分类

本文实例为大家分享了使用RNN进行文本分类,python代码实现,供大家参考,具体内容如下 1、本博客项目由来是oxford 的nlp 深度学习课程第三周作业,作业要求使用LSTM进行...