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

相关文章

Python3显示当前时间、计算时间差及时间加减法示例代码

Python3显示当前时间、计算时间差及时间加减法示例代码

摘要 在使用Python写程序时,经常需要输出系统的当前时间以及计算两个时间之间的差值,或者将当前时间加减一定时间(天数、小时、分钟、秒)来得到新的时间,这篇文章就系统的对这些进行总结...

Python的动态重新封装的教程

让我们描绘一下本文的情节:假设您要在本地机器上运行一个进程,而部分程序逻辑却在另一处。让我们特别假设这个程序逻辑会不时更新, 而您运行进程时,希望使用最新的程序逻辑。有许多方法可以满足刚...

基于Python的身份证号码自动生成程序

基于Python的身份证号码自动生成程序

需求细化: 1.身份证必须能够通过身份证校验程序。 2.通过查询,发现身份证号码是有国家标准的,标准号为 GB 11643-1999 可以从百度下载到这个文档 下载:GB11643-19...

Python处理JSON数据并生成条形图

Python处理JSON数据并生成条形图

一、JSON 数据准备 首先准备一份 JSON 数据,这份数据共有 3560 条内容,每条内容结构如下: 本示例主要是以 tz(timezone 时区) 这一字段的值,分析这份数据里时...

python读取文本中数据并转化为DataFrame的实例

python读取文本中数据并转化为DataFrame的实例

在技术问答中看到一个这样的问题,感觉相对比较常见,就单开一篇文章写下来。 从纯文本格式文件 “file_in”中读取数据,格式如下: 需要输出成“file_out”,格式如下: 数据...