Ejemplo n.º 1
0
        # check if database needs an upgrade
        db.metadata.create_all(engine)
        try:
            v = self.session.query(db.Configuration).filter_by(param=u'version').first()    # returns None if table exists && param ISNULL
        except OperationalError, e:
            log.info(e)
            v = 0
        except Exception, e:
            log.error(e)
            v = 0

        if v is not None and v > 1:
            v = int(v.value)
        if v < self.version:
            from dbupgrade import upgrade_database
            if not upgrade_database(self, v, config):
                raise Exception('cannot upgrade database')
        elif v > self.version:
            log.error("database version mismatch (detected:%s; current:%s)", v, self.version)
            gutils.warning(_('This database requires newer version of Griffith.'))
            raise Exception("database version mismatch")


def update_whereclause(query, cond): # {{{
    if cond['loaned'] is True:
        query.append_whereclause(db.Movie.loaned==True)
    if cond['loaned'] is False:
        query.append_whereclause(db.Movie.loaned==False)
    if cond['seen'] is True:
        query.append_whereclause(db.Movie.seen==True)
    if cond['seen'] is False:
Ejemplo n.º 2
0
        try:
            v = self.session.query(
                db.Configuration).filter_by(param=u'version').first(
                )  # returns None if table exists && param ISNULL
        except OperationalError, e:
            log.info(e)
            v = 0
        except Exception, e:
            log.error(e)
            v = 0

        if v is not None and v > 1:
            v = int(v.value)
        if v < self.version:
            from dbupgrade import upgrade_database
            if not upgrade_database(self, v, config):
                raise Exception('cannot upgrade database')
        elif v > self.version:
            log.error("database version mismatch (detected:%s; current:%s)", v,
                      self.version)
            warning(_('This database requires newer version of Griffith.'))
            raise Exception("database version mismatch")

    def dispose(self):
        # close every session and connection so that a sqlite database file can be removed
        # otherwise it will remain opened by the current process and can't be deleted
        try:
            self.session.close()
            self.Session.close_all()
            self.engine.dispose()
            del self.session
Ejemplo n.º 3
0
        # check if database needs an upgrade
        db.metadata.create_all(engine)
        try:
            v = self.session.query(db.Configuration).filter_by(param=u'version').first()    # returns None if table exists && param ISNULL
        except OperationalError, e:
            log.info(str(e))
            v = 0
        except Exception, e:
            log.error(str(e))
            v = 0

        if v is not None and v>1:
            v = int(v.value)
        if v < self.version:
            from dbupgrade import upgrade_database
            if not upgrade_database(self, v, locations, config):
                raise Exception("cannot upgrade database")
        elif v > self.version:
            log.error("database version mismatch (detacted:%s; current:%s)", v, self.version)
            gutils.warning(_('This database requires newer version of Griffith.'))
            raise Exception("database version mismatch")


def update_whereclause(query, cond): # {{{
    if cond['loaned'] is True:
        query.append_whereclause(db.Movie.loaned==True)
    if cond['loaned'] is False:
        query.append_whereclause(db.Movie.loaned==False)
    if cond['seen'] is True:
        query.append_whereclause(db.Movie.seen==True)
    if cond['seen'] is False: