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

相关文章

Pandas 合并多个Dataframe(merge,concat)的方法

在数据处理的时候,尤其在搞大数据竞赛的时候经常会遇到一个问题就是,多个表单的合并问题,比如一个表单有user_id和age这两个字段,另一个表单有user_id和sex这两个字段,要把这...

如何用itertools解决无序排列组合的问题

最近我作为Python菜鸟一枚开始征战Codewars,所以打算在这里记下遇到的有意思的题目。今天这第一题叫做“Best Travel”: John和Mary计划去一些小镇旅行。Mary...

在Python中操作时间之tzset()方法的使用教程

 tzset()方法重置所使用的库例程的时间转换规则。环境变量TZ指定如何完成此操作。 TZ环境变量的标准格式(空格为清楚起见而加的): 复制代码 代码如下:std offse...

Python实现八大排序算法

如何用Python实现八大排序算法 1、插入排序 描述 插入排序的基本操作就是将一个数据插入到已经排好序的有序数据中,从而得到一个新的、个数加一的有序数据,算法适用于少量数据的排序,时间...

Python 实现异步调用函数的示例讲解

async_call.py #coding:utf-8 from threading import Thread def async_call(fn): def wrapper...