iwla

iwla Commit Details

Date:2015-05-14 09:54:25 (6 years 2 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:86fc5f2189c07bf34c7d7e1a4885bf68c4609d07
Parents: 62be78845a7d4e1defbfa3c6ce54b91e4743cf5a
Message:Add FileIter to iwla, allowing to specify multiple files to analyse

Changes:
Miwla.py (2 diffs)

File differences

iwla.py
720720
721721
722722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
723755
724756
725757
......
775807
776808
777809
778
779
780
781
782
810
else:
self.logger.info('==> Analyse not started : nothing new')
class FileIter(object):
def __init__(self, filenames):
self.filenames = [f for f in filenames.split(',') if f]
for f in self.filenames:
if not os.path.exists(f):
print 'No such file \'%s\'' % (f)
sys.exit(-1)
self.cur_file = None
self._openNextFile()
def __iter__(self):
return self
def __next__(self):
return self.next()
def _openNextFile(self):
if self.cur_file:
self.cur_file.close()
self.cur_file = None
if not self.filenames:
raise StopIteration()
self.cur_file = open(self.filenames.pop(0))
def next(self):
l = self.cur_file.readline()
if not l:
self._openNextFile()
l = self.cur_file.readline()
return l[:-1]
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Intelligent Web Log Analyzer')
iwla.start(sys.stdin)
else:
filename = args.file or conf.analyzed_filename
if not os.path.exists(filename):
print 'No such file \'%s\'' % (filename)
sys.exit(-1)
with open(filename) as f:
iwla.start(f)
iwla.start(FileIter(filename))

Archive Download the corresponding diff file

Branches

Tags