~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Martin Pool
  • Date: 2005-04-15 02:50:12 UTC
  • Revision ID: mbp@sourcefrog.net-20050415025012-041f1e79f85586d3
- auto-rollover of .bzr.log

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
 
78
78
 
79
79
 
 
80
def _rollover_trace_maybe(trace_fname):
 
81
    try:
 
82
        size = os.stat(trace_fname)[stat.ST_SIZE]
 
83
        if size <= 100000:
 
84
            return
 
85
        old_fname = trace_fname + '.old'
 
86
 
 
87
        try:
 
88
            # must remove before rename on windows
 
89
            os.remove(old_fname)
 
90
        except OSError:
 
91
            pass
 
92
 
 
93
        try:
 
94
            # might fail if in use on windows
 
95
            os.rename(trace_fname, old_fname)
 
96
        except OSError:
 
97
            pass
 
98
    except OSError:
 
99
        return
 
100
 
 
101
 
 
102
 
80
103
def create_tracefile(argv):
81
104
    # TODO: Also show contents of /etc/lsb-release, if it can be parsed.
82
105
    #       Perhaps that should eventually go into the platform library?
89
112
 
90
113
    _starttime = os.times()[4]
91
114
 
92
 
    # TODO: If the file exists and is too large, rename it to .old;
93
 
    # must handle failures of this because we can't rename an open
94
 
    # file on Windows.
95
 
 
96
115
    trace_fname = os.path.join(os.path.expanduser('~/.bzr.log'))
 
116
    _rollover_trace_maybe(trace_fname)
97
117
 
98
118
    # buffering=1 means line buffered
99
119
    _tracefile = codecs.open(trace_fname, 'at', 'utf8', buffering=1)