-
Notifications
You must be signed in to change notification settings - Fork 1
/
elogsplit.py
59 lines (46 loc) · 1.32 KB
/
elogsplit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import sys
import logging
from base import *
from elogreorder import *
def parse_module_name( fileName ):
idx = fileName.rfind( '.' )
mname = fileName
if idx > 0:
mname = fileName[0:idx]
if mname.endswith( '000' ):
return None
if mname.endswith( 'errorlog' ):
tail = len(mname) - len('errorlog')
mname = mname[0:tail]
elif mname.endswith( 'err' ):
tail = len(mname) - len('err')
mname = mname[0:tail]
elif mname.endswith( 'log' ):
tail = len(mname) - len('log')
mname = mname[0:tail]
if mname.endswith( '_' ) or mname.endswith('-'):
mname = mname[0:len(mname)-1]
return mname
def split_error_files( logDir ):
for fileName in os.listdir(logDir):
ipath = os.path.join( logDir, fileName )
if os.path.isfile(ipath):
mname = parse_module_name( fileName )
if mname is None or mname==fileName:
continue
odir = os.path.join( logDir, mname )
mkdir( odir )
opath = os.path.join( odir, fileName )
logging.info( 'ipath:'+ipath )
logging.info( 'opath:'+opath )
os.rename( ipath, opath )
def reorder_error_files( logDir ):
for fileName in os.listdir(logDir):
ipath = os.path.join( logDir, fileName )
if os.path.isdir(ipath):
reorder_elog_edir( ipath, False )
if __name__ == '__main__':
logDir = sys.argv[1]
split_error_files( logDir )
reorder_error_files( logDir )