Esempio n. 1
0
def on_error(exc_type, exc_value, exc_tb):
    """Run when the application crashes. Display to the user, log it, and quit."""
    # We don't want this to fail, so import everything here, and wrap in
    # except Exception.
    import traceback

    # Close loading screens if they're visible..
    try:
        import loadScreen
        loadScreen.close_all()
    except Exception:
        pass

    err = ''.join(traceback.format_exception(exc_type, exc_value, exc_tb))

    # Grab and release the grab so nothing else can block the error message.
    try:
        TK_ROOT.grab_set_global()
        TK_ROOT.grab_release()

        # Append traceback to the clipboard.
        TK_ROOT.clipboard_append(err)
    except Exception:
        pass

    if not issubclass(exc_type, Exception):
        # It's subclassing BaseException (KeyboardInterrupt, SystemExit),
        # so ignore the error.
        return

    # Put it onscreen.
    try:
        from tkinter import messagebox
        messagebox.showinfo(
            title='BEE2 Error!',
            message='An error occurred: \n{}\n\nThis has '
            'been copied to the clipboard.'.format(err),
            icon=messagebox.ERROR,
        )
    except Exception:
        pass

    try:
        from BEE2_config import GEN_OPTS
        # Try to turn on the logging window for next time..
        GEN_OPTS.load()
        GEN_OPTS['Debug']['show_log_win'] = '1'
        GEN_OPTS['Debug']['window_log_level'] = 'DEBUG'
        GEN_OPTS.save()
    except Exception:
        # Ignore failures...
        pass
Esempio n. 2
0
def on_error(
    exc_type: Type[BaseException],
    exc_value: BaseException,
    exc_tb: TracebackType,
) -> None:
    """Run when the application crashes. Display to the user, log it, and quit."""
    # We don't want this to fail, so import everything here, and wrap in
    # except Exception.
    import traceback
    err = ''.join(traceback.format_exception(exc_type, exc_value, exc_tb))

    # Grab and release the grab so nothing else can block the error message.
    try:
        TK_ROOT.grab_set_global()
        TK_ROOT.grab_release()

        # Append traceback to the clipboard.
        TK_ROOT.clipboard_append(err)
    except Exception:
        pass

    if not issubclass(exc_type, Exception):
        # It's subclassing BaseException (KeyboardInterrupt, SystemExit),
        # so ignore the error.
        return

    # Put it onscreen.
    try:
        from tkinter import messagebox
        from localisation import gettext
        messagebox.showinfo(
            title=gettext('BEEMOD {} Error!').format(utils.BEE_VERSION),
            message=gettext(
                'An error occurred: \n{}\n\n'
                'This has been copied to the clipboard.').format(err),
            icon=messagebox.ERROR,
        )
    except Exception:
        pass

    try:
        from BEE2_config import GEN_OPTS
        # Try to turn on the logging window for next time..
        GEN_OPTS.load()
        GEN_OPTS['Debug']['show_log_win'] = '1'
        GEN_OPTS['Debug']['window_log_level'] = 'DEBUG'
        GEN_OPTS.save()
    except Exception:
        # Ignore failures...
        pass
Esempio n. 3
0
def on_error(exc_type, exc_value, exc_tb):
    """Run when the application crashes. Display to the user, log it, and quit."""
    # We don't want this to fail, so import everything here, and wrap in
    # except Exception.
    import traceback

    # Close loading screens if they're visible..
    try:
        import loadScreen
        loadScreen.close_all()
    except Exception:
        pass

    err = ''.join(traceback.format_exception(exc_type, exc_value, exc_tb))

    # Grab and release the grab so nothing else can block the error message.
    try:
        TK_ROOT.grab_set_global()
        TK_ROOT.grab_release()

        # Append traceback to the clipboard.
        TK_ROOT.clipboard_append(err)
    except Exception:
        pass

    # Put it onscreen.
    try:
        from tkinter import messagebox
        messagebox.showinfo(
            title='BEE2 Error!',
            message='An error occurred: \n{}\n\nThis has '
                    'been copied to the clipboard.'.format(err),
            icon=messagebox.ERROR,
        )
    except Exception:
        pass

    try:
        from BEE2_config import GEN_OPTS
        # Try to turn on the logging window for next time..
        GEN_OPTS.load()
        GEN_OPTS['Debug']['show_log_win'] = '1'
        GEN_OPTS['Debug']['window_log_level'] = 'DEBUG'
        GEN_OPTS.save()
    except Exception:
        # Ignore failures...
        pass
Esempio n. 4
0
def update_modtimes():
    """Update the cache modification times, so next time we don't extract.

    This should only be done if we've copied all the files.
    """
    import time
    from BEE2_config import GEN_OPTS
    LOGGER.info('Setting modtimes..')
    for pack in packageLoader.packages.values():
        # Set modification times for each package.
        pack.set_modtime()

    # Reset package cache times for removed packages. This ensures they'll be
    # detected if re-added.
    for pak_id in packageLoader.PACK_CONFIG:
        if pak_id not in packageLoader.packages:
            packageLoader.PACK_CONFIG[pak_id]['ModTime'] = '0'

    # Set the overall cache time to now.
    GEN_OPTS['General']['cache_time'] = str(int(time.time()))
    GEN_OPTS['General']['cache_pack_count'] = str(len(packageLoader.packages))

    packageLoader.PACK_CONFIG.save()
    GEN_OPTS.save()
Esempio n. 5
0
def update_modtimes():
    """Update the cache modification times, so next time we don't extract.

    This should only be done if we've copied all the files.
    """
    import time
    from BEE2_config import GEN_OPTS
    LOGGER.info('Setting modtimes..')
    for pack in packageLoader.packages.values():
        # Set modification times for each package.
        pack.set_modtime()

    # Reset package cache times for removed packages. This ensures they'll be
    # detected if re-added.
    for pak_id in packageLoader.PACK_CONFIG:
        if pak_id not in packageLoader.packages:
            packageLoader.PACK_CONFIG[pak_id]['ModTime'] = '0'

    # Set the overall cache time to now.
    GEN_OPTS['General']['cache_time'] = str(int(time.time()))
    GEN_OPTS['General']['cache_pack_count'] = str(len(packageLoader.packages))

    packageLoader.PACK_CONFIG.save()
    GEN_OPTS.save()