/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Alexander Belchenko
  • Date: 2007-01-30 10:51:38 UTC
  • mto: This revision was merged to the branch mainline in revision 2259.
  • Revision ID: bialix@ukr.net-20070130105138-280dj0ayzeh886rb
trace.py: open_tracefile(): win98-compatible detection of location for .bzr.log

It's also change default location of .bzr.log on Windows 2000/XP as well:
now it in user's My Documents folder, so it's much better 
for users without administarator priveleges.

Also workaround win32-specific issue with file.tell().

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
        return
138
138
 
139
139
 
140
 
def open_tracefile(tracefilename='~/.bzr.log'):
 
140
def open_tracefile(tracefilename=None):
141
141
    # Messages are always written to here, so that we have some
142
142
    # information if something goes wrong.  In a future version this
143
143
    # file will be removed on successful completion.
144
144
    global _file_handler, _bzr_log_file
145
145
    import codecs
146
146
 
147
 
    trace_fname = os.path.join(os.path.expanduser(tracefilename))
 
147
    if tracefilename is None:
 
148
        if sys.platform == 'win32':
 
149
            from bzrlib import win32utils
 
150
            home = win32utils.get_home_location()
 
151
        else:
 
152
            home = os.path.expanduser('~')
 
153
        tracefilename = os.path.join(home, '.bzr.log')
 
154
 
 
155
    trace_fname = os.path.expanduser(tracefilename)
148
156
    _rollover_trace_maybe(trace_fname)
149
157
    try:
150
158
        LINE_BUFFERED = 1
151
159
        #tf = codecs.open(trace_fname, 'at', 'utf8', buffering=LINE_BUFFERED)
152
160
        tf = open(trace_fname, 'at', LINE_BUFFERED)
153
161
        _bzr_log_file = tf
154
 
        if tf.tell() == 0:
155
 
            tf.write("\nthis is a debug log for diagnosing/reporting problems in bzr\n")
 
162
        # tf.tell() on windows always return 0 until some writing done
 
163
        tf.write('\n')
 
164
        if tf.tell() <= 2:
 
165
            tf.write("this is a debug log for diagnosing/reporting problems in bzr\n")
156
166
            tf.write("you can delete or truncate this file, or include sections in\n")
157
167
            tf.write("bug reports to bazaar@lists.canonical.com\n\n")
158
168
        _file_handler = logging.StreamHandler(tf)