/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: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

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