将压缩日志解压并根据关键字取出对应的日志行python

######################################################
#file_name : gather check
#
#function target: gather file error select
#
#author:  zL
#time  :  2018/04
#flow  :  get porcess path       || (tar_file_analysis)
#      :  unprocess file         || (un_cab, un_tar)
#      :  vol gather file check  || (vogather_check)
#      :  get error line         || (target_file_analysis, get_error_line)
#      :   agent lrt ensure      ||  ()
#######################################################

#import rarfile
#import pandas
import os
#import time

#import sys
#import importlib
#importlib.reload(sys)
#reload(sys)
#sys.setdefaultencoding('utf8')
#importlib.setdefaultencoding('utf8')

#save CAB file
tarZ_path = []
tarZ_name = []
CAB_path = []
CAB_name = []
bz2_path = []
bz2_name = []


#add filename here
trace_file = ["aPP_Log.log", "aPPmaind.trc"]
trace_file.append("aPPmsgdd.trc");

#add check key worlds here
key_world = ["error", "warning"]#, "aPPwebd start", "aPPmaind", "aPPsvr start"
ignore_world = ["error=0", "errno=<2>", "errno=<16>"]
trace_path = []


#flag 
result_file_flag = 1  # start

#######################################
#funtion: check if path exists
#in:      dir
#out:     1: exists  do nothing
#         0: not exists, mkdir
#######################################
def zl_WinRAR(file, path):
    if os.path.exists("C:\Program Files\WinRAR\WinRAR.exe"):
        cmd = "\"C:\Program Files\WinRAR\WinRAR.exe\" x " + file + " " + path
    elif os.path.exists("C:\Program Files (x86)\WinRAR\WinRAR.exe"):
        cmd = "\"C:\Program Files (x86)\WinRAR\WinRAR.exe\" x " + file + " " + path
    else:
        print("There is no WinRAR in your computer!\n")
        exit(0)
    os.system(cmd)


#######################################
#funtion: check if path exists
#in:      dir
#out:     1: exists  do nothing
#         0: not exists, mkdir
#######################################
def zl_mkdir(dir):
    if os.path.isdir(dir):
        return 1
    else:
        os.mkdir(dir)
        return 0

#######################################
#funtion: check it is targetfile
#in:      filename
#out:     yes/no
#######################################
def isTargetFile(filename):
    for value in trace_file:
        if filename == value:
            return 1
    return 0

#######################################
#funtion: get compress file path and name
#in:      now dir
#out:     NULL
#######################################
def tar_file_analysis(file_dir):<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值