annotate idavoll/tap.py @ 167:ef22e4150caa

Move protocol implementations (pubsub, disco, forms) to and depend on wokkel. Author: ralphm Fixes: #4
author Ralph Meijer <ralphm@ik.nu>
date Wed, 03 Oct 2007 12:41:43 +0000
parents 1701c0e2c707
children 96afb248df5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
1 # Copyright (c) 2003-2007 Ralph Meijer
155
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
2 # See LICENSE for details.
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
3
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
4 from twisted.application import service
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
5 from twisted.python import usage
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
6 from twisted.words.protocols.jabber.jid import JID
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
7
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
8 from wokkel.component import Component
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
9 from wokkel.disco import DiscoHandler
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
10 from wokkel.generic import FallbackHandler, VersionHandler
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
11 from wokkel.iwokkel import IPubSubService
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
12
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
13 from idavoll.backend import BackendService
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
14
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
15 __version__ = '0.6.0'
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
17 class Options(usage.Options):
156
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
18 optParameters = [
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
19 ('jid', None, 'pubsub'),
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
20 ('secret', None, 'secret'),
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
21 ('rhost', None, '127.0.0.1'),
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
22 ('rport', None, '5347'),
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
23 ('backend', None, 'memory'),
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
24 ('dbuser', None, ''),
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
25 ('dbname', None, 'pubsub'),
163
1701c0e2c707 Add --dbpass option for passing a password to the PostgreSQL backend.
Ralph Meijer <ralphm@ik.nu>
parents: 156
diff changeset
26 ('dbpass', None, ''),
156
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
27 ]
76
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 42
diff changeset
28
156
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
29 optFlags = [
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
30 ('verbose', 'v', 'Show traffic'),
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
31 ('hide-nodes', None, 'Hide all nodes for disco')
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
32 ]
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
33
156
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
34 def postOptions(self):
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
35 if self['backend'] not in ['pgsql', 'memory']:
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
36 raise usage.UsageError, "Unknown backend!"
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
37
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
38 def makeService(config):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
39 s = service.MultiService()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
40
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
41 cs = Component(config["rhost"], int(config["rport"]),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
42 config["jid"], config["secret"])
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
43 cs.setServiceParent(s)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
44
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
45 cs.factory.maxDelay = 900
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
46
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
47 if config["verbose"]:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
48 cs.logTraffic = True
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
49
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
50 FallbackHandler().setHanderParent(cs)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
51 VersionHandler('Idavoll', __version__).setHanderParent(cs)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
52 DiscoHandler().setHanderParent(cs)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
53
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
54 if config['backend'] == 'pgsql':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
55 from idavoll.pgsql_storage import Storage
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
56 st = Storage(user=config['dbuser'],
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
57 database=config['dbname'],
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
58 password=config['dbpass'])
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
59 elif config['backend'] == 'memory':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
60 from idavoll.memory_storage import Storage
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
61 st = Storage()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
62
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
63 bs = BackendService(st)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
64 bs.setServiceParent(s)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
65
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
66 ps = IPubSubService(bs)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
67 ps.setHanderParent(cs)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
68 ps.hideNodes = config["hide-nodes"]
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
69 ps.serviceJID = JID(config["jid"])
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
70
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
71 return s