Exemplo n.º 1
0
def report_bug_legacy(exc_info, err_file):
    """Report a bug by just printing a message to the user."""
    trace.print_exception(exc_info, err_file)
    err_file.write('\n')
    import textwrap
    def print_wrapped(l):
        err_file.write(textwrap.fill(l,
            width=78, subsequent_indent='    ') + '\n')
    print_wrapped('bzr %s on python %s (%s)\n' % \
        (bzrlib.__version__,
        bzrlib._format_version_tuple(sys.version_info),
        platform.platform(aliased=1)))
    print_wrapped('arguments: %r\n' % sys.argv)
    print_wrapped(textwrap.fill(
        'plugins: ' + plugin.format_concise_plugin_list(),
        width=78,
        subsequent_indent='    ',
        ) + '\n')
    print_wrapped(
        'encoding: %r, fsenc: %r, lang: %r\n' % (
            osutils.get_user_encoding(), sys.getfilesystemencoding(),
            os.environ.get('LANG')))
    # We used to show all the plugins here, but it's too verbose.
    err_file.write(
        "\n"
        "*** Bazaar has encountered an internal error.  This probably indicates a\n"
        "    bug in Bazaar.  You can help us fix it by filing a bug report at\n"
        "        https://bugs.launchpad.net/bzr/+filebug\n"
        "    including this traceback and a description of the problem.\n"
        )
Exemplo n.º 2
0
def report_bug_legacy(exc_info, err_file):
    """Report a bug by just printing a message to the user."""
    trace.print_exception(exc_info, err_file)
    err_file.write('\n')
    import textwrap

    def print_wrapped(l):
        err_file.write(
            textwrap.fill(l, width=78, subsequent_indent='    ') + '\n')
    print_wrapped('bzr %s on python %s (%s)\n' % \
        (bzrlib.__version__,
        bzrlib._format_version_tuple(sys.version_info),
        platform.platform(aliased=1)))
    print_wrapped('arguments: %r\n' % sys.argv)
    print_wrapped(
        textwrap.fill(
            'plugins: ' + plugin.format_concise_plugin_list(),
            width=78,
            subsequent_indent='    ',
        ) + '\n')
    print_wrapped('encoding: %r, fsenc: %r, lang: %r\n' %
                  (osutils.get_user_encoding(), sys.getfilesystemencoding(),
                   os.environ.get('LANG')))
    # We used to show all the plugins here, but it's too verbose.
    err_file.write(
        "\n"
        "*** Bazaar has encountered an internal error.  This probably indicates a\n"
        "    bug in Bazaar.  You can help us fix it by filing a bug report at\n"
        "        https://bugs.launchpad.net/bzr/+filebug\n"
        "    including this traceback and a description of the problem.\n")
