Mercurial > libervia-backend
annotate sat/bridge/bridge_constructor/constructors/dbus-xml/constructor.py @ 3417:bfe9ebd253a7
plugin app manager: fixed `public_url` value check
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 14 Nov 2020 21:20:48 +0100 |
parents | 559a625a236b |
children | be6d91572633 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
2085 | 3 |
4 # SàT: a XMPP client | |
3136 | 5 # Copyright (C) 2009-2020 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" | |
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 | 40 |
41 def generateCoreSide(self): | |
42 try: | |
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 | 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 | 47 sys.exit(1) |
48 except IndexError: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 print("Template error") |
2085 | 50 sys.exit(1) |
51 | |
52 sections = self.bridge_template.sections() | |
53 sections.sort() | |
54 for section in sections: | |
55 function = self.getValues(section) | |
3028 | 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 | 61 |
62 idx = 0 | |
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 | 72 new_elt.appendChild(arg_elt) |
73 if "annotation" in self.args.flags: | |
74 if arg in self.default_annotation: | |
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 | 80 new_elt.appendChild(annot_elt) |
81 idx += 1 | |
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 | 87 new_elt.appendChild(arg_elt) |
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 | 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 | 97 new_elt.appendChild(annot_elt) |
98 | |
99 interface_elt.appendChild(new_elt) | |
100 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
101 # now we write to final file |
2085 | 102 self.finalWrite(self.core_dest, [doc.toprettyxml()]) |