changeset 42:7d088c61e131

Make choice of backend an option to mktap. This includes the database configuration.
author Ralph Meijer <ralphm@ik.nu>
date Sun, 31 Oct 2004 21:12:55 +0000
parents ea3d3544a52e
children 9685b7e291ef
files idavoll/idavoll.py idavoll/tap.py
diffstat 2 files changed, 23 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/idavoll/idavoll.py	Sun Oct 31 21:11:03 2004 +0000
+++ b/idavoll/idavoll.py	Sun Oct 31 21:12:55 2004 +0000
@@ -2,7 +2,6 @@
 from twisted.application import service
 from twisted.python import components
 import backend
-import memory_backend
 import pubsub
 import xmpp_error
 
@@ -88,8 +87,14 @@
     sm = component.buildServiceManager(config["jid"], config["secret"],
             ("tcp:%s:%s" % (config["rhost"], config["rport"])))
 
-    b = memory_backend
-    bs = b.BackendService()
+    if config['backend'] == 'pgsql':
+        import pgsql_backend as b
+        st = b.Storage(user=config['dbuser'], database=config['dbname'])
+        bs = b.BackendService(st)
+    elif config['backend'] == 'memory':
+        import memory_backend as b
+        bs = b.BackendService()
+
 
     component.IService(bs).setServiceParent(sm)
 
@@ -101,13 +106,14 @@
     bsc.setServiceParent(bs)
     component.IService(bsc).setServiceParent(sm)
 
-    bsc = b.NodeCreationService()
-    bsc.setServiceParent(bs)
-    component.IService(bsc).setServiceParent(sm)
+    if config['backend'] == 'memory':
+        bsc = b.NodeCreationService()
+        bsc.setServiceParent(bs)
+        component.IService(bsc).setServiceParent(sm)
 
-    bsc = b.SubscriptionService()
-    bsc.setServiceParent(bs)
-    component.IService(bsc).setServiceParent(sm)
+        bsc = b.SubscriptionService()
+        bsc.setServiceParent(bs)
+        component.IService(bsc).setServiceParent(sm)
 
     s = IdavollService()
     s.setServiceParent(sm)
--- a/idavoll/tap.py	Sun Oct 31 21:11:03 2004 +0000
+++ b/idavoll/tap.py	Sun Oct 31 21:12:55 2004 +0000
@@ -8,8 +8,15 @@
 		('jid', None, 'pubsub'),
 		('secret', None, None),
 		('rhost', None, '127.0.0.1'),
-		('rport', None, '6000')
+		('rport', None, '6000'),
+		('backend', None, 'memory'),
+		('dbuser', None, ''),
+		('dbname', None, 'pubsub'),
 	]
+	
+	def postOptions(self):
+		if self['backend'] not in ['pgsql', 'memory']:
+			raise usage.UsageError, "Unknown backend!"
 
 def makeService(config):
 	return idavoll.makeService(config)