Exemplo n.º 3
0
def show_version(show_config=True, show_copyright=True, to_file=None):
    if to_file is None:
        to_file = sys.stdout
    to_file.write("Bazaar (bzr) %s\n" % bzrlib.__version__)
    # is bzrlib itself in a branch?
    src_tree = _get_bzr_source_tree()
    if src_tree:
        src_revision_id = src_tree.last_revision()
        revno = src_tree.branch.revision_id_to_revno(src_revision_id)
        to_file.write("  from bzr checkout %s\n" % (src_tree.basedir, ))
        to_file.write("    revision: %s\n" % (revno, ))
        to_file.write("    revid: %s\n" % (src_revision_id, ))
        to_file.write("    branch nick: %s\n" % (src_tree.branch.nick, ))

    to_file.write("  Python interpreter: ")
    # show path to python interpreter
    # (bzr.exe use python interpreter from pythonXY.dll
    # but sys.executable point to bzr.exe itself)
    if not hasattr(sys, 'frozen'):  # check for bzr.exe
        # python executable
        to_file.write(sys.executable + ' ')
    else:
        # pythonXY.dll
        basedir = os.path.dirname(sys.executable)
        python_dll = "python%d%d.dll" % sys.version_info[:2]
        to_file.write(os.path.join(basedir, python_dll) + ' ')
    # and now version of python interpreter
    to_file.write(bzrlib._format_version_tuple(sys.version_info))
    to_file.write('\n')

    to_file.write("  Python standard library:" + ' ')
    to_file.write(os.path.dirname(os.__file__) + '\n')
    to_file.write("  bzrlib: ")
    if len(bzrlib.__path__) > 1:
        # print repr, which is a good enough way of making it clear it's
        # more than one element (eg ['/foo/bar', '/foo/bzr'])
        to_file.write(repr(bzrlib.__path__) + '\n')
    else:
        to_file.write(bzrlib.__path__[0] + '\n')
    if show_config:
        config_dir = os.path.normpath(
            config.config_dir())  # use native slashes
        if not isinstance(config_dir, unicode):
            config_dir = config_dir.decode(bzrlib.user_encoding)
        to_file.write("  Bazaar configuration: %s\n" % (config_dir, ))
        to_file.write("  Bazaar log file: ")
        to_file.write(trace._bzr_log_filename + '\n')
    if show_copyright:
        to_file.write('\n')
        to_file.write(bzrlib.__copyright__ + '\n')
        to_file.write("http://bazaar-vcs.org/\n")
        to_file.write('\n')
        to_file.write(
            "bzr comes with ABSOLUTELY NO WARRANTY.  bzr is free software, and\n"
        )
        to_file.write(
            "you may use, modify and redistribute it under the terms of the GNU\n"
        )
        to_file.write("General Public License version 2 or later.\n")
    to_file.write('\n')
Exemplo n.º 4
0
def show_version(show_config=True, show_copyright=True, to_file=None):
    if to_file is None:
        to_file = sys.stdout
    to_file.write("Bazaar (bzr) %s\n" % bzrlib.__version__)
    # is bzrlib itself in a branch?
    src_tree = _get_bzr_source_tree()
    if src_tree:
        src_revision_id = src_tree.last_revision()
        revno = src_tree.branch.revision_id_to_revno(src_revision_id)
        to_file.write("  from bzr checkout %s\n" % (src_tree.basedir,))
        to_file.write("    revision: %s\n" % (revno,))
        to_file.write("    revid: %s\n" % (src_revision_id,))
        to_file.write("    branch nick: %s\n" % (src_tree.branch.nick,))

    to_file.write("  Python interpreter: ")
    # show path to python interpreter
    # (bzr.exe use python interpreter from pythonXY.dll
    # but sys.executable point to bzr.exe itself)
    # however, sys.frozen exists if running from bzr.exe
    # see http://www.py2exe.org/index.cgi/Py2exeEnvironment
    if getattr(sys, 'frozen', None) is None: # if not bzr.exe
        to_file.write(sys.executable + ' ')
    else:
        # pythonXY.dll
        basedir = os.path.dirname(sys.executable)
        python_dll = "python%d%d.dll" % sys.version_info[:2]
        to_file.write(os.path.join(basedir, python_dll) + ' ')
    # and now version of python interpreter
    to_file.write(bzrlib._format_version_tuple(sys.version_info))
    to_file.write('\n')

    to_file.write("  Python standard library:" + ' ')
    to_file.write(os.path.dirname(os.__file__) + '\n')
    to_file.write("  Platform: %s\n"
                  % platform.platform(aliased=1).decode('utf-8'))
    to_file.write("  bzrlib: ")
    if len(bzrlib.__path__) > 1:
        # print repr, which is a good enough way of making it clear it's
        # more than one element (eg ['/foo/bar', '/foo/bzr'])
        to_file.write(repr(bzrlib.__path__) + '\n')
    else:
        to_file.write(bzrlib.__path__[0] + '\n')
    if show_config:
        config_dir = osutils.normpath(config.config_dir())  # use native slashes
        if not isinstance(config_dir, unicode):
            config_dir = config_dir.decode(osutils.get_user_encoding())
        to_file.write("  Bazaar configuration: %s\n" % (config_dir,))
        to_file.write("  Bazaar log file: ")
        to_file.write(trace._bzr_log_filename + '\n')
    if show_copyright:
        to_file.write('\n')
        to_file.write(bzrlib.__copyright__ + '\n')
        to_file.write("http://bazaar.canonical.com/\n")
        to_file.write('\n')
        to_file.write("bzr comes with ABSOLUTELY NO WARRANTY.  bzr is free software, and\n")
        to_file.write("you may use, modify and redistribute it under the terms of the GNU\n")
        to_file.write("General Public License version 2 or later.\n")
        to_file.write("\nBazaar is part of the GNU Project to produce a free operating "
                "system.\n")
    to_file.write('\n')
def deprecated_in(version_tuple):
    """Generate a message that something was deprecated in a release.

    >>> deprecated_in((1, 4, 0))
    '%s was deprecated in version 1.4.0.'
    """
    return ("%%s was deprecated in version %s."
            % bzrlib._format_version_tuple(version_tuple))
Exemplo n.º 6
0
def deprecated_in(version_tuple):
    """Generate a message that something was deprecated in a release.

    >>> deprecated_in((1, 4, 0))
    '%s was deprecated in version 1.4.'
    """
    return ("%%s was deprecated in version %s."
            % bzrlib._format_version_tuple(version_tuple))
Exemplo n.º 7
0
Arquivo: plugins.py Projeto: biji/qbzr
def format_plugin_version(plugin):
    """Return the version of a plugin as a formatted string."""
    version_info = plugin.version_info()
    if version_info is None:
        result = ''
    else:
        try:
            result = _format_version_tuple(version_info)
        except (ValueError, IndexError):
            # Version info fails the expected rules.
            # Format it nicely anyhow.
            result = ".".join([str(part) for part in version_info])
    return result
Exemplo n.º 8
0
def get_sys_info():
    """Get the system information.

    :return: a dictionary mapping fields to values. Field names are:
      * bzr-version - version of Bazaar
      * bzr-lib-path - paths to bzrlib roots (a list)
      * bzr-source-tree - source tree holding Bazaar (None or a Tree object)
      * bzr-config-dir - configuration directory holding bazaar.conf, etc.
      * bzr-log-file - path to bzr.log file
      * python-file - path to Python interpreter
      * python-version - version of Python interpreter
      * python-lib-dir - path to Python standard library
    """
    result = {}

    # Bazaar installation
    result["bzr-version"] = bzrlib.__version__
    result["bzr-lib-path"] = bzrlib.__path__
    # is bzrlib itself in a branch?
    source_tree = None  #_get_bzr_source_tree()
    if source_tree:
        result["bzr-source-tree"] = _source_tree_details()
    else:
        result["bzr-source-tree"] = None

    # Bazaar configuration
    config_dir = os.path.normpath(config.config_dir())  # use native slashes
    if not isinstance(config_dir, unicode):
        config_dir = config_dir.decode(osutils.get_user_encoding())
    result["bzr-config-dir"] = config_dir
    result["bzr-log-file"] = trace._bzr_log_filename

    # Python installation
    # (bzr.exe use python interpreter from pythonXY.dll
    # but sys.executable point to bzr.exe itself)
    if not hasattr(sys, 'frozen'):  # check for bzr.exe
        # python executable
        py_file = sys.executable
    else:
        # pythonXY.dll
        basedir = os.path.dirname(sys.executable)
        python_dll = "python%d%d.dll" % sys.version_info[:2]
        py_file = os.path.join(basedir, python_dll)
    result["python-file"] = py_file
    result["python-version"] = bzrlib._format_version_tuple(sys.version_info)
    result["python-lib-dir"] = os.path.dirname(os.__file__)
    return result
