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