import base64
import os
import tarfile
import gzip
import zipfile
# 对gz类型进行解压
def gzip_file(file):
c_path = file+"\\logcat_log.tar.gz"
try:
g = gzip.GzipFile(mode='rb',fileobj=open(c_path,'rb'))
open(c_path.replace('.gz',''),'wb').write(g.read())
except Exception as e:
print(e)
else:
untar(c_path.replace('.gz',''),file+'./',file)
#print('文件解压成功!')
def untar(fname,dirs,origin):
print("fname="+fname)
try:
t = tarfile.open(fname)
t.extractall(path=dirs)
except Exception as e:
print(e)
else:
#print('解压tar成功')
zip_allfile(origin+"\\log")
def zip_allfile(dirs):
for f in os.listdir(dirs):
if '.zip' in f:
zip_file = zipfile.ZipFile(dirs+"\\"+f)
zip_file.extract(zip_file.namelist()[0],dirs)
for f in os.listdir(dirs):
l_file = dirs+"\\"+f
with open(l_file, "r", encoding="utf-8" ,errors="ignore") as f:
for line in f:
#if 'fatal' in line:
#print(line)
#if 'died' in line:
#print(line)
if 'avc: denied' in line and 'toybox_vendor' not in line:
print(line)
if __name__ == "__main__":
#modify_name()
path = 'D:\\log分析\\xxx'
gzip_file(path)
一键解压文件
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 在最近的工作中,笔者遇到了一个问题。笔者从TCGA数据库中下载了全部癌症病人的whole genome的RNA-s...
- 压缩解压命令 毕竟Linux常用情况是字符界面,没有花花绿绿的软件供你使用,在这里你能使用的只有原汁原味的底层命令...
- 1.brew install unrar 2.unrar -version 3.进入需要解压的文件目录下,unra...
- 大致总结了一下linux下各种格式的压缩包的压缩、解压方法。但是部分方法我没有用到,也就不全,希望大家帮我补充,我...
- mac解压软件BetterZip解压文件乱码是什么原因?该怎么解决? 原因: BetterZip内置了自动编码检测...