annotate sat/bridge/bridge_constructor/constructors/dbus-xml/constructor.py @ 3167:d0fb79f97466

quick frontends (app): added an "ignore_missing" argument to RemoveListener: normally an error is logged when removeListener is call on a inexisting listener, but sometimes listeners are added only in specific scenarios, and it may be handy to try to delete them without having to explictly check that they have been used.
author Goffi <goffi@goffi.org>
date Wed, 12 Feb 2020 19:44:05 +0100
parents 559a625a236b
children be6d91572633
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SàT: a XMPP client
3136
9d0df638c8b4 dates update
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org)
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.bridge.bridge_constructor import base_constructor
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from xml.dom import minidom
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import sys
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
23
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
24
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 class DbusXmlConstructor(base_constructor.Constructor):
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 """Constructor for DBus XML syntaxt (used by Qt frontend)"""
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
27
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 def __init__(self, bridge_template, options):
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 base_constructor.Constructor.__init__(self, bridge_template, options)
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 self.template = "dbus_xml_template.xml"
2628
779351da2c13 core, frontends: replaced org\.goffi namespaces by org.salutatoi + fixed generation:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
32 self.core_dest = "org.salutatoi.sat.xml"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
33 self.default_annotation = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
34 "a{ss}": "StringDict",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
35 "a(sa{ss}as)": "QList<Contact>",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36 "a{i(ss)}": "HistoryT",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
37 "a(sss)": "QList<MenuT>",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
38 "a{sa{s(sia{ss})}}": "PresenceStatusT",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 }
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 def generateCoreSide(self):
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 try:
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 doc = minidom.parse(self.getTemplatePath(self.template))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
44 interface_elt = doc.getElementsByTagName("interface")[0]
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 except IOError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
46 print("Can't access template")
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 sys.exit(1)
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 except IndexError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 print("Template error")
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 sys.exit(1)
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 sections = self.bridge_template.sections()
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 sections.sort()
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 for section in sections:
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 function = self.getValues(section)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
56 print(("Adding %s %s" % (section, function["type"])))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 new_elt = doc.createElement(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 "method" if function["type"] == "method" else "signal"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 new_elt.setAttribute("name", section)
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 idx = 0
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 args_doc = self.getArgumentsDoc(section)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 for arg in self.argumentsParser(function["sig_in"] or ""):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 arg_elt = doc.createElement("arg")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 arg_elt.setAttribute(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 "name", args_doc[idx][0] if idx in args_doc else "arg_%i" % idx
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 arg_elt.setAttribute("type", arg)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 _direction = "in" if function["type"] == "method" else "out"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 arg_elt.setAttribute("direction", _direction)
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 new_elt.appendChild(arg_elt)
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 if "annotation" in self.args.flags:
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 if arg in self.default_annotation:
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 annot_elt = doc.createElement("annotation")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 annot_elt.setAttribute(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 "name", "com.trolltech.QtDBus.QtTypeName.In%d" % idx
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 annot_elt.setAttribute("value", self.default_annotation[arg])
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 new_elt.appendChild(annot_elt)
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 idx += 1
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
82
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 if function["sig_out"]:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 arg_elt = doc.createElement("arg")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 arg_elt.setAttribute("type", function["sig_out"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 arg_elt.setAttribute("direction", "out")
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 new_elt.appendChild(arg_elt)
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 if "annotation" in self.args.flags:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 if function["sig_out"] in self.default_annotation:
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 annot_elt = doc.createElement("annotation")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 annot_elt.setAttribute(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
92 "name", "com.trolltech.QtDBus.QtTypeName.Out0"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 annot_elt.setAttribute(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 "value", self.default_annotation[function["sig_out"]]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 )
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 new_elt.appendChild(annot_elt)
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
98
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 interface_elt.appendChild(new_elt)
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
100
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 # now we write to final file
2085
da4097de5a95 bridge (constructor): refactoring:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 self.finalWrite(self.core_dest, [doc.toprettyxml()])