Commits

Martin von Löwis  committed 9ec6903

Adjust to PEP 381: no local monthly stats; use two-digit months and days.

  • Participants
  • Parent commits b4aa56c

Comments (0)

Files changed (2)

File pep381client/apache_stats.py

 
     def build_local_stats(self, year, month, day, logfile, directory=None):
         """builds local stats with default values"""
-        filename = '%d-%d-%d.bz2' % (year, month, day)
+        filename = '%d-%.2d-%.2d.bz2' % (year, month, day)
         if directory is not None:
             filename = os.path.join(directory, filename)
 
 #!/usr/bin/python
 # Generates download stats for all days in the given log files,
-# except for the oldest and the newest day, and for all months
-# except for the newest one (possibly reading older daily stats)
+# except for the oldest and the newest day.
 import sys, os, csv
 from pep381client import apache_reader, apache_stats
 
 if not os.path.isdir(statsdir):
     os.mkdir(statsdir)
     os.mkdir(statsdir+'days')
-    os.mkdir(statsdir+'months')
 
 days = set()
 records = []
 class Stats(apache_stats.LocalStats):
     def _get_logs(self, logfile, files_url):
         return records
-months = set()
 stats = Stats()
 for year,month,day in days:
-    months.add((year,month))
     stats.build_local_stats(year, month, day, None, statsdir+'days')
 
-months = sorted(months)[:-1]
-files = os.listdir(statsdir+'days')
-for year,month in months:
-    totals = {}
-    ym = '%s-%s-' % (year, month)
-    for fn in files:
-        if fn.startswith(ym):
-            for r in stats.read_stats(statsdir+'days/'+fn):
-                key = (r['packagename'], r['filename'], r['useragent'])
-                value = r['count']
-                if key in totals:
-                    totals[key] += value
-                else:
-                    totals[key] = value
-    fileobj = stats._get_file_obj(statsdir+'months/%s-%s.bz2' % (year, month), 'wb', 'bz2')
-    writer = csv.writer(fileobj)
-    for key in sorted(totals.keys()):
-        count = totals[key]
-        writer.writerow(key + (count,))
-    fileobj.close()
-