Mercurial > libervia-backend
annotate src/bridge/bridge_constructor/constructors/dbus-xml/constructor.py @ 2463:65a6d2496504
plugin identity: return resource for MUC room occupants' nicks + added avatar and avatar_basename.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 03 Jan 2018 00:20:21 +0100 |
parents | 8b37a62336c3 |
children | 0046283a285d |
rev | line source |
---|---|
2085 | 1 #!/usr/bin/env python2 |
2 #-*- coding: utf-8 -*- | |
3 | |
4 # SàT: a XMPP client | |
2414
8b37a62336c3
misc: date update (yes it's a bit late :p )
Goffi <goffi@goffi.org>
parents:
2085
diff
changeset
|
5 # Copyright (C) 2009-2017 Jérôme Poisson (goffi@goffi.org) |
2085 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 from sat.bridge.bridge_constructor import base_constructor | |
21 from xml.dom import minidom | |
22 import sys | |
23 | |
24 | |
25 class DbusXmlConstructor(base_constructor.Constructor): | |
26 """Constructor for DBus XML syntaxt (used by Qt frontend)""" | |
27 | |
28 def __init__(self, bridge_template, options): | |
29 base_constructor.Constructor.__init__(self, bridge_template, options) | |
30 | |
31 self.template = "dbus_xml_template.xml" | |
32 self.core_dest = "org.goffi.sat.xml" | |
33 self.default_annotation = {'a{ss}': 'StringDict', | |
34 'a(sa{ss}as)': 'QList<Contact>', | |
35 'a{i(ss)}': 'HistoryT', | |
36 'a(sss)': 'QList<MenuT>', | |
37 'a{sa{s(sia{ss})}}': 'PresenceStatusT', | |
38 } | |
39 | |
40 def generateCoreSide(self): | |
41 try: | |
42 doc = minidom.parse(self.getTemplatePath(self.template)) | |
43 interface_elt = doc.getElementsByTagName('interface')[0] | |
44 except IOError: | |
45 print ("Can't access template") | |
46 sys.exit(1) | |
47 except IndexError: | |
48 print ("Template error") | |
49 sys.exit(1) | |
50 | |
51 sections = self.bridge_template.sections() | |
52 sections.sort() | |
53 for section in sections: | |
54 function = self.getValues(section) | |
55 print ("Adding %s %s" % (section, function["type"])) | |
56 new_elt = doc.createElement('method' if function["type"] == 'method' else 'signal') | |
57 new_elt.setAttribute('name', section) | |
58 | |
59 idx = 0 | |
60 args_doc = self.getArgumentsDoc(section) | |
61 for arg in self.argumentsParser(function['sig_in'] or ''): | |
62 arg_elt = doc.createElement('arg') | |
63 arg_elt.setAttribute('name', args_doc[idx][0] if idx in args_doc else "arg_%i" % idx) | |
64 arg_elt.setAttribute('type', arg) | |
65 _direction = 'in' if function["type"] == 'method' else 'out' | |
66 arg_elt.setAttribute('direction', _direction) | |
67 new_elt.appendChild(arg_elt) | |
68 if "annotation" in self.args.flags: | |
69 if arg in self.default_annotation: | |
70 annot_elt = doc.createElement("annotation") | |
71 annot_elt.setAttribute('name', "com.trolltech.QtDBus.QtTypeName.In%d" % idx) | |
72 annot_elt.setAttribute('value', self.default_annotation[arg]) | |
73 new_elt.appendChild(annot_elt) | |
74 idx += 1 | |
75 | |
76 if function['sig_out']: | |
77 arg_elt = doc.createElement('arg') | |
78 arg_elt.setAttribute('type', function['sig_out']) | |
79 arg_elt.setAttribute('direction', 'out') | |
80 new_elt.appendChild(arg_elt) | |
81 if "annotation" in self.args.flags: | |
82 if function['sig_out'] in self.default_annotation: | |
83 annot_elt = doc.createElement("annotation") | |
84 annot_elt.setAttribute('name', "com.trolltech.QtDBus.QtTypeName.Out0") | |
85 annot_elt.setAttribute('value', self.default_annotation[function['sig_out']]) | |
86 new_elt.appendChild(annot_elt) | |
87 | |
88 interface_elt.appendChild(new_elt) | |
89 | |
90 #now we write to final file | |
91 self.finalWrite(self.core_dest, [doc.toprettyxml()]) |