annotate src/bridge/bridge_constructor/bridge_constructor.py @ 1450:7797dda847ae

plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
author Goffi <goffi@goffi.org>
date Sat, 15 Aug 2015 22:20:43 +0200
parents 069ad98b360d
children d17772b0fe22
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 #-*- coding: utf-8 -*-
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
4 # SAT: a jabber client
1396
069ad98b360d 2015 copyright dates update
Goffi <goffi@goffi.org>
parents: 1290
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org)
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
10 # (at your option) any later version.
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
15 # GNU Affero General Public License for more details.
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 #consts
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 NAME = u"bridge_constructor"
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
22 VERSION = "0.1.0"
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
23 DEST_DIR = "generated"
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
24 ABOUT = NAME + u""" v%s (c) Jérôme Poisson (aka Goffi) 2011
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 ---
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
27 """ + NAME + u""" Copyright (C) 2011 Jérôme Poisson (aka Goffi)
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 This program comes with ABSOLUTELY NO WARRANTY;
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 This is free software, and you are welcome to redistribute it
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 under certain conditions.
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 ---
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 This script construct a SàT bridge using the given protocol
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 """
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
35 MANAGED_PROTOCOLES = ['dbus', 'mediawiki', 'dbus-xml']
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
36 DEFAULT_PROTOCOLE = 'dbus'
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
37 FLAGS = ['deprecated', 'async']
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
39 ENV_OVERRIDE = "SAT_BRIDGE_CONST_" # Prefix used to override a constant
359
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
40
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 import sys
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 import os
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 from optparse import OptionParser
266
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
44 from ConfigParser import SafeConfigParser as Parser
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 from ConfigParser import NoOptionError
266
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
46 import re
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
47 from datetime import datetime
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
48 from xml.dom import minidom
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 class ParseError(Exception):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
52 #Used when the signature parsing is going wrong (invalid signature ?)
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 pass
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
55
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
56 class Constructor(object):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
57
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 def __init__(self, bridge_template, options):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.bridge_template = bridge_template
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self.options = options
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 def getValues(self, name):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 """Return values of a function in a dict
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 @param name: Name of the function to get
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 @return: dict, each key has the config value or None if the value is not set"""
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
66 function = {}
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
67 for option in ['type', 'category', 'sig_in', 'sig_out', 'doc']:
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 try:
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 value = self.bridge_template.get(name, option)
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 except NoOptionError:
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 value = None
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 function[option] = value
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 return function
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
74
266
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
75 def getDefault(self, name):
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
76 """Return default values of a function in a dict
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
77 @param name: Name of the function to get
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
78 @return: dict, each key is the integer param number (no key if no default value)"""
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
79 default_dict = {}
266
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
80 def_re = re.compile(r"param_(\d+)_default")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
81
266
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
82 for option in self.bridge_template.options(name):
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
83 match = def_re.match(option)
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
84 if match:
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
85 try:
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
86 idx = int(match.group(1))
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
87 except ValueError:
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
88 raise ParseError("Invalid value [%s] for parameter number" % match.group(1))
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
89 default_dict[idx] = self.bridge_template.get(name, option)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
90
266
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
91 return default_dict
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
93 def getFlags(self, name):
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
94 """Return list of flags set for this function
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
95 @param name: Name of the function to get
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
96 @return: List of flags (string)"""
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
97 flags = []
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
98 for option in self.bridge_template.options(name):
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
99 if option in FLAGS:
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
100 flags.append(option)
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
101 return flags
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
102
266
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
103 def getArgumentsDoc(self, name):
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
104 """Return documentation of arguments
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
105 @param name: Name of the function to get
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
106 @return: dict, each key is the integer param number (no key if no argument doc), value is a tuple (name, doc)"""
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
107 doc_dict = {}
266
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
108 option_re = re.compile(r"doc_param_(\d+)")
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
109 value_re = re.compile(r"^(\w+): (.*)$", re.MULTILINE | re.DOTALL)
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
110 for option in self.bridge_template.options(name):
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
111 if option == 'doc_return':
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
112 doc_dict['return'] = self.bridge_template.get(name, option)
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
113 continue
266
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
114 match = option_re.match(option)
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
115 if match:
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
116 try:
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
117 idx = int(match.group(1))
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
118 except ValueError:
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
119 raise ParseError("Invalid value [%s] for parameter number" % match.group(1))
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
120 value_match = value_re.match(self.bridge_template.get(name, option))
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
121 if not value_match:
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
122 raise ParseError("Invalid value for parameter doc [%i]" % idx)
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
123 doc_dict[idx] = (value_match.group(1), value_match.group(2))
266
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
124 return doc_dict
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
125
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
126 def getDoc(self, name):
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
127 """Return documentation of the method
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
128 @param name: Name of the function to get
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
129 @return: string documentation, or None"""
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
130 if self.bridge_template.has_option(name, "doc"):
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
131 return self.bridge_template.get(name, "doc")
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
132 return None
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
133
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
134 def argumentsParser(self, signature):
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
135 """Generator which return individual arguments signatures from a global signature"""
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
136 start = 0
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
137 i = 0
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
138
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
139 while i < len(signature):
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
140 if signature[i] not in ['b', 'y', 'n', 'i', 'x', 'q', 'u', 't', 'd', 's', 'a']:
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141 raise ParseError("Unmanaged attribute type [%c]" % signature[i])
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 if signature[i] == 'a':
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
144 i += 1
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
145 if signature[i] != '{' and signature[i] != '(': # FIXME: must manage tuples out of arrays
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
146 i += 1
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
147 yield signature[start:i]
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
148 start = i
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
149 continue # we have a simple type for the array
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150 opening_car = signature[i]
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
151 assert(opening_car in ['{', '('])
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152 closing_car = '}' if opening_car == '{' else ')'
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153 opening_count = 1
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
154 while (True): # we have a dict or a list of tuples
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
155 i += 1
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
156 if i >= len(signature):
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
157 raise ParseError("missing }")
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158 if signature[i] == opening_car:
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
159 opening_count += 1
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
160 if signature[i] == closing_car:
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
161 opening_count -= 1
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
162 if opening_count == 0:
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
163 break
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
164 i += 1
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
165 yield signature[start:i]
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
166 start = i
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
167
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
168 def getArguments(self, signature, name=None, default=None, unicode_protect=False):
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
169 """Return arguments to user given a signature
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
170 @param signature: signature in the short form (using s,a,i,b etc)
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
171 @param name: dictionary of arguments name like given by getArguments
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
172 @param default: dictionary of default values, like given by getDefault
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
173 @param unicode_protect: activate unicode protection on strings (return strings as unicode(str))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
174 @return: list of arguments that correspond to a signature (e.g.: "sss" return "arg1, arg2, arg3")"""
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
175 idx = 0
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
176 attr_string = []
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
177
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
178 for arg in self.argumentsParser(signature):
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
179 attr_string.append(("unicode(%(name)s)%(default)s" if (unicode_protect and arg == 's') else "%(name)s%(default)s") % {
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
180 'name': name[idx][0] if (name and idx in name) else "arg_%i" % idx,
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
181 'default': "=" + default[idx] if (default and idx in default) else ''})
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
182 # give arg_1, arg2, etc or name1, name2=default, etc.
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
183 #give unicode(arg_1), unicode(arg_2), etc. if unicode_protect is set and arg is a string
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
184 idx += 1
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
185
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
186 return ", ".join(attr_string)
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
187
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
188 def generateCoreSide(self):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
189 """create the constructor in SàT core side (backend)"""
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
190 raise NotImplementedError
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
191
271
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
192 def generateFrontendSide(self):
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
193 """create the constructor in SàT frontend side"""
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
194 raise NotImplementedError
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
195
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
196 def finalWrite(self, filename, file_buf):
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
197 """Write the final generated file in DEST_DIR/filename
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
198 @param filename: name of the file to generate
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
199 @param file_buf: list of lines (stings) of the file"""
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
200 if os.path.exists(DEST_DIR) and not os.path.isdir(DEST_DIR):
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
201 print ("The destination dir [%s] can't be created: a file with this name already exists !")
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
202 sys.exit(1)
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
203 try:
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
204 if not os.path.exists(DEST_DIR):
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
205 os.mkdir(DEST_DIR)
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
206 full_path = os.path.join(DEST_DIR, filename)
271
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
207 if os.path.exists(full_path) and not self.options.force:
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
208 print ("The destination file [%s] already exists ! Use --force to overwrite it" % full_path)
271
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
209 try:
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
210 with open(full_path, 'w') as dest_file:
271
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
211 dest_file.write('\n'.join(file_buf))
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
212 except IOError:
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
213 print ("Can't open destination file [%s]" % full_path)
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
214 except OSError:
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
215 print("It's not possible to generate the file, check your permissions")
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
216 exit(1)
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
217
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
218
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
219 class MediawikiConstructor(Constructor):
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
220
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
221 def __init__(self, bridge_template, options):
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
222 Constructor.__init__(self, bridge_template, options)
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
223 self.core_template = "mediawiki_template.tpl"
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
224 self.core_dest = "mediawiki.wiki"
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
225
377
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
226 def _addTextDecorations(self, text):
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
227 """Add text decorations like coloration or shortcuts"""
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
228
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
229 def anchor_link(match):
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
230 link = match.group(1)
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
231 #we add anchor_link for [method_name] syntax:
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
232 if link in self.bridge_template.sections():
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
233 return "[[#%s|%s]]" % (link, link)
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
234 print ("WARNING: found an anchor link to an unknown method")
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
235 return link
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
236
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
237 return re.sub(r"\[(\w+)\]", anchor_link, text)
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
238
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
239 def _wikiParameter(self, name, sig_in):
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
240 """Format parameters with the wiki syntax
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
241 @param name: name of the function
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
242 @param sig_in: signature in
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
243 @return: string of the formated parameters"""
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
244 arg_doc = self.getArgumentsDoc(name)
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
245 arg_default = self.getDefault(name)
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
246 args_str = self.getArguments(sig_in)
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
247 args = args_str.split(', ') if args_str else [] # ugly but it works :)
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
248 wiki = []
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
249 for i in range(len(args)):
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
250 if i in arg_doc:
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
251 name, doc = arg_doc[i]
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
252 doc = '\n:'.join(doc.rstrip('\n').split('\n'))
377
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
253 wiki.append("; %s: %s" % (name, self._addTextDecorations(doc)))
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
254 else:
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
255 wiki.append("; arg_%d: " % i)
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
256 if i in arg_default:
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
257 wiki.append(":''DEFAULT: %s''" % arg_default[i])
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
258 return "\n".join(wiki)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
259
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
260 def _wikiReturn(self, name):
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
261 """Format return doc with the wiki syntax
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
262 @param name: name of the function
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
263 """
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
264 arg_doc = self.getArgumentsDoc(name)
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
265 wiki = []
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
266 if 'return' in arg_doc:
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
267 wiki.append('\n|-\n! scope=row | return value\n|')
377
aa2cd6639e00 Bridge Constructor: added anchor link in mediawiki constructor
Goffi <goffi@goffi.org>
parents: 375
diff changeset
268 wiki.append('<br />\n'.join(self._addTextDecorations(arg_doc['return']).rstrip('\n').split('\n')))
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
269 return "\n".join(wiki)
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
270
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
271 def generateCoreSide(self):
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
272 signals_part = []
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
273 methods_part = []
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
274 sections = self.bridge_template.sections()
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
275 sections.sort()
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
276 for section in sections:
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
277 function = self.getValues(section)
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
278 print ("Adding %s %s" % (section, function["type"]))
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
279 default = self.getDefault(section)
431
482b9bcf0ca4 bridge: typo in bridge constructor
Goffi <goffi@goffi.org>
parents: 423
diff changeset
280 async_msg = """<br />'''This method is asynchronous'''"""
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
281 deprecated_msg = """<br />'''<font color="#FF0000">/!\ WARNING /!\ : This method is deprecated, please don't use it !</font>'''"""
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
282 signature_signal = \
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
283 """\
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
284 ! scope=row | signature
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
285 | %s
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
286 |-\
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
287 """ % function['sig_in']
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
288 signature_method = \
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
289 """\
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
290 ! scope=row | signature in
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
291 | %s
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
292 |-
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
293 ! scope=row | signature out
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
294 | %s
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
295 |-\
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
296 """ % (function['sig_in'], function['sig_out'])
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
297 completion = {
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
298 'signature': signature_signal if function['type'] == "signal" else signature_method,
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
299 'sig_out': function['sig_out'] or '',
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
300 'category': function['category'],
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
301 'name': section,
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
302 'doc': self.getDoc(section) or "FIXME: No description available",
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
303 'async': async_msg if "async" in self.getFlags(section) else "",
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
304 'deprecated': deprecated_msg if "deprecated" in self.getFlags(section) else "",
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
305 'parameters': self._wikiParameter(section, function['sig_in']),
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
306 'return': self._wikiReturn(section) if function['type'] == 'method' else ''}
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
307
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
308 dest = signals_part if function['type'] == "signal" else methods_part
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
309 dest.append("""\
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
310 == %(name)s ==
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
311 ''%(doc)s''
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
312 %(deprecated)s
337
4402ac630712 bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents: 276
diff changeset
313 %(async)s
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
314 {| class="wikitable" style="text-align:left; width:80%%;"
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
315 ! scope=row | category
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
316 | %(category)s
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
317 |-
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
318 %(signature)s
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
319 ! scope=row | parameters
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
320 |
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
321 %(parameters)s%(return)s
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
322 |}
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
323 """ % completion)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
324
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
325 #at this point, signals_part, and methods_part should be filled,
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
326 #we just have to place them in the right part of the template
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
327 core_bridge = []
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
328 try:
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
329 with open(self.core_template) as core_template:
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
330 for line in core_template:
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
331 if line.startswith('##SIGNALS_PART##'):
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
332 core_bridge.extend(signals_part)
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
333 elif line.startswith('##METHODS_PART##'):
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
334 core_bridge.extend(methods_part)
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
335 elif line.startswith('##TIMESTAMP##'):
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
336 core_bridge.append('Generated on %s' % datetime.now())
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
337 else:
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
338 core_bridge.append(line.replace('\n', ''))
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
339 except IOError:
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
340 print ("Can't open template file [%s]" % self.core_template)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
341 sys.exit(1)
273
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
342
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
343 #now we write to final file
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
344 self.finalWrite(self.core_dest, core_bridge)
3b5e856b3a32 Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents: 271
diff changeset
345
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
346
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
347 class DbusConstructor(Constructor):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
348
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
349 def __init__(self, bridge_template, options):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
350 Constructor.__init__(self, bridge_template, options)
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
351 self.core_template = "dbus_core_template.py"
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
352 self.frontend_template = "dbus_frontend_template.py"
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
353 self.frontend_dest = self.core_dest = "DBus.py"
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
354
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
355 def generateCoreSide(self):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
356 signals_part = []
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
357 methods_part = []
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
358 direct_calls = []
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
359 sections = self.bridge_template.sections()
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
360 sections.sort()
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
361 for section in sections:
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
362 function = self.getValues(section)
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
363 print ("Adding %s %s" % (section, function["type"]))
266
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
364 default = self.getDefault(section)
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 265
diff changeset
365 arg_doc = self.getArgumentsDoc(section)
337
4402ac630712 bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents: 276
diff changeset
366 async = "async" in self.getFlags(section)
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
367 completion = {
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
368 'sig_in': function['sig_in'] or '',
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
369 'sig_out': function['sig_out'] or '',
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
370 'category': 'PLUGIN' if function['category'] == 'plugin' else 'CORE',
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
371 'name': section,
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
372 'args': self.getArguments(function['sig_in'], name=arg_doc, default=default)}
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
373
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
374 if function["type"] == "signal":
1024
7e43ea75cce8 bridge (constructor): fixed D-Bus frontend generator for async method without sig_in + fixed --debug option + regenerated bridge to fix bad frontend D-Bus bridge.
Goffi <goffi@goffi.org>
parents: 811
diff changeset
375 completion['body'] = "pass" if not self.options.debug else 'log.debug ("%s")' % section
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
376 signals_part.append("""\
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
377 @dbus.service.signal(const_INT_PREFIX+const_%(category)s_SUFFIX,
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
378 signature='%(sig_in)s')
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
379 def %(name)s(self, %(args)s):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
380 %(body)s
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
381 """ % completion)
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
382 direct_calls.append("""\
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
383 def %(name)s(self, %(args)s):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
384 self.dbus_bridge.%(name)s(%(args)s)
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
385 """ % completion)
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
386
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
387 elif function["type"] == "method":
1024
7e43ea75cce8 bridge (constructor): fixed D-Bus frontend generator for async method without sig_in + fixed --debug option + regenerated bridge to fix bad frontend D-Bus bridge.
Goffi <goffi@goffi.org>
parents: 811
diff changeset
388 completion['debug'] = "" if not self.options.debug else 'log.debug ("%s")\n%s' % (section, 8 * ' ')
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
389 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc, unicode_protect=self.options.unicode)
337
4402ac630712 bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents: 276
diff changeset
390 completion['async_comma'] = ', ' if async and function['sig_in'] else ''
4402ac630712 bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents: 276
diff changeset
391 completion['async_args_def'] = 'callback=None, errback=None' if async else ''
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 419
diff changeset
392 completion['async_args_call'] = 'callback=callback, errback=errback' if async else ''
337
4402ac630712 bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents: 276
diff changeset
393 completion['async_callbacks'] = "('callback', 'errback')" if async else "None"
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
394 methods_part.append("""\
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
395 @dbus.service.method(const_INT_PREFIX+const_%(category)s_SUFFIX,
337
4402ac630712 bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents: 276
diff changeset
396 in_signature='%(sig_in)s', out_signature='%(sig_out)s',
4402ac630712 bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents: 276
diff changeset
397 async_callbacks=%(async_callbacks)s)
4402ac630712 bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents: 276
diff changeset
398 def %(name)s(self, %(args)s%(async_comma)s%(async_args_def)s):
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 419
diff changeset
399 %(debug)sreturn self._callback("%(name)s", %(args_result)s%(async_comma)s%(async_args_call)s)
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
400 """ % completion)
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
401
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
402 #at this point, signals_part, methods_part and direct_calls should be filled,
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
403 #we just have to place them in the right part of the template
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
404 core_bridge = []
359
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
405 const_override_pref = filter(lambda env: env.startswith(ENV_OVERRIDE), os.environ)
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
406 const_override = [env[len(ENV_OVERRIDE):] for env in const_override_pref]
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
407 try:
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
408 with open(self.core_template) as core_template:
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
409 for line in core_template:
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
410 if line.startswith('##SIGNALS_PART##'):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
411 core_bridge.extend(signals_part)
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
412 elif line.startswith('##METHODS_PART##'):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
413 core_bridge.extend(methods_part)
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
414 elif line.startswith('##DIRECT_CALLS##'):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
415 core_bridge.extend(direct_calls)
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
416 else:
359
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
417 if line.startswith('const_'):
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
418 const_name = line[len('const_'):line.find(' = ')]
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
419 if const_name in const_override:
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
420 print ("const %s overriden" % const_name)
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
421 core_bridge.append('const_%s = %s' % (const_name, os.environ[ENV_OVERRIDE + const_name]))
359
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
422 continue
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
423 core_bridge.append(line.replace('\n', ''))
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
424 except IOError:
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
425 print ("Can't open template file [%s]" % self.core_template)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
426 sys.exit(1)
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
427
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
428 #now we write to final file
271
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
429 self.finalWrite(self.core_dest, core_bridge)
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
430
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
431 def generateFrontendSide(self):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
432 methods_part = []
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
433 sections = self.bridge_template.sections()
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
434 sections.sort()
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
435 for section in sections:
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
436 function = self.getValues(section)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
437 print ("Adding %s %s" % (section, function["type"]))
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
438 default = self.getDefault(section)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
439 arg_doc = self.getArgumentsDoc(section)
337
4402ac630712 bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents: 276
diff changeset
440 async = "async" in self.getFlags(section)
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
441 completion = {
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
442 'sig_in': function['sig_in'] or '',
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
443 'sig_out': function['sig_out'] or '',
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
444 'category': 'plugin' if function['category'] == 'plugin' else 'core',
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
445 'name': section,
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
446 'args': self.getArguments(function['sig_in'], name=arg_doc, default=default)}
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
447
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
448 if function["type"] == "method":
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
449 # XXX: we can manage blocking call in the same way as async one: if callback is None the call will be blocking
1024
7e43ea75cce8 bridge (constructor): fixed D-Bus frontend generator for async method without sig_in + fixed --debug option + regenerated bridge to fix bad frontend D-Bus bridge.
Goffi <goffi@goffi.org>
parents: 811
diff changeset
450 completion['debug'] = "" if not self.options.debug else 'log.debug ("%s")\n%s' % (section, 8 * ' ')
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
451 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc)
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
452 completion['async_args'] = 'callback=None, errback=None'
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
453 completion['async_comma'] = ', ' if function['sig_in'] else ''
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
454 completion['error_handler'] = """if callback is None:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
455 error_handler = None
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
456 else:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
457 if errback is None:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
458 errback = log.error
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
459 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
460 """
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
461 if async:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
462 completion['blocking_call'] = ''
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
463 completion['async_args_result'] = 'timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler'
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
464 else:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
465 # XXX: To have a blocking call, we must have not reply_handler, so we test if callback exists, and add reply_handler only in this case
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
466 completion['blocking_call'] = """kwargs={}
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
467 if callback is not None:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
468 kwargs['timeout'] = const_TIMEOUT
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
469 kwargs['reply_handler'] = callback
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
470 kwargs['error_handler'] = error_handler
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
471 """
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
472 completion['async_args_result'] = '**kwargs'
337
4402ac630712 bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents: 276
diff changeset
473 result = "self.db_%(category)s_iface.%(name)s(%(args_result)s%(async_comma)s%(async_args_result)s)" % completion
276
a00e87d48213 bridge, bridge constructor: fixed mix stuff
Goffi <goffi@goffi.org>
parents: 273
diff changeset
474 completion['result'] = ("unicode(%s)" if self.options.unicode and function['sig_out'] == 's' else "%s") % result
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
475 methods_part.append("""\
1024
7e43ea75cce8 bridge (constructor): fixed D-Bus frontend generator for async method without sig_in + fixed --debug option + regenerated bridge to fix bad frontend D-Bus bridge.
Goffi <goffi@goffi.org>
parents: 811
diff changeset
476 def %(name)s(self, %(args)s%(async_comma)s%(async_args)s):
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1237
diff changeset
477 %(error_handler)s%(blocking_call)s%(debug)sreturn %(result)s
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
478 """ % completion)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
479
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
480 #at this point, methods_part should be filled,
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
481 #we just have to place it in the right part of the template
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
482 frontend_bridge = []
359
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
483 const_override_pref = filter(lambda env: env.startswith(ENV_OVERRIDE), os.environ)
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
484 const_override = [env[len(ENV_OVERRIDE):] for env in const_override_pref]
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
485 try:
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
486 with open(self.frontend_template) as frontend_template:
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
487 for line in frontend_template:
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
488 if line.startswith('##METHODS_PART##'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
489 frontend_bridge.extend(methods_part)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
490 else:
359
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
491 if line.startswith('const_'):
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
492 const_name = line[len('const_'):line.find(' = ')]
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
493 if const_name in const_override:
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
494 print ("const %s overriden" % const_name)
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
495 frontend_bridge.append('const_%s = %s' % (const_name, os.environ[ENV_OVERRIDE + const_name]))
359
eb9d33ba4e36 bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents: 337
diff changeset
496 continue
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
497 frontend_bridge.append(line.replace('\n', ''))
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
498 except IOError:
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
499 print ("Can't open template file [%s]" % self.frontend_template)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
500 sys.exit(1)
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
501
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
502 #now we write to final file
271
0288f97334f2 bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents: 267
diff changeset
503 self.finalWrite(self.frontend_dest, frontend_bridge)
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
504
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
505
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
506 class DbusXmlConstructor(Constructor):
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
507 """Constructor for DBus XML syntaxt (used by Qt frontend)"""
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
508
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
509 def __init__(self, bridge_template, options):
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
510 Constructor.__init__(self, bridge_template, options)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
511
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
512 self.template = "dbus_xml_template.xml"
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
513 self.core_dest = "org.goffi.sat.xml"
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
514 self.default_annotation = {'a{ss}': 'StringDict',
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
515 'a(sa{ss}as)': 'QList<Contact>',
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
516 'a{i(ss)}': 'HistoryT',
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
517 'a(sss)': 'QList<MenuT>',
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
518 'a{sa{s(sia{ss})}}': 'PresenceStatusT',
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
519 'a{sa{ss}}': 'ActionResultExtDataT'}
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
520
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
521 def generateCoreSide(self):
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
522 try:
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
523 doc = minidom.parse(self.template)
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
524 interface_elt = doc.getElementsByTagName('interface')[0]
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
525 except IOError:
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
526 print ("Can't access template")
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
527 sys.exit(1)
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
528 except IndexError:
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
529 print ("Template error")
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
530 sys.exit(1)
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
531
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
532 sections = self.bridge_template.sections()
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
533 sections.sort()
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
534 for section in sections:
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
535 function = self.getValues(section)
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
536 print ("Adding %s %s" % (section, function["type"]))
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
537 new_elt = doc.createElement('method' if function["type"] == 'method' else 'signal')
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
538 new_elt.setAttribute('name', section)
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
539 args_in_str = self.getArguments(function['sig_in'])
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
540
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
541 idx = 0
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
542 args_doc = self.getArgumentsDoc(section)
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
543 for arg in self.argumentsParser(function['sig_in'] or ''):
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
544 arg_elt = doc.createElement('arg')
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
545 arg_elt.setAttribute('name', args_doc[idx][0] if idx in args_doc else "arg_%i" % idx)
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
546 arg_elt.setAttribute('type', arg)
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
547 _direction = 'in' if function["type"] == 'method' else 'out'
375
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
548 arg_elt.setAttribute('direction', _direction)
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
549 new_elt.appendChild(arg_elt)
375
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
550 if "annotation" in self.options.flags:
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
551 if arg in self.default_annotation:
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
552 annot_elt = doc.createElement("annotation")
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
553 annot_elt.setAttribute('name', "com.trolltech.QtDBus.QtTypeName.In%d" % idx)
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
554 annot_elt.setAttribute('value', self.default_annotation[arg])
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
555 new_elt.appendChild(annot_elt)
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
556 idx += 1
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
557
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
558 if function['sig_out']:
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
559 arg_elt = doc.createElement('arg')
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
560 arg_elt.setAttribute('type', function['sig_out'])
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
561 arg_elt.setAttribute('direction', 'out')
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
562 new_elt.appendChild(arg_elt)
375
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
563 if "annotation" in self.options.flags:
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
564 if function['sig_out'] in self.default_annotation:
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
565 annot_elt = doc.createElement("annotation")
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
566 annot_elt.setAttribute('name', "com.trolltech.QtDBus.QtTypeName.Out0")
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
567 annot_elt.setAttribute('value', self.default_annotation[function['sig_out']])
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
568 new_elt.appendChild(annot_elt)
374
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
569
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
570 interface_elt.appendChild(new_elt)
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
571
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
572 #now we write to final file
193fd5995430 bridge-constructor: added dbus-xml constructor (used for Qt frontend)
Goffi <goffi@goffi.org>
parents: 371
diff changeset
573 self.finalWrite(self.core_dest, [doc.toprettyxml()])
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
574
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
575
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
576 class ConstructorError(Exception):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
577 pass
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
578
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
579
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
580 class ConstructorFactory(object):
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
581 def create(self, bridge_template, options):
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
582 if options.protocole == 'dbus':
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
583 return DbusConstructor(bridge_template, options)
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
584 elif options.protocole == 'mediawiki':
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
585 return MediawikiConstructor(bridge_template, options)
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
586 elif options.protocole == 'dbus-xml':
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
587 return DbusXmlConstructor(bridge_template, options)
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
588
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
589 raise ConstructorError('Unknown constructor type')
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
590
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
591
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
592 class BridgeConstructor(object):
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
593 def __init__(self):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
594 self.options = None
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
595
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
596 def check_options(self):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
597 """Check command line options"""
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
598 _usage = """
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
599 %prog [options]
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
600
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
601 %prog --help for options list
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
602 """
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
603 parser = OptionParser(usage=_usage, version=ABOUT % VERSION)
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
604
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
605 parser.add_option("-p", "--protocole", action="store", type="string", default=DEFAULT_PROTOCOLE,
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
606 help="Generate bridge using PROTOCOLE (default: %s, possible values: [%s])" % (DEFAULT_PROTOCOLE, ", ".join(MANAGED_PROTOCOLES)))
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
607 parser.add_option("-s", "--side", action="store", type="string", default="core",
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
608 help="Which side of the bridge do you want to make ? (default: %default, possible values: [core, frontend])")
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
609 parser.add_option("-t", "--template", action="store", type="string", default='bridge_template.ini',
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
610 help="Use TEMPLATE to generate bridge (default: %default)")
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
611 parser.add_option("-f", "--force", action="store_true", default=False,
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
612 help=("Force overwritting of existing files"))
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
613 parser.add_option("-d", "--debug", action="store_true", default=False,
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
614 help=("Add debug information printing"))
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
615 parser.add_option("--no_unicode", action="store_false", dest="unicode", default=True,
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
616 help=("Remove unicode type protection from string results"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
617 parser.add_option("--flags", action="store", type="string",
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
618 help=("Constructors' specific flags, comma separated"))
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
619
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
620 (self.options, args) = parser.parse_args()
375
502489e17685 D-Bus constructor: add Constructors specific flags (--flags argument)
Goffi <goffi@goffi.org>
parents: 374
diff changeset
621 self.options.flags = self.options.flags.split(',') if self.options.flags else []
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
622 return args
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
623
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
624 def go(self):
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
625 self.check_options()
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
626 self.template = Parser()
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
627 try:
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
628 self.template.readfp(open(self.options.template))
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
629 except IOError:
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
630 print ("The template file doesn't exist or is not accessible")
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
631 exit(1)
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
632 constructor = ConstructorFactory().create(self.template, self.options)
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
633 if self.options.side == "core":
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
634 constructor.generateCoreSide()
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
635 elif self.options.side == "frontend":
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents: 266
diff changeset
636 constructor.generateFrontendSide()
265
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
637
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
638 if __name__ == "__main__":
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
639 bc = BridgeConstructor()
b5f1f3dc9ac6 bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
640 bc.go()