Example #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:
Example #2
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: