Beispiel #1
0
def exception_handler(type, value, tb):
    """
    This is a custom exception handler to replace the python original one.
    The idea is to show the user a dialog with the information and let him/her
    decide wether to send the developers a report with additional info.
    The report is created and sent using the callback.
    Since this handler may be called from threads, the dialog must be created
    using gtk idle_add or signals to avoid issues.
    """
    import hashlib
    import platform

    text = StringIO()
    traceback.print_exception(type, value, tb, file=text)
    error_name = text.getvalue().split('\n')[-2]

    excepts = """
    Traceback: %s
    """ % (text.getvalue())

    exception_hash = hashlib.sha256(excepts).hexdigest()
    os_dist = " ".join(platform.dist())
    python_version = platform.python_version()
    faraday_version = CONF.getVersion()

    modules_info = ""
    try:
        import pip
        modules_info = ",".join([
            "%s=%s" % (x.key, x.version)
            for x in pip.get_installed_distributions()
        ])
    except ImportError:
        pass

    python_dist = "Python %s \n Modules: [ %s ]" % (python_version,
                                                    modules_info)

    description = """
    Exception: %s
    Identifier: %s
    Versions: OS: %s,
              Faraday Version: %s
              Python Versions: %s
    """ % (excepts, exception_hash, os_dist, faraday_version, python_dist)

    event = ShowExceptionCustomEvent(description, reportToDevelopers,
                                     error_name)
    model.guiapi.postCustomEvent(event)
    text.seek(0)
    text.truncate()
    del text
Beispiel #2
0
def exception_handler(type, value, tb):
    """
    This is a custom exception handler to replace the python original one.
    The idea is to show the user a dialog with the information and let him/her
    decide wether to send the developers a report with additional info.
    The report is created and sent using the callback.
    Since this handler may be called from threads, the dialog must be created
    using qt custom events to avoid issues.
    """
    import requests
    import hashlib
    import platform
    from pip.commands import freeze

    text = StringIO()
    traceback.print_exception(type, value, tb, file=text)

    excepts = """
    Traceback: %s
    """ % (text.getvalue())

    exception_hash = hashlib.sha256(excepts).hexdigest()
    os_dist = " ".join(platform.dist())
    python_version = platform.python_version()
    modules_info = ",".join([
        "%s=%s" % (x.key, x.version)
        for x in freeze.get_installed_distributions()
    ])

    python_dist = "Python %s \n Modules: [ %s ]" % (python_version,
                                                    modules_info)

    description = """
    Exception: %s
    Identifier: %s
    Versions: OS: %s, 
              Python Versions: %s
    """ % (excepts, exception_hash, os_dist, python_dist)

    event = ShowExceptionCustomEvent(description, reportToDevelopers)
    model.guiapi.postCustomEvent(event)
    text.seek(0)
    text.truncate()
    del text