Exemplo n.º 9
0
def report_bug(exc_info, err_file):
    """Report an exception that probably indicates a bug in bzr"""
    print_exception(exc_info, err_file)
    err_file.write('\n')
    err_file.write('bzr %s on python %s (%s)\n' % \
                       (bzrlib.__version__,
                        bzrlib._format_version_tuple(sys.version_info),
                        sys.platform))
    err_file.write('arguments: %r\n' % sys.argv)
    err_file.write('encoding: %r, fsenc: %r, lang: %r\n' %
                   (osutils.get_user_encoding(), sys.getfilesystemencoding(),
                    os.environ.get('LANG')))
    err_file.write("plugins:\n")
    for name, a_plugin in sorted(plugin.plugins().items()):
        err_file.write("  %-20s %s [%s]\n" %
                       (name, a_plugin.path(), a_plugin.__version__))
    err_file.write("""\
*** Bazaar has encountered an internal error.
    Please report a bug at https://bugs.launchpad.net/bzr/+filebug
    including this traceback, and a description of what you
    were doing when the error occurred.
""")
Exemplo n.º 10
0
def report_bug(exc_info, err_file):
    """Report an exception that probably indicates a bug in bzr"""
    print_exception(exc_info, err_file)
    err_file.write('\n')
    err_file.write('bzr %s on python %s (%s)\n' % \
                       (bzrlib.__version__,
                        bzrlib._format_version_tuple(sys.version_info),
                        sys.platform))
    err_file.write('arguments: %r\n' % sys.argv)
    err_file.write(
        'encoding: %r, fsenc: %r, lang: %r\n' % (
            osutils.get_user_encoding(), sys.getfilesystemencoding(),
            os.environ.get('LANG')))
    err_file.write("plugins:\n")
    for name, a_plugin in sorted(plugin.plugins().items()):
        err_file.write("  %-20s %s [%s]\n" %
            (name, a_plugin.path(), a_plugin.__version__))
    err_file.write(
"""\
*** Bazaar has encountered an internal error.
    Please report a bug at https://bugs.launchpad.net/bzr/+filebug
    including this traceback, and a description of what you
    were doing when the error occurred.
""")
Exemplo n.º 11
0
def _write_apport_report_to_file(exc_info):
    import traceback
    from apport.report import Report

    exc_type, exc_object, exc_tb = exc_info

    pr = Report()
    # add_proc_info sets the ExecutablePath, InterpreterPath, etc.
    pr.add_proc_info()
    # It also adds ProcMaps which for us is rarely useful and mostly noise, so
    # let's remove it.
    del pr['ProcMaps']
    pr.add_user_info()

    # Package and SourcePackage are needed so that apport will report about even
    # non-packaged versions of bzr; also this reports on their packaged
    # dependencies which is useful.
    pr['SourcePackage'] = 'bzr'
    pr['Package'] = 'bzr'

    pr['CommandLine'] = pprint.pformat(sys.argv)
    pr['BzrVersion'] = bzrlib.__version__
    pr['PythonVersion'] = bzrlib._format_version_tuple(sys.version_info)
    pr['Platform'] = platform.platform(aliased=1)
    pr['UserEncoding'] = osutils.get_user_encoding()
    pr['FileSystemEncoding'] = sys.getfilesystemencoding()
    pr['Locale'] = os.environ.get('LANG', 'C')
    pr['BzrPlugins'] = _format_plugin_list()
    pr['PythonLoadedModules'] = _format_module_list()
    pr['BzrDebugFlags'] = pprint.pformat(debug.debug_flags)

    # actually we'd rather file directly against the upstream product, but
    # apport does seem to count on there being one in there; we might need to
    # redirect it elsewhere anyhow
    pr['SourcePackage'] = 'bzr'
    pr['Package'] = 'bzr'

    # tell apport to file directly against the bzr package using 
    # <https://bugs.launchpad.net/bzr/+bug/391015>
    #
    # XXX: unfortunately apport may crash later if the crashdb definition
    # file isn't present
    pr['CrashDb'] = 'bzr'

    tb_file = StringIO()
    traceback.print_exception(exc_type, exc_object, exc_tb, file=tb_file)
    pr['Traceback'] = tb_file.getvalue()

    _attach_log_tail(pr)

    # We want to use the 'bzr' crashdb so that it gets sent directly upstream,
    # which is a reasonable default for most internal errors.  However, if we
    # set it here then apport will crash later if it doesn't know about that
    # crashdb.  Instead, we rely on the bzr package installing both a
    # source hook telling crashes to go to this crashdb, and a crashdb
    # configuration describing it.

    # these may contain some sensitive info (smtp_passwords)
    # TODO: strip that out and attach the rest
    #
    #attach_file_if_exists(report,
    #   os.path.join(dot_bzr, 'bazaar.conf', 'BzrConfig')
    #attach_file_if_exists(report,
    #   os.path.join(dot_bzr, 'locations.conf', 'BzrLocations')
    
    # strip username, hostname, etc
    pr.anonymize()

    if pr.check_ignored():
        # eg configured off in ~/.apport-ignore.xml
        return None
    else:
        crash_file_name, crash_file = _open_crash_file()
        pr.write(crash_file)
        crash_file.close()
        return crash_file_name
