Mercurial > hg > Feedworm
comparison backend/sqlalchemy/SqlAlchemyBackend.py @ 155:a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sat, 27 Aug 2011 08:52:03 +0200 |
parents | 2682db280be0 |
children | a3c945ce434c |
comparison
equal
deleted
inserted
replaced
154:2682db280be0 | 155:a05719a6175e |
---|---|
1 | 1 |
2 from Feed import Feed | 2 from Feed import Feed |
3 from FeedEntry import FeedEntry | 3 from FeedEntry import FeedEntry |
4 from Preferences import Preferences | 4 from Preferences import Preferences |
5 from backend.AbstractBackend import AbstractBackend | |
5 from datetime import datetime, timedelta | 6 from datetime import datetime, timedelta |
6 from sqlalchemy.orm import joinedload | 7 from sqlalchemy.orm import joinedload |
7 from sqlalchemy.sql import and_ | 8 from sqlalchemy.sql import and_ |
8 import Database | 9 import Database |
9 import FeedUpdater | 10 import FeedUpdater |
10 import Mapping | 11 import Mapping |
11 import logging | 12 import logging |
12 import util | 13 import util |
13 | 14 |
14 class SqlAlchemyBackend(object): | 15 class SqlAlchemyBackend(AbstractBackend): |
15 ''' | 16 ''' |
16 Backend that uses sqlalchemy for persistence | 17 Backend that uses sqlalchemy for persistence |
17 ''' | 18 ''' |
18 | 19 |
19 def __init__(self): | 20 def __init__(self): |
21 AbstractBackend.__init__(self) | |
20 self._initLogging() | 22 self._initLogging() |
21 self.session = Database.createSession() | 23 self.session = Database.createSession() |
22 self.prefs = Preferences(self.session) | 24 self.prefs = Preferences(self.session) |
23 self.updater = None | 25 self.updater = None |
24 self.feeds = [] | |
25 self.selectedFeed = None | |
26 self.feedEntries = None | |
27 self.selectedFeedEntry = None | |
28 | 26 |
29 def _initLogging(self): | 27 def _initLogging(self): |
30 logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN) | 28 logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN) |
31 | 29 |
32 sqlalchemyLogLevel = logging.ERROR | 30 sqlalchemyLogLevel = logging.ERROR |
62 def _collectFeeds(self, feedEntries): | 60 def _collectFeeds(self, feedEntries): |
63 feeds = [entry.feed for entry in feedEntries] | 61 feeds = [entry.feed for entry in feedEntries] |
64 uniqueFeeds = set(feeds) | 62 uniqueFeeds = set(feeds) |
65 return list(uniqueFeeds) | 63 return list(uniqueFeeds) |
66 | 64 |
67 def selectFeed(self, index): | 65 def _retrieveEntriesForSelectedFeed(self, hideReadEntries): |
68 self.selectedFeed = self.feeds[index] | 66 return self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries) |
69 self.feedEntries = None | |
70 return self.selectedFeed | |
71 | |
72 def entriesForSelectedFeed(self): | |
73 hideReadEntries = self.prefs.hideReadFeedEntries() | |
74 if self.feedEntries is None: | |
75 self.feedEntries = self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries) | |
76 return self.feedEntries | |
77 | 67 |
78 def markSelectedFeedAsRead(self): | 68 def markSelectedFeedAsRead(self): |
79 self.selectedFeed.markAllEntriesRead() | 69 self.selectedFeed.markAllEntriesRead() |
80 self.session.commit() | 70 self.session.commit() |
81 | 71 |
101 self.session.commit() | 91 self.session.commit() |
102 | 92 |
103 # | 93 # |
104 # handling of the selected feed entry | 94 # handling of the selected feed entry |
105 # | 95 # |
106 def selectFeedEntry(self, index): | 96 |
107 self.selectedFeedEntry = self.feedEntries[index] | 97 def _markSelectedFeedEntryRead(self): |
108 self.selectedFeedEntry.markRead() | 98 self.selectedFeedEntry.markRead() |
109 return self.selectedFeedEntry | |
110 | 99 |
111 def markFeedEntriesAsRead(self, indices): | 100 def markFeedEntriesAsRead(self, indices): |
112 for index in indices: | 101 for index in indices: |
113 self.feedEntries[index].markRead() | 102 self.feedEntries[index].markRead() |
114 self.session.commit() | 103 self.session.commit() |
115 | 104 |
116 def toggleSelectedFeedEntryRead(self): | 105 def toggleSelectedFeedEntryRead(self): |
117 self.selectedFeedEntry.toggleRead() | 106 self.selectedFeedEntry.toggleRead() |
118 self.session.commit() | 107 self.session.commit() |
119 | |
120 | 108 |
121 def expireFeedEntries(self): | 109 def expireFeedEntries(self): |
122 logger = logging.getLogger("feedupdater") | 110 logger = logging.getLogger("feedupdater") |
123 expireDate = self._calculateExpireDate() | 111 expireDate = self._calculateExpireDate() |
124 logger.info("expiring entries older than " + str(expireDate)) | 112 logger.info("expiring entries older than " + str(expireDate)) |