[Erp5-report] r45659 luke - /erp5/trunk/utils/z2loganalyser/analyzeZ2log.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Apr 22 16:52:41 CEST 2011
Author: luke
Date: Fri Apr 22 16:52:40 2011
New Revision: 45659
URL: http://svn.erp5.org?rev=45659&view=rev
Log:
- use glob.glob instead of os.walk
Modified:
erp5/trunk/utils/z2loganalyser/analyzeZ2log.py
Modified: erp5/trunk/utils/z2loganalyser/analyzeZ2log.py
URL: http://svn.erp5.org/erp5/trunk/utils/z2loganalyser/analyzeZ2log.py?rev=45659&r1=45658&r2=45659&view=diff
==============================================================================
--- erp5/trunk/utils/z2loganalyser/analyzeZ2log.py [utf8] (original)
+++ erp5/trunk/utils/z2loganalyser/analyzeZ2log.py [utf8] Fri Apr 22 16:52:40 2011
@@ -34,6 +34,7 @@ import os
import re
import datetime
import gzip
+import glob
class Parser(OptionParser):
"""
@@ -127,45 +128,41 @@ class Executor:
result_dict = {}
top_directory_path = self.config.directory_path
- for root, dirs, files in os.walk(top_directory_path):
- # Z2.log-20090430.gz
- for file in files:
- if file.startswith('Z2.log') and file.endswith('.gz'):
- log_path = '%s/%s' % (root, file)
- file = gzip.open(log_path, 'rb')
- # file = open(log_path, 'rb')
-
- for line in file:
- m = regexp_match(line)
- try:
- result = m.groupdict()
- except AttributeError:
- continue
- else:
- # date = datetime.date(int(result['year']), 12, int(result['day']))
- format = '%d/%b/%Y:%H:%M:%S'
- date = datetime.datetime.strptime(result['date'], format)
- user = result['user']
- if user in ('', 'Anonymous', None):
- continue
-
- # ordinal = date.date().toordinal()
- ordinal = date.date().isoformat()
- time = date.time().isoformat()
- try:
- user_dict = result_dict[ordinal]
- except KeyError:
- result_dict[ordinal] = {}
- user_dict = result_dict[ordinal]
-
- if user in user_dict:
- time_frame = user_dict[user]
- user_dict[user] = [min(time, time_frame[0]),
- max(time, time_frame[1]),
- time_frame[2] + 1]
- else:
- user_dict[user] = [time, time, 1]
- file.close()
+ # Z2.log-20090430.gz
+ for filename in glob.glob(self.config.directory_path + '/Z2.log*.gz'):
+ f = gzip.open(filename, 'rb')
+
+ for line in f:
+ m = regexp_match(line)
+ try:
+ result = m.groupdict()
+ except AttributeError:
+ continue
+ else:
+ # date = datetime.date(int(result['year']), 12, int(result['day']))
+ format = '%d/%b/%Y:%H:%M:%S'
+ date = datetime.datetime.strptime(result['date'], format)
+ user = result['user']
+ if user in ('', 'Anonymous', None):
+ continue
+
+ # ordinal = date.date().toordinal()
+ ordinal = date.date().isoformat()
+ time = date.time().isoformat()
+ try:
+ user_dict = result_dict[ordinal]
+ except KeyError:
+ result_dict[ordinal] = {}
+ user_dict = result_dict[ordinal]
+
+ if user in user_dict:
+ time_frame = user_dict[user]
+ user_dict[user] = [min(time, time_frame[0]),
+ max(time, time_frame[1]),
+ time_frame[2] + 1]
+ else:
+ user_dict[user] = [time, time, 1]
+ f.close()
if not self.config.dry_run:
logfile = open(self.config.output_path, 'w')
More information about the Erp5-report
mailing list