/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 breezy/trace.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-16 23:19:12 UTC
  • mfrom: (7180 work)
  • mto: This revision was merged to the branch mainline in revision 7294.
  • Revision ID: jelmer@jelmer.uk-20181116231912-e043vpq22bdkxa6q
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
249
249
            else:
250
250
                osutils.copy_ownership_from_path(filename)
251
251
                break
252
 
        return os.fdopen(fd, 'ab', 0) # unbuffered
253
 
 
 
252
        return os.fdopen(fd, 'ab', 0)  # unbuffered
254
253
 
255
254
    _brz_log_filename = _get_brz_log_filename()
256
255
    _rollover_trace_maybe(_brz_log_filename)
258
257
        brz_log_file = _open_or_create_log_file(_brz_log_filename)
259
258
        brz_log_file.write(b'\n')
260
259
        if brz_log_file.tell() <= 2:
261
 
            brz_log_file.write(b"this is a debug log for diagnosing/reporting problems in brz\n")
262
 
            brz_log_file.write(b"you can delete or truncate this file, or include sections in\n")
263
 
            brz_log_file.write(b"bug reports to https://bugs.launchpad.net/brz/+filebug\n\n")
 
260
            brz_log_file.write(
 
261
                b"this is a debug log for diagnosing/reporting problems in brz\n")
 
262
            brz_log_file.write(
 
263
                b"you can delete or truncate this file, or include sections in\n")
 
264
            brz_log_file.write(
 
265
                b"bug reports to https://bugs.launchpad.net/brz/+filebug\n\n")
264
266
 
265
267
        return brz_log_file
266
268
 
295
297
    brz_log_file = _open_brz_log()
296
298
    if brz_log_file is not None:
297
299
        brz_log_file.write(start_time.encode('utf-8') + b'\n')
298
 
    memento = push_log_file(brz_log_file,
 
300
    memento = push_log_file(
 
301
        brz_log_file,
299
302
        r'[%(process)5d] %(asctime)s.%(msecs)03d %(levelname)s: %(message)s',
300
303
        r'%Y-%m-%d %H:%M:%S')
301
304
    # after hooking output into brz_log, we also need to attach a stderr
302
305
    # handler, writing only at level info and with encoding
303
306
    if sys.version_info[0] == 2:
304
 
        stderr_handler = EncodedStreamHandler(sys.stderr,
305
 
            osutils.get_terminal_encoding(), 'replace', level=logging.INFO)
 
307
        stderr_handler = EncodedStreamHandler(
 
308
            sys.stderr, osutils.get_terminal_encoding(), 'replace',
 
309
            level=logging.INFO)
306
310
    else:
307
311
        stderr_handler = logging.StreamHandler(stream=sys.stderr)
308
312
    logging.getLogger('brz').addHandler(stderr_handler)
340
344
    old_trace_file = _trace_file
341
345
    # send traces to the new one
342
346
    _trace_file = to_file
343
 
    result = new_handler, _trace_file
344
347
    return ('log_memento', old_handlers, new_handler, old_trace_file, to_file)
345
348
 
346
349
 
429
432
 
430
433
_short_fields = ('VmPeak', 'VmSize', 'VmRSS')
431
434
 
 
435
 
432
436
def _debug_memory_proc(message='', short=True):
433
437
    try:
434
438
        status_file = open('/proc/%s/status' % os.getpid(), 'rb')
449
453
                    note(line)
450
454
                    break
451
455
 
 
456
 
452
457
def _dump_memory_usage(err_file):
453
458
    try:
454
459
        try:
460
465
        except ImportError:
461
466
            err_file.write("Dumping memory requires meliae module.\n")
462
467
            log_exception_quietly()
463
 
        except:
 
468
        except BaseException:
464
469
            err_file.write("Exception while dumping memory.\n")
465
470
            log_exception_quietly()
466
471
    finally:
508
513
            err_file.write("Use -Dmem_dump to dump memory to a file.\n")
509
514
        return errors.EXIT_ERROR
510
515
    elif isinstance(exc_object, ImportError) \
511
 
        and str(exc_object).startswith("No module named "):
512
 
        report_user_error(exc_info, err_file,
 
516
            and str(exc_object).startswith("No module named "):
 
517
        report_user_error(
 
518
            exc_info, err_file,
513
519
            'You may need to install this Python library separately.')
514
520
        return errors.EXIT_ERROR
515
521
    elif not getattr(exc_object, 'internal_error', True):
562
568
    try:
563
569
        sys.stdout.flush()
564
570
        sys.stderr.flush()
565
 
    except ValueError as e:
 
571
    except ValueError:
566
572
        # On Windows, I get ValueError calling stdout.flush() on a closed
567
573
        # handle
568
574
        pass
637
643
    """
638
644
 
639
645
    def __enter__(self):
640
 
        return self # This is bound to the 'as' clause in a with statement.
 
646
        return self  # This is bound to the 'as' clause in a with statement.
641
647
 
642
648
    def __exit__(self, exc_type, exc_val, exc_tb):
643
 
        return False # propogate exceptions.
 
649
        return False  # propogate exceptions.
644
650
 
645
651
 
646
652
class DefaultConfig(Config):
652
658
    def __enter__(self):
653
659
        self._original_filename = _brz_log_filename
654
660
        self._original_state = enable_default_logging()
655
 
        return self # This is bound to the 'as' clause in a with statement.
 
661
        return self  # This is bound to the 'as' clause in a with statement.
656
662
 
657
663
    def __exit__(self, exc_type, exc_val, exc_tb):
658
664
        pop_log_file(self._original_state)
659
665
        global _brz_log_filename
660
666
        _brz_log_filename = self._original_filename
661
 
        return False # propogate exceptions.
 
667
        return False  # propogate exceptions.