/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 19:47:19 UTC
  • mfrom: (7178 work)
  • mto: This revision was merged to the branch mainline in revision 7179.
  • Revision ID: jelmer@jelmer.uk-20181116194719-m5ut2wfuze5x9s1p
Merge trunk.

Show diffs side-by-side

added added

removed removed

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