Exemplo n.º 12
0
def _write_apport_report_to_file(exc_info):
    import traceback
    from apport.report import Report

    exc_type, exc_object, exc_tb = exc_info

    pr = Report()
    # add_proc_info sets the ExecutablePath, InterpreterPath, etc.
    pr.add_proc_info()
    # It also adds ProcMaps which for us is rarely useful and mostly noise, so
    # let's remove it.
    del pr['ProcMaps']
    pr.add_user_info()

    # Package and SourcePackage are needed so that apport will report about even
    # non-packaged versions of bzr; also this reports on their packaged
    # dependencies which is useful.
    pr['SourcePackage'] = 'bzr'
    pr['Package'] = 'bzr'

    pr['CommandLine'] = pprint.pformat(sys.argv)
    pr['BzrVersion'] = bzrlib.__version__
    pr['PythonVersion'] = bzrlib._format_version_tuple(sys.version_info)
    pr['Platform'] = platform.platform(aliased=1)
    pr['UserEncoding'] = osutils.get_user_encoding()
    pr['FileSystemEncoding'] = sys.getfilesystemencoding()
    pr['Locale'] = os.environ.get('LANG', 'C')
    pr['BzrPlugins'] = _format_plugin_list()
    pr['PythonLoadedModules'] = _format_module_list()
    pr['BzrDebugFlags'] = pprint.pformat(debug.debug_flags)

    # actually we'd rather file directly against the upstream product, but
    # apport does seem to count on there being one in there; we might need to
    # redirect it elsewhere anyhow
    pr['SourcePackage'] = 'bzr'
    pr['Package'] = 'bzr'

    # tell apport to file directly against the bzr package using
    # <https://bugs.launchpad.net/bzr/+bug/391015>
    #
    # XXX: unfortunately apport may crash later if the crashdb definition
    # file isn't present
    pr['CrashDb'] = 'bzr'

    tb_file = StringIO()
    traceback.print_exception(exc_type, exc_object, exc_tb, file=tb_file)
    pr['Traceback'] = tb_file.getvalue()

    _attach_log_tail(pr)

    # We want to use the 'bzr' crashdb so that it gets sent directly upstream,
    # which is a reasonable default for most internal errors.  However, if we
    # set it here then apport will crash later if it doesn't know about that
    # crashdb.  Instead, we rely on the bzr package installing both a
    # source hook telling crashes to go to this crashdb, and a crashdb
    # configuration describing it.

    # these may contain some sensitive info (smtp_passwords)
    # TODO: strip that out and attach the rest
    #
    #attach_file_if_exists(report,
    #   os.path.join(dot_bzr, 'bazaar.conf', 'BzrConfig')
    #attach_file_if_exists(report,
    #   os.path.join(dot_bzr, 'locations.conf', 'BzrLocations')

    # strip username, hostname, etc
    pr.anonymize()

    if pr.check_ignored():
        # eg configured off in ~/.apport-ignore.xml
        return None
    else:
        crash_file_name, crash_file = _open_crash_file()
        pr.write(crash_file)
        crash_file.close()
        return crash_file_name
