Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: modules/statsmaster/templates/build_static_head.erb

Issue 5667089633247232: Issue 479 - Make AWStats produce daily reports as well (Closed)
Patch Set: Created June 24, 2014, 6:08 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import subprocess 3 import subprocess
4 import sys 4 import sys
5 import os 5 import os
6 import re 6 import re
7 from datetime import datetime, timedelta 7 from datetime import datetime, timedelta
8 8
9 if len(sys.argv) > 1: 9 if len(sys.argv) > 1:
10 yearmonth = sys.argv[1] 10 yearmonth = sys.argv[1]
11 if yearmonth == 'prevmonth': 11 if yearmonth == 'prevmonth':
12 now = datetime.now() 12 now = datetime.now()
13 yearmonth = (now - timedelta(days=now.day)).strftime('%Y%m') 13 yearmonth = (now - timedelta(days=now.day)).strftime('%Y%m')
14 year, month = re.search(r'^(\d{4})(\d{2})$', yearmonth).groups() 14 year, month = re.search(r'^(\d{4})(\d{2})$', yearmonth).groups()
15 dirtemplate = os.path.join('/var/www/awstats/archive/%s', yearmonth) 15 dirtemplate = os.path.join('/var/www/awstats/archive/%s', yearmonth)
16 additional_params = ['-month=%s' % month, '-year=%s' % year] 16 additional_params = ['-month=%s' % month, '-year=%s' % year]
17 day = None
17 else: 18 else:
18 dirtemplate = '/var/www/awstats/%s' 19 dirtemplate = '/var/www/awstats/%s'
19 additional_params = [] 20 additional_params = []
21
22 yesterday = datetime.now() - timedelta(days=1)
23 day = yesterday.strftime('%Y%m%d')
24 daily_params = ['-day=%i' % yesterday.day,
25 '-month=%i' % yesterday.month,
26 '-year=%i' % yesterday.year]
27
28 def build_pages(site, dir, databasebreak):
29 if not os.path.exists(dir):
30 os.mkdir(dir, 0755)
31
32 datadir = {
33 'month': '/var/www/awstatsdata',
34 'day': '/var/www/awstatsdatadaily',
35 }[databasebreak]
36
37 additional = daily_params if databasebreak == 'day' else additional_params
38
39 subprocess.check_output([
40 '/usr/share/awstats/tools/awstats_buildstaticpages.pl',
41 '-configdir=/var/www/awstatsconf',
42 '-config=%s' % site,
43 '-databasebreak=%s' % databasebreak,
44 '-dir=%s' % dir
45 ] + additional, env={'AWSTATSDATA': datadir})
46
47 index = os.path.join(dir, 'index.html')
48 if not os.path.exists(index):
49 os.symlink(os.path.join(dir, 'awstats.%s.html' % site), index)
OLDNEW
« no previous file with comments | « modules/statsmaster/templates/awstats.conf ('k') | modules/statsmaster/templates/build_static_item.erb » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld