Add some arguments
This commit is contained in:
parent
95023a5db3
commit
9c82c61cf8
48
iwla.py
48
iwla.py
|
@ -1,11 +1,14 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import pickle
|
import pickle
|
||||||
import gzip
|
import gzip
|
||||||
import importlib
|
import importlib
|
||||||
|
import argparse
|
||||||
from calendar import monthrange
|
from calendar import monthrange
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
|
@ -439,7 +442,7 @@ class IWLA(object):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def start(self):
|
def start(self, _file):
|
||||||
print '==> Load previous database'
|
print '==> Load previous database'
|
||||||
|
|
||||||
self.meta_infos = self._deserialize(conf.META_PATH) or self._clearMeta()
|
self.meta_infos = self._deserialize(conf.META_PATH) or self._clearMeta()
|
||||||
|
@ -454,17 +457,16 @@ class IWLA(object):
|
||||||
|
|
||||||
print '==> Analysing log'
|
print '==> Analysing log'
|
||||||
|
|
||||||
with open(conf.analyzed_filename) as f:
|
for l in _file:
|
||||||
for l in f:
|
# print "line " + l
|
||||||
# print "line " + l
|
|
||||||
|
|
||||||
groups = self.log_re.match(l)
|
groups = self.log_re.match(l)
|
||||||
|
|
||||||
if groups:
|
if groups:
|
||||||
if not self._newHit(groups.groupdict()):
|
if not self._newHit(groups.groupdict()):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print "No match for " + l
|
print "No match for " + l
|
||||||
#break
|
#break
|
||||||
|
|
||||||
if self.analyse_started:
|
if self.analyse_started:
|
||||||
|
@ -477,5 +479,29 @@ class IWLA(object):
|
||||||
self._generateMonthStats()
|
self._generateMonthStats()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser(description='Intelligent Web Log Analyzer')
|
||||||
|
|
||||||
|
parser.add_argument('-c', '--clean-output', dest='clean_output', action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='Clean output before starting')
|
||||||
|
|
||||||
|
parser.add_argument('-i', '--stdin', dest='stdin', action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='Read data from stdin instead of conf.analyzed_filename')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.clean_output:
|
||||||
|
if os.path.exists(conf.DB_ROOT): shutil.rmtree(conf.DB_ROOT)
|
||||||
|
if os.path.exists(conf.DISPLAY_ROOT): shutil.rmtree(conf.DISPLAY_ROOT)
|
||||||
|
|
||||||
iwla = IWLA()
|
iwla = IWLA()
|
||||||
iwla.start()
|
|
||||||
|
if args.stdin:
|
||||||
|
iwla.start(sys.stdin)
|
||||||
|
else:
|
||||||
|
if not os.path.exists(conf.analyzed_filename):
|
||||||
|
print 'No such file \'%s\'' % (conf.analyzed_filename)
|
||||||
|
sys.exit(-1)
|
||||||
|
with open(conf.analyzed_filename) as f:
|
||||||
|
iwla.start(f)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user