annotate idavoll/idavoll.py @ 159:6fe78048baf9

Rework error handling, depend on Twisted Words 0.4.0. Twisted Words 0.4.0 introduced support for stanza error handling, much better than the custom error handling in Idavoll. Also, all protocol-level errors were examined and brought up to date with version 1.8 of JEP-0060. As a result of the error examination, the retrieval of default configuration options using <default/> is now supported properly.
author Ralph Meijer <ralphm@ik.nu>
date Wed, 06 Sep 2006 12:38:47 +0000
parents 5191ba7c4df8
children 1701c0e2c707
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
155
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 140
diff changeset
1 # Copyright (c) 2003-2006 Ralph Meijer
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 140
diff changeset
2 # See LICENSE for details.
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 140
diff changeset
3
159
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
4 from twisted.words.protocols.jabber import component, error
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
5 from twisted.application import service
67
cdf17c4d3bf9 Made returning disco info use deferreds.
Ralph Meijer <ralphm@ik.nu>
parents: 63
diff changeset
6 from twisted.internet import defer
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
7 import backend
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
8 import pubsub
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
9 import disco
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
10
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
11 import sys
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
12
155
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 140
diff changeset
13 __version__ = '0.5.0'
140
d79f0816f6c3 Revert changes to error handling into disco calls.
Ralph Meijer <ralphm@ik.nu>
parents: 130
diff changeset
14
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
15 NS_VERSION = 'jabber:iq:version'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
16
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
17 IQ_GET = '/iq[@type="get"]'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
18 IQ_SET = '/iq[@type="set"]'
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
19 VERSION = IQ_GET + '/query[@xmlns="' + NS_VERSION + '"]'
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
20 DISCO_INFO = IQ_GET + '/query[@xmlns="' + disco.NS_INFO + '"]'
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
21 DISCO_ITEMS = IQ_GET + '/query[@xmlns="' + disco.NS_ITEMS + '"]'
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
22
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
23 class IdavollService(component.Service):
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
24
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
25 def componentConnected(self, xmlstream):
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
26 self.xmlstream = xmlstream
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
27 xmlstream.addObserver(VERSION, self.onVersion, 1)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
28 xmlstream.addObserver(DISCO_INFO, self.onDiscoInfo, 1)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
29 xmlstream.addObserver(DISCO_ITEMS, self.onDiscoItems, 1)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
30 xmlstream.addObserver(IQ_GET, self.iqFallback, -1)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
31 xmlstream.addObserver(IQ_SET, self.iqFallback, -1)
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
32
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
33 def get_disco_info(self, node):
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
34 info = []
57
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
35
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
36 if not node:
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
37 info.append(disco.Feature(disco.NS_ITEMS))
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
38 info.append(disco.Feature(NS_VERSION))
57
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
39
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
40 return defer.succeed(info)
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
41
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
42 def onVersion(self, iq):
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
43 iq.swapAttributeValues("to", "from")
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
44 iq["type"] = "result"
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
45 name = iq.addElement("name", None, 'Idavoll')
140
d79f0816f6c3 Revert changes to error handling into disco calls.
Ralph Meijer <ralphm@ik.nu>
parents: 130
diff changeset
46 version = iq.addElement("version", None, __version__)
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
47 self.send(iq)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
48 iq.handled = True
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
49
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
50 def onDiscoInfo(self, iq):
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
51 dl = []
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
52 node = iq.query.getAttribute("node")
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
53
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
54 for c in self.parent:
105
8d8946e67fcb Move to Twisted 2.0.
Ralph Meijer <ralphm@ik.nu>
parents: 102
diff changeset
55 if component.IService.providedBy(c):
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
56 if hasattr(c, "get_disco_info"):
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
57 dl.append(c.get_disco_info(node))
92
878a5b7697f2 Consume errors in DeferredLists.
Ralph Meijer <ralphm@ik.nu>
parents: 91
diff changeset
58 d = defer.DeferredList(dl, fireOnOneErrback=1, consumeErrors=1)
140
d79f0816f6c3 Revert changes to error handling into disco calls.
Ralph Meijer <ralphm@ik.nu>
parents: 130
diff changeset
59 d.addCallback(self._disco_info_results, iq, node)
102
f4d725a94202 Fix bug in how errors are handled in disco info request.
Ralph Meijer <ralphm@ik.nu>
parents: 101
diff changeset
60 d.addErrback(self._error, iq)
67
cdf17c4d3bf9 Made returning disco info use deferreds.
Ralph Meijer <ralphm@ik.nu>
parents: 63
diff changeset
61 d.addCallback(self.send)
cdf17c4d3bf9 Made returning disco info use deferreds.
Ralph Meijer <ralphm@ik.nu>
parents: 63
diff changeset
62
cdf17c4d3bf9 Made returning disco info use deferreds.
Ralph Meijer <ralphm@ik.nu>
parents: 63
diff changeset
63 iq.handled = True
cdf17c4d3bf9 Made returning disco info use deferreds.
Ralph Meijer <ralphm@ik.nu>
parents: 63
diff changeset
64
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
65 def _disco_info_results(self, results, iq, node):
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
66 info = []
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
67 for i in results:
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
68 info.extend(i[1])
67
cdf17c4d3bf9 Made returning disco info use deferreds.
Ralph Meijer <ralphm@ik.nu>
parents: 63
diff changeset
69
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
70 if node and not info:
159
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
71 return error.StanzaError('item-not-found').toResponse(iq)
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
72 else:
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
73 iq.swapAttributeValues("to", "from")
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
74 iq["type"] = "result"
101
b75fcc554358 Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
75 for item in info:
b75fcc554358 Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
76 #domish.Element.addChild should probably do this for all
b75fcc554358 Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
77 # subclasses of Element
b75fcc554358 Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
78 item.parent = iq.query
b75fcc554358 Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
79
b75fcc554358 Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
80 iq.query.addChild(item)
67
cdf17c4d3bf9 Made returning disco info use deferreds.
Ralph Meijer <ralphm@ik.nu>
parents: 63
diff changeset
81
cdf17c4d3bf9 Made returning disco info use deferreds.
Ralph Meijer <ralphm@ik.nu>
parents: 63
diff changeset
82 return iq
cdf17c4d3bf9 Made returning disco info use deferreds.
Ralph Meijer <ralphm@ik.nu>
parents: 63
diff changeset
83
101
b75fcc554358 Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
84 def _error(self, result, iq):
b75fcc554358 Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
85 print "Got error on index %d:" % result.value[1]
b75fcc554358 Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
86 result.value[0].printBriefTraceback()
159
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
87 return error.StanzaError('internal-server-error').toResponse(iq)
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
88
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
89 def onDiscoItems(self, iq):
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
90 dl = []
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
91 node = iq.query.getAttribute("node")
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
92
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
93 for c in self.parent:
105
8d8946e67fcb Move to Twisted 2.0.
Ralph Meijer <ralphm@ik.nu>
parents: 102
diff changeset
94 if component.IService.providedBy(c):
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
95 if hasattr(c, "get_disco_items"):
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
96 dl.append(c.get_disco_items(node))
92
878a5b7697f2 Consume errors in DeferredLists.
Ralph Meijer <ralphm@ik.nu>
parents: 91
diff changeset
97 d = defer.DeferredList(dl, fireOnOneErrback=1, consumeErrors=1)
140
d79f0816f6c3 Revert changes to error handling into disco calls.
Ralph Meijer <ralphm@ik.nu>
parents: 130
diff changeset
98 d.addCallback(self._disco_items_result, iq, node)
102
f4d725a94202 Fix bug in how errors are handled in disco info request.
Ralph Meijer <ralphm@ik.nu>
parents: 101
diff changeset
99 d.addErrback(self._error, iq)
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
100 d.addCallback(self.send)
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
101
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
102 iq.handled = True
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
103
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
104 def _disco_items_result(self, results, iq, node):
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
105 items = []
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
106
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
107 for i in results:
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
108 items.extend(i[1])
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
109
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
110 iq.swapAttributeValues("to", "from")
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
111 iq["type"] = "result"
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
112 iq.query.children = items
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
113
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 67
diff changeset
114 return iq
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
115
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
116 def iqFallback(self, iq):
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
117 if iq.handled == True:
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
118 return
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
119
159
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
120 self.send(error.StanzaError('service-unavailable').toResponse(iq))
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
121
76
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
122 class LogService(component.Service):
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
123
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
124 def transportConnected(self, xmlstream):
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
125 xmlstream.rawDataInFn = self.rawDataIn
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
126 xmlstream.rawDataOutFn = self.rawDataOut
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
127
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
128 def rawDataIn(self, buf):
78
a7196ca7cefd Fixed bug in LogService with non-ascii chars.
Ralph Meijer <ralphm@ik.nu>
parents: 76
diff changeset
129 print "RECV: %s" % unicode(buf, 'utf-8').encode('ascii', 'replace')
76
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
130
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
131 def rawDataOut(self, buf):
78
a7196ca7cefd Fixed bug in LogService with non-ascii chars.
Ralph Meijer <ralphm@ik.nu>
parents: 76
diff changeset
132 print "SEND: %s" % unicode(buf, 'utf-8').encode('ascii', 'replace')
76
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
133
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
134 def makeService(config):
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
135 serviceCollection = service.MultiService()
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
136
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
137 # set up Jabber Component
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
138 sm = component.buildServiceManager(config["jid"], config["secret"],
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
139 ("tcp:%s:%s" % (config["rhost"], config["rport"])))
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
140
76
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
141 if config["verbose"]:
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
142 LogService().setServiceParent(sm)
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 75
diff changeset
143
42
7d088c61e131 Make choice of backend an option to mktap. This includes the database
Ralph Meijer <ralphm@ik.nu>
parents: 35
diff changeset
144 if config['backend'] == 'pgsql':
109
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
145 import pgsql_storage
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
146 st = pgsql_storage.Storage(user=config['dbuser'],
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
147 database=config['dbname'])
42
7d088c61e131 Make choice of backend an option to mktap. This includes the database
Ralph Meijer <ralphm@ik.nu>
parents: 35
diff changeset
148 elif config['backend'] == 'memory':
109
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
149 import memory_storage
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
150 st = memory_storage.Storage()
42
7d088c61e131 Make choice of backend an option to mktap. This includes the database
Ralph Meijer <ralphm@ik.nu>
parents: 35
diff changeset
151
109
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
152 import generic_backend as b
43
9685b7e291ef Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents: 42
diff changeset
153 bs = b.BackendService(st)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
154
97
cf918d581da5 Enable admin to hide all nodes when the service is queried using disco items.
Ralph Meijer <ralphm@ik.nu>
parents: 92
diff changeset
155 c = component.IService(bs)
cf918d581da5 Enable admin to hide all nodes when the service is queried using disco items.
Ralph Meijer <ralphm@ik.nu>
parents: 92
diff changeset
156 c.setServiceParent(sm)
cf918d581da5 Enable admin to hide all nodes when the service is queried using disco items.
Ralph Meijer <ralphm@ik.nu>
parents: 92
diff changeset
157 c.hide_nodes = config["hide-nodes"]
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
158
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
159 bsc = b.PublishService()
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
160 bsc.setServiceParent(bs)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
161 component.IService(bsc).setServiceParent(sm)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
162
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
163 bsc = b.NotificationService()
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
164 bsc.setServiceParent(bs)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
165 component.IService(bsc).setServiceParent(sm)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
166
52
0947b46c0968 Use ISubscriptionService support of PostgreSQL backend.
Ralph Meijer <ralphm@ik.nu>
parents: 43
diff changeset
167 bsc = b.SubscriptionService()
0947b46c0968 Use ISubscriptionService support of PostgreSQL backend.
Ralph Meijer <ralphm@ik.nu>
parents: 43
diff changeset
168 bsc.setServiceParent(bs)
0947b46c0968 Use ISubscriptionService support of PostgreSQL backend.
Ralph Meijer <ralphm@ik.nu>
parents: 43
diff changeset
169 component.IService(bsc).setServiceParent(sm)
0947b46c0968 Use ISubscriptionService support of PostgreSQL backend.
Ralph Meijer <ralphm@ik.nu>
parents: 43
diff changeset
170
57
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
171 bsc = b.NodeCreationService()
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
172 bsc.setServiceParent(bs)
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
173 component.IService(bsc).setServiceParent(sm)
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
174
75
1f7b8b6b8ce9 Enable AffiliationsService for memory backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
175 bsc = b.AffiliationsService()
1f7b8b6b8ce9 Enable AffiliationsService for memory backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
176 bsc.setServiceParent(bs)
1f7b8b6b8ce9 Enable AffiliationsService for memory backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
177 component.IService(bsc).setServiceParent(sm)
63
60e95c60252d Setup AffiliationsService and matching protocol adapter for the pgsql
Ralph Meijer <ralphm@ik.nu>
parents: 57
diff changeset
178
109
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
179 bsc = b.ItemRetrievalService()
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
180 bsc.setServiceParent(bs)
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
181 component.IService(bsc).setServiceParent(sm)
82
758cb81b97ce Enable ItemRetrievalService for pgsql backend.
Ralph Meijer <ralphm@ik.nu>
parents: 78
diff changeset
182
109
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
183 bsc = b.RetractionService()
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
184 bsc.setServiceParent(bs)
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
185 component.IService(bsc).setServiceParent(sm)
85
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 82
diff changeset
186
109
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
187 bsc = b.NodeDeletionService()
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
188 bsc.setServiceParent(bs)
9fb8f0867d02 Use storage.
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
189 component.IService(bsc).setServiceParent(sm)
91
47ee5369c410 Use NodeDeletionService for the pgsql backend.
Ralph Meijer <ralphm@ik.nu>
parents: 89
diff changeset
190
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
191 s = IdavollService()
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
192 s.setServiceParent(sm)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
193
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
194 sm.setServiceParent(serviceCollection)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
195
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
196 # other stuff
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
197
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
198 return sm