OLD | NEW |
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) |
OLD | NEW |