changeset 133:9e1e6b96d8b0

implement proxyHost/proxyPort in Preferences
author Dirk Olmes <dirk@xanthippe.ping.de>
date Tue, 23 Aug 2011 03:44:08 +0200
parents 63d6d60d37ff
children 40163eac0d27
files backend/couchdb/CouchDbBackend.py backend/couchdb/Preferences.py feedworm-gui.py
diffstat 3 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/backend/couchdb/CouchDbBackend.py	Mon Aug 22 19:51:59 2011 +0200
+++ b/backend/couchdb/CouchDbBackend.py	Tue Aug 23 03:44:08 2011 +0200
@@ -1,6 +1,9 @@
 
+from Preferences import Preferences
 import couchdb
 
+DATABASE = "feedtest"
+
 class CouchDbBackend(object):
     '''
     Backend that uses CouchDB for persistence
@@ -8,10 +11,10 @@
 
     def __init__(self):
         server = couchdb.Server()
-        self.database = server["feedtest"]
+        self.database = server[DATABASE]
 
     def preferences(self):
-        raise Exception("not yet implemented")
+        return Preferences(self.database)
 
     def getFeeds(self):
         raise Exception("not yet implemented")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backend/couchdb/Preferences.py	Tue Aug 23 03:44:08 2011 +0200
@@ -0,0 +1,22 @@
+
+class Preferences(object):
+    def __init__(self, database):
+        self.database = database
+        self.viewResults = self.database.view("feedtest/preference_by_key")
+
+    def _valueForKey(self, key):
+        try:
+            resultsForKey = self.viewResults[key]
+            row = iter(resultsForKey).next()
+            return row.value["value"]
+        except StopIteration:
+            return None
+
+    def isProxyConfigured(self):
+        return self.proxyHost() is not None
+
+    def proxyHost(self):
+        return self._valueForKey("proxyHost")
+
+    def proxyPort(self):
+        return self._valueForKey("proxyPort")
--- a/feedworm-gui.py	Mon Aug 22 19:51:59 2011 +0200
+++ b/feedworm-gui.py	Tue Aug 23 03:44:08 2011 +0200
@@ -3,6 +3,7 @@
 from PyQt4 import QtGui
 from PyQt4.QtNetwork import QNetworkProxy
 from backend.sqlalchemy.SqlAlchemyBackend import SqlAlchemyBackend
+from backend.couchdb.CouchDbBackend import CouchDbBackend
 import logging
 import sys
 
@@ -15,7 +16,8 @@
 
 if __name__ == '__main__':
     logging.basicConfig(level=logging.DEBUG)
-    backend = SqlAlchemyBackend()
+#    backend = SqlAlchemyBackend()
+    backend = CouchDbBackend()
     preferences = backend.preferences()
 
     setupProxy(preferences)