view backend/sqlalchemy/SqlAlchemyBackend.py @ 124:a4b2077c9603 backend

editing a feed's properties is implemented through the backend now
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 22 Aug 2011 11:02:53 +0200
parents 862760b161b4
children 514e5d7dca98
line wrap: on
line source


from Preferences import Preferences
import Database
import FeedList
import FeedUpdater
import logging
import util

class SqlAlchemyBackend(object):
    '''
    Backend that uses sqlalchemy for persistence
    '''

    def __init__(self):
        self._initLogging()
        self.session = Database.createSession()
        self.prefs = Preferences(self.session)
        self.updater = None

    def _initLogging(self):
        logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN)

        sqlalchemyLogLevel = logging.ERROR
        if util.databaseLoggingEnabled():
            sqlalchemyLogLevel = logging.INFO
        logging.getLogger("sqlalchemy").setLevel(sqlalchemyLogLevel)

    def preferences(self):
        return self.prefs

    def getFeeds(self):
        return FeedList.getFeeds(self.session)

    def toggleRead(self, feedEntry):
        feedEntry.toggleRead()
        self.session.commit()

    def markAllEntriesRead(self, feed):
        feed.markAllEntriesRead()
        self.session.commit()

    def createFeed(self, url):
        try:
            FeedUpdater.createNewFeed(url, self.session)
            self.session.commit()
        except AttributeError as ae:
            self.session.rollback()
            raise ae

    def updateFeed(self, feed, changes):
        feed.takeChangesFrom(changes)
        feed.incrementNextUpdateDate()
        self.session.commit()

    def dispose(self):
        # save all uncommitted state, just in case
        self.session.commit()