/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/crash.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
In principle apport can run on any platform though as of Feb 2010 there seem
33
33
to be some portability bugs.
34
34
 
35
 
To force this off in brz turn set APPORT_DISABLE in the environment or 
 
35
To force this off in brz turn set APPORT_DISABLE in the environment or
36
36
-Dno_apport.
37
37
"""
38
38
 
39
 
from __future__ import absolute_import
40
 
 
41
 
# for interactive testing, try the 'brz assert-fail' command 
 
39
# for interactive testing, try the 'brz assert-fail' command
42
40
# or see http://code.launchpad.net/~mbp/bzr/bzr-fail
43
41
#
44
42
# to test with apport it's useful to set
45
43
# export APPORT_IGNORE_OBSOLETE_PACKAGES=1
46
44
 
 
45
from io import StringIO
47
46
import os
48
47
import platform
49
48
import pprint
52
51
 
53
52
import breezy
54
53
from . import (
55
 
    config,
 
54
    bedding,
56
55
    debug,
57
56
    osutils,
58
57
    plugin,
59
58
    trace,
60
59
    )
61
 
from .sixish import (
62
 
    StringIO,
63
 
    )
64
60
 
65
61
 
66
62
def report_bug(exc_info, stderr):
67
63
    if ('no_apport' in debug.debug_flags) or \
68
 
        os.environ.get('APPORT_DISABLE', None):
 
64
            os.environ.get('APPORT_DISABLE', None):
69
65
        return report_bug_legacy(exc_info, stderr)
70
66
    try:
71
67
        if report_bug_to_apport(exc_info, stderr):
86
82
    trace.print_exception(exc_info, err_file)
87
83
    err_file.write('\n')
88
84
    import textwrap
 
85
 
89
86
    def print_wrapped(l):
90
 
        err_file.write(textwrap.fill(l,
91
 
            width=78, subsequent_indent='    ') + '\n')
92
 
    print_wrapped('brz %s on python %s (%s)\n' % \
93
 
        (breezy.__version__,
94
 
        breezy._format_version_tuple(sys.version_info),
95
 
        platform.platform(aliased=1)))
 
87
        err_file.write(textwrap.fill(
 
88
            l, width=78, subsequent_indent='    ') + '\n')
 
89
    print_wrapped('brz %s on python %s (%s)\n' %
 
90
                  (breezy.__version__,
 
91
                   breezy._format_version_tuple(sys.version_info),
 
92
                   platform.platform(aliased=1)))
96
93
    print_wrapped('arguments: %r\n' % sys.argv)
97
94
    print_wrapped(textwrap.fill(
98
95
        'plugins: ' + plugin.format_concise_plugin_list(),
124
121
    # This import is apparently not used, but we're doing it so that if the
125
122
    # import fails, the exception will be caught at a higher level and we'll
126
123
    # report the error by other means.
127
 
    import apport
 
124
    import apport  # noqa: F401
128
125
 
129
126
    crash_filename = _write_apport_report_to_file(exc_info)
130
127
 
131
128
    if crash_filename is None:
132
129
        stderr.write("\n"
133
 
            "apport is set to ignore crashes in this version of brz.\n"
134
 
            )
 
130
                     "apport is set to ignore crashes in this version of brz.\n"
 
131
                     )
135
132
    else:
136
133
        trace.print_exception(exc_info, stderr)
137
134
        stderr.write("\n"
138
 
            "You can report this problem to Bazaar's developers by running\n"
139
 
            "    apport-bug %s\n"
140
 
            "if a bug-reporting window does not automatically appear.\n"
141
 
            % (crash_filename))
 
135
                     "You can report this problem to Bazaar's developers by running\n"
 
136
                     "    apport-bug %s\n"
 
137
                     "if a bug-reporting window does not automatically appear.\n"
 
138
                     % (crash_filename))
142
139
        # XXX: on Windows, Mac, and other platforms where we might have the
143
140
        # apport libraries but not have an apport always running, we could
144
141
        # synchronously file now
183
180
    pr['SourcePackage'] = 'brz'
184
181
    pr['Package'] = 'brz'
185
182
 
186
 
    # tell apport to file directly against the brz package using 
 
183
    # tell apport to file directly against the brz package using
187
184
    # <https://bugs.launchpad.net/bzr/+bug/391015>
188
185
    #
189
186
    # XXX: unfortunately apport may crash later if the crashdb definition
206
203
    # these may contain some sensitive info (smtp_passwords)
207
204
    # TODO: strip that out and attach the rest
208
205
    #
209
 
    #attach_file_if_exists(report,
 
206
    # attach_file_if_exists(report,
210
207
    #   os.path.join(dot_brz, 'breezy.conf', 'BrzConfig')
211
 
    #attach_file_if_exists(report,
 
208
    # attach_file_if_exists(report,
212
209
    #   os.path.join(dot_brz, 'locations.conf', 'BrzLocations')
213
210
 
214
211
    # strip username, hostname, etc
238
235
 
239
236
 
240
237
def _open_crash_file():
241
 
    crash_dir = config.crash_dir()
 
238
    crash_dir = bedding.crash_dir()
242
239
    if not osutils.isdir(crash_dir):
243
240
        # on unix this should be /var/crash and should already exist; on
244
241
        # Windows or if it's manually configured it might need to be created,
258
255
    # be careful here that people can't play tmp-type symlink mischief in the
259
256
    # world-writable directory
260
257
    return filename, os.fdopen(
261
 
        os.open(filename, 
262
 
            os.O_WRONLY|os.O_CREAT|os.O_EXCL,
263
 
            0o600),
 
258
        os.open(filename,
 
259
                os.O_WRONLY | os.O_CREAT | os.O_EXCL,
 
260
                0o600),
264
261
        'wb')
265
262
 
266
263