Exemplo n.º 13
0
Arquivo: trace.py Projeto: biji/qbzr
def report_exception(exc_info=None,
                     type=MAIN_LOAD_METHOD,
                     window=None,
                     ui_mode=False):
    """Report an exception.

    The error is reported to the console or a message box, depending
    on the type. 
    """

    # We only want one error to show if the user chose Close
    global closing_due_to_error
    # 0.20 special: We check hasattr() first to work around
    # <http://bugs.python.org/issue4230>
    if closing_due_to_error or \
            (hasattr(window, 'closing_due_to_error') and
             window.closing_due_to_error):
        return

    if exc_info is None:
        exc_info = sys.exc_info()

    exc_type, exc_object, exc_tb = exc_info

    # Don't show error for StopException
    if isinstance(exc_object, StopException):
        # Do we maybe want to log this?
        return

    msg_box = ((type == MAIN_LOAD_METHOD and
                (window and window.ui_mode or ui_mode))
               or not type == MAIN_LOAD_METHOD)
    pdb = os.environ.get('BZR_PDB')
    if pdb:
        msg_box = False

    if msg_box:
        err_file = StringIO()
    else:
        err_file = sys.stderr

    # always tell bzr to report it, so it ends up in the log.
    # See https://bugs.launchpad.net/bzr/+bug/785695
    error_type = _bzrlib_report_exception(exc_info, err_file)
    backtrace = traceback.format_exception(*exc_info)
    mutter(''.join(backtrace))

    if (type == MAIN_LOAD_METHOD and window):
        window.ret_code = error_type

    # XXX This is very similar to bzrlib.commands.exception_to_return_code.
    # We shoud get bzr to refactor so that that this is reuseable.
    if pdb:
        # With out this - pyQt shows lot of warnings. see:
        # http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#using-pyqt-from-the-python-shell
        QtCore.pyqtRemoveInputHook()

        print '**** entering debugger'
        tb = exc_info[2]
        import pdb
        if sys.version_info[:2] < (2, 6):
            # XXX: we want to do
            #    pdb.post_mortem(tb)
            # but because pdb.post_mortem gives bad results for tracebacks
            # from inside generators, we do it manually.
            # (http://bugs.python.org/issue4150, fixed in Python 2.6)

            # Setup pdb on the traceback
            p = pdb.Pdb()
            p.reset()
            p.setup(tb.tb_frame, tb)
            # Point the debugger at the deepest frame of the stack
            p.curindex = len(p.stack) - 1
            p.curframe = p.stack[p.curindex][0]
            # Start the pdb prompt.
            p.print_stack_entry(p.stack[p.curindex])
            p.execRcLines()
            p.cmdloop()
        else:
            pdb.post_mortem(tb)

    close = True
    if msg_box:
        if isinstance(exc_object, errors.LockContention):
            msg_box = create_lockerror_dialog(error_type, window)

        elif error_type == errors.EXIT_INTERNAL_ERROR:
            # this is a copy of bzrlib.trace.report_bug
            # but we seperate the message, and the trace back,
            # and addes a hyper link to the filebug page.
            traceback_file = StringIO()
            _bzrlib_print_exception(exc_info, traceback_file)
            traceback_file.write('\n')
            traceback_file.write('bzr %s on python %s (%s)\n' % \
                               (bzrlib.__version__,
                                bzrlib._format_version_tuple(sys.version_info),
                                sys.platform))
            traceback_file.write('arguments: %r\n' % sys.argv)
            traceback_file.write(
                'encoding: %r, fsenc: %r, lang: %r\n' %
                (osutils.get_user_encoding(), sys.getfilesystemencoding(),
                 os.environ.get('LANG')))
            traceback_file.write("plugins:\n")
            for name, a_plugin in sorted(plugin.plugins().items()):
                traceback_file.write(
                    "  %-20s %s [%s]\n" %
                    (name, a_plugin.path(), a_plugin.__version__))

            msg_box = ErrorReport(gettext("Error"), True,
                                  traceback_file.getvalue(), exc_info, type,
                                  window)
        else:
            msg_box = ErrorReport(gettext("Error"), False, err_file.getvalue(),
                                  exc_info, type, window)
        if window is None:
            icon = QtGui.QIcon()
            icon.addFile(":/bzr-16.png", QtCore.QSize(16, 16))
            icon.addFile(":/bzr-32.png", QtCore.QSize(32, 32))
            icon.addFile(":/bzr-48.png", QtCore.QSize(48, 48))
            msg_box.setWindowIcon(icon)

        msg_box.exec_()

        if not msg_box.result() == QtGui.QMessageBox.Close:
            close = False

    if close:
        if window is None:
            closing_due_to_error = True
            QtCore.QCoreApplication.instance().quit()
        else:
            window.closing_due_to_error = True
            window.close()
    return error_type