~arges/ubuntu-archive-tools/sru-review1

« back to all changes in this revision

Viewing changes to auto-sync

  • Committer: Colin Watson
  • Date: 2014-11-14 18:03:52 UTC
  • Revision ID: cjwatson@canonical.com-20141114180352-owfsdhrtp15odb7t
auto-sync: create a current.log symlink if logging to timestamped files

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import atexit
27
27
import bz2
28
28
from contextlib import closing
 
29
import errno
29
30
import gzip
30
31
from optparse import OptionParser, Values
31
32
import os
724
725
 
725
726
    if options.log_directory is not None:
726
727
        now = time.gmtime()
727
 
        log_file = os.path.join(
728
 
            options.log_directory, time.strftime("%F", now),
729
 
            "%s.log" % time.strftime("%T", now))
 
728
        log_relative_path = os.path.join(
 
729
            time.strftime("%F", now), "%s.log" % time.strftime("%T", now))
 
730
        log_file = os.path.join(options.log_directory, log_relative_path)
730
731
        if not os.path.isdir(os.path.dirname(log_file)):
731
732
            os.makedirs(os.path.dirname(log_file))
732
733
        sys.stdout = open(log_file, "w", buffering=1)
765
766
 
766
767
    sync_differences(options)
767
768
 
768
 
    if log_file is not None:
 
769
    if options.log_directory is not None:
769
770
        sys.stdout.close()
 
771
        current_link = os.path.join(options.log_directory, "current.log")
 
772
        try:
 
773
            os.unlink(current_link)
 
774
        except OSError as e:
 
775
            if e.errno != errno.ENOENT:
 
776
                raise
 
777
        os.symlink(log_relative_path, current_link)
770
778
 
771
779
 
772
780
if __name__ == '__main__':