Mercurial > libervia-backend
comparison sat/bridge/bridge_constructor/constructors/dbus-xml/constructor.py @ 2624:56f94936df1e
code style reformatting using black
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 20:14:46 +0200 |
parents | 26edcf3a30eb |
children | 779351da2c13 |
comparison
equal
deleted
inserted
replaced
2623:49533de4540b | 2624:56f94936df1e |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python2 |
2 #-*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # SàT: a XMPP client | 4 # SàT: a XMPP client |
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) | 5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) |
6 | 6 |
7 # This program is free software: you can redistribute it and/or modify | 7 # This program is free software: you can redistribute it and/or modify |
28 def __init__(self, bridge_template, options): | 28 def __init__(self, bridge_template, options): |
29 base_constructor.Constructor.__init__(self, bridge_template, options) | 29 base_constructor.Constructor.__init__(self, bridge_template, options) |
30 | 30 |
31 self.template = "dbus_xml_template.xml" | 31 self.template = "dbus_xml_template.xml" |
32 self.core_dest = "org.goffi.sat.xml" | 32 self.core_dest = "org.goffi.sat.xml" |
33 self.default_annotation = {'a{ss}': 'StringDict', | 33 self.default_annotation = { |
34 'a(sa{ss}as)': 'QList<Contact>', | 34 "a{ss}": "StringDict", |
35 'a{i(ss)}': 'HistoryT', | 35 "a(sa{ss}as)": "QList<Contact>", |
36 'a(sss)': 'QList<MenuT>', | 36 "a{i(ss)}": "HistoryT", |
37 'a{sa{s(sia{ss})}}': 'PresenceStatusT', | 37 "a(sss)": "QList<MenuT>", |
38 } | 38 "a{sa{s(sia{ss})}}": "PresenceStatusT", |
39 } | |
39 | 40 |
40 def generateCoreSide(self): | 41 def generateCoreSide(self): |
41 try: | 42 try: |
42 doc = minidom.parse(self.getTemplatePath(self.template)) | 43 doc = minidom.parse(self.getTemplatePath(self.template)) |
43 interface_elt = doc.getElementsByTagName('interface')[0] | 44 interface_elt = doc.getElementsByTagName("interface")[0] |
44 except IOError: | 45 except IOError: |
45 print ("Can't access template") | 46 print("Can't access template") |
46 sys.exit(1) | 47 sys.exit(1) |
47 except IndexError: | 48 except IndexError: |
48 print ("Template error") | 49 print("Template error") |
49 sys.exit(1) | 50 sys.exit(1) |
50 | 51 |
51 sections = self.bridge_template.sections() | 52 sections = self.bridge_template.sections() |
52 sections.sort() | 53 sections.sort() |
53 for section in sections: | 54 for section in sections: |
54 function = self.getValues(section) | 55 function = self.getValues(section) |
55 print ("Adding %s %s" % (section, function["type"])) | 56 print("Adding %s %s" % (section, function["type"])) |
56 new_elt = doc.createElement('method' if function["type"] == 'method' else 'signal') | 57 new_elt = doc.createElement( |
57 new_elt.setAttribute('name', section) | 58 "method" if function["type"] == "method" else "signal" |
59 ) | |
60 new_elt.setAttribute("name", section) | |
58 | 61 |
59 idx = 0 | 62 idx = 0 |
60 args_doc = self.getArgumentsDoc(section) | 63 args_doc = self.getArgumentsDoc(section) |
61 for arg in self.argumentsParser(function['sig_in'] or ''): | 64 for arg in self.argumentsParser(function["sig_in"] or ""): |
62 arg_elt = doc.createElement('arg') | 65 arg_elt = doc.createElement("arg") |
63 arg_elt.setAttribute('name', args_doc[idx][0] if idx in args_doc else "arg_%i" % idx) | 66 arg_elt.setAttribute( |
64 arg_elt.setAttribute('type', arg) | 67 "name", args_doc[idx][0] if idx in args_doc else "arg_%i" % idx |
65 _direction = 'in' if function["type"] == 'method' else 'out' | 68 ) |
66 arg_elt.setAttribute('direction', _direction) | 69 arg_elt.setAttribute("type", arg) |
70 _direction = "in" if function["type"] == "method" else "out" | |
71 arg_elt.setAttribute("direction", _direction) | |
67 new_elt.appendChild(arg_elt) | 72 new_elt.appendChild(arg_elt) |
68 if "annotation" in self.args.flags: | 73 if "annotation" in self.args.flags: |
69 if arg in self.default_annotation: | 74 if arg in self.default_annotation: |
70 annot_elt = doc.createElement("annotation") | 75 annot_elt = doc.createElement("annotation") |
71 annot_elt.setAttribute('name', "com.trolltech.QtDBus.QtTypeName.In%d" % idx) | 76 annot_elt.setAttribute( |
72 annot_elt.setAttribute('value', self.default_annotation[arg]) | 77 "name", "com.trolltech.QtDBus.QtTypeName.In%d" % idx |
78 ) | |
79 annot_elt.setAttribute("value", self.default_annotation[arg]) | |
73 new_elt.appendChild(annot_elt) | 80 new_elt.appendChild(annot_elt) |
74 idx += 1 | 81 idx += 1 |
75 | 82 |
76 if function['sig_out']: | 83 if function["sig_out"]: |
77 arg_elt = doc.createElement('arg') | 84 arg_elt = doc.createElement("arg") |
78 arg_elt.setAttribute('type', function['sig_out']) | 85 arg_elt.setAttribute("type", function["sig_out"]) |
79 arg_elt.setAttribute('direction', 'out') | 86 arg_elt.setAttribute("direction", "out") |
80 new_elt.appendChild(arg_elt) | 87 new_elt.appendChild(arg_elt) |
81 if "annotation" in self.args.flags: | 88 if "annotation" in self.args.flags: |
82 if function['sig_out'] in self.default_annotation: | 89 if function["sig_out"] in self.default_annotation: |
83 annot_elt = doc.createElement("annotation") | 90 annot_elt = doc.createElement("annotation") |
84 annot_elt.setAttribute('name', "com.trolltech.QtDBus.QtTypeName.Out0") | 91 annot_elt.setAttribute( |
85 annot_elt.setAttribute('value', self.default_annotation[function['sig_out']]) | 92 "name", "com.trolltech.QtDBus.QtTypeName.Out0" |
93 ) | |
94 annot_elt.setAttribute( | |
95 "value", self.default_annotation[function["sig_out"]] | |
96 ) | |
86 new_elt.appendChild(annot_elt) | 97 new_elt.appendChild(annot_elt) |
87 | 98 |
88 interface_elt.appendChild(new_elt) | 99 interface_elt.appendChild(new_elt) |
89 | 100 |
90 #now we write to final file | 101 # now we write to final file |
91 self.finalWrite(self.core_dest, [doc.toprettyxml()]) | 102 self.finalWrite(self.core_dest, [doc.toprettyxml()]) |