2 from collections
import Counter
4 from django
.core
.management
.base
import BaseCommand
5 from django
.core
.urlresolvers
import resolve
, Resolver404
8 class Command(BaseCommand
):
9 """ Calculates the view-usage from CouchDB log files
11 log files can be gzipped. Output is printed to stdout """
13 def handle(self
, *args
, **options
):
19 for f
in self
.open_files(args
):
22 # assume standard Apache log format
23 part
= line
.split(' ')[6]
30 mod
= match
.func
.__module
__
31 key
= (mod
, match
.func
.__name
__)
35 for (mod
, funcname
), n
in handlers
.most_common(show_max
):
36 fqname
= '{}.{}'.format(mod
, funcname
)
37 print '{:60} {:>7}'.format(fqname
, n
)
40 def open_files(self
, files
):
41 for filename
in files
:
43 yield gzip
.open(filename
)