예제 #1
0
파일: startup.py 프로젝트: kmshi/miro
 def wrapped(*args, **kwargs):
     try:
         func(*args, **kwargs)
     except StartupError, e:
         if e.summary is not None:
             m = messages.StartupFailure(e.summary, e.description)
         else:
             m = messages.FrontendQuit()
         m.send_to_frontend()
예제 #2
0
파일: startup.py 프로젝트: kmshi/miro
                        "Start Fresh button and restart %(appname)s.\n\n"
                        "To help us fix problems like this in the future, "
                        "please file a bug report at %(url)s.", {
                            "appname": app.config.get(prefs.SHORT_APP_NAME),
                            "url": app.config.get(prefs.BUG_REPORT_URL),
                            "error": msg
                        }))
                m.send_to_frontend()

            else:
                logging.warn("Unknown startup error: %s",
                             traceback.format_exc())
                m = messages.StartupFailure(
                    _("Unknown Error"),
                    _(
                        "An unknown error prevented %(appname)s from startup.  "
                        "Please file a bug report at %(url)s.", {
                            "appname": app.config.get(prefs.SHORT_APP_NAME),
                            "url": app.config.get(prefs.BUG_REPORT_URL)
                        }))
                m.send_to_frontend()

    return wrapped


def _movies_directory_gone_handler(callback):
    """Default _movies_directory_gone_handler.  The frontend should
    override this using the ``install_movies_directory_gone_handler``
    function.
    """
    logging.error("Movies directory is gone -- no handler installed!")
    eventloop.add_urgent_call(callback, "continuing startup")
예제 #3
0
def startup_function(func):
    """Decorator for startup functions.  This decorator catches exceptions and
    turns them into StartupFailure messages.
    """
    def wrapped(*args, **kwargs):
        try:
            func(*args, **kwargs)
        except StartupError, e:
            if e.summary is not None:
                m = messages.StartupFailure(e.summary, e.description)
            else:
                m = messages.FrontendQuit()
            m.send_to_frontend()
        except StandardError, exc:
            # we do this so that we only kick up the database error
            # if it's a database-related exception AND the app has a
            # db attribute
            if ((isinstance(exc, (database.DatabaseException,
                                  database.DatabaseStandardError,
                                  storedatabase.sqlite3.DatabaseError,
                                  storedatabase.sqlite3.OperationalError))
                 and app.db is not None)):

                # somewhere in one of the startup functions, Miro
                # kicked up a database-related problem.  we don't know
                # where it happend, so we can't just start fresh and
                # keep going.  instead we have to start fresh, shut
                # miro down, and on the next run, maybe miro will
                # work.
                msg = exc.message
                if not msg:
                    msg = str(exc)
                logging.exception("Database error on startup:")
                m = messages.StartupDatabaseFailure(
                    _("Database Error"),
                    _("We're sorry, %(appname)s was unable to start up due "
                      "to a problem with the database:\n\n"
                      "Error: %(error)s\n\n"
                      "It's possible that your database file is corrupted and "
                      "cannot be used.\n\n"
                      "You can start fresh and your damaged database will be "
                      "removed, but you will have to re-add your podcasts and "
                      "media files.  If you want to do this, press the "
                      "Start Fresh button and restart %(appname)s.\n\n"
                      "To help us fix problems like this in the future, "
                      "please file a bug report at %(url)s.",
                      {"appname": app.config.get(prefs.SHORT_APP_NAME),
                       "url": app.config.get(prefs.BUG_REPORT_URL),
                       "error": msg}
                      ))
                m.send_to_frontend()

            else:
                logging.warn(
                    "Unknown startup error: %s", traceback.format_exc())
                m = messages.StartupFailure(
                    _("Unknown Error"),
                    _("An unknown error prevented %(appname)s from startup.  "
                      "Please file a bug report at %(url)s.",
                      {"appname": app.config.get(prefs.SHORT_APP_NAME),
                       "url": app.config.get(prefs.BUG_REPORT_URL)}
                      ))
                m.send_to_frontend()