/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

Merge test-run support.

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