~james-w/udd/management-commands

« back to all changes in this revision

Viewing changes to udd/scripts/logrotate.py

  • Committer: James Westby
  • Date: 2011-12-13 21:09:23 UTC
  • mfrom: (557.1.1 drop_email_failures)
  • Revision ID: james.westby@canonical.com-20111213210923-tfrirlx3xbwmi70u
Merged drop_email_failures into management-commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import os
5
5
import subprocess
6
6
 
7
 
from udd import iconfig
 
7
from udd import (
 
8
    icommon,
 
9
    iconfig,
 
10
    )
8
11
 
9
 
logrotate_configuration='''%s {
 
12
logrotate_configuration='''{pi.driver.log.debug} {
10
13
    daily
11
14
    dateext
12
15
    rotate 7
16
19
    missingok
17
20
}
18
21
 
19
 
%s {
 
22
{pi.driver.log.progress} {
20
23
    daily
21
24
    dateext
22
25
    rotate 28
28
31
'''
29
32
 
30
33
def main():
31
 
    conf = iconfig.Iconfig()
32
 
    debug_log = conf.get('pkgimport.driver.log.debug')
33
 
    progress_log = conf.get('pkgimport.driver.log.progress')
 
34
    conf = iconfig.ImporterStack()
34
35
 
35
 
    log_dir = conf.get('pkgimport.driver.log_dir')
 
36
    log_dir = conf.get('pi.driver.log_dir')
 
37
    icommon.ensure_directory(log_dir)
36
38
    lrot_conf_path = os.path.join(log_dir, 'logrotate.conf')
37
 
    # We let the open fail if the directory doesn't exist, either there is no
38
 
    # log files or the setup is misconfigured anyway.
39
 
    lrot_conf = open(lrot_conf_path, 'w')
40
 
    try:
41
 
        # FIXME: Another use case for config.expand_options -- vila 2011-03-24
42
 
        lrot_conf.write(logrotate_configuration % (debug_log, progress_log))
43
 
    finally:
44
 
        lrot_conf.close()
 
39
    with open(lrot_conf_path, 'w') as f:
 
40
        f.write(conf.expand_options(logrotate_configuration))
45
41
 
46
42
    lrot_state_path = os.path.join(log_dir, 'logrotate.state')
47
43
    retcode = subprocess.call(['/usr/sbin/logrotate', '-s', lrot_state_path,