美文网首页
一键解压文件

一键解压文件

作者: 西厌西厌 | 来源:发表于2023-02-19 17:27 被阅读0次
    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分析\\hx11_dhu_simplelog_20230209155259'
        gzip_file(path)
    

    相关文章

      网友评论

          本文标题:一键解压文件

          本文链接:https://www.haomeiwen.com/subject/xdjogktx.html