Mercurial > libervia-backend
annotate src/bridge/bridge_constructor/bridge_contructor.py @ 313:cc8ffbfe938c
QnD workaround for presence broadcast openfire bug
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 16 Apr 2011 18:06:22 +0200 |
parents | a00e87d48213 |
children | 4402ac630712 |
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 """ |
273
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
38 MANAGED_PROTOCOLES=['dbus','mediawiki'] |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 DEFAULT_PROTOCOLE='dbus' |
273
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
40 FLAGS=['deprecated'] |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 import sys |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 import os |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 from os import path |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 from optparse import OptionParser |
266
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
46 from ConfigParser import SafeConfigParser as Parser |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 from ConfigParser import NoOptionError |
266
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
48 import re |
273
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
49 from datetime import datetime |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 class ParseError(Exception): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 #Used when the signature parsing is going wrong (invalid signature ?) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 pass |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 class Constructor: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 def __init__(self, bridge_template, options): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 self.bridge_template = bridge_template |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 self.options = options |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 def getValues(self, name): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 """Return values of a function in a dict |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 @param name: Name of the function to get |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 @return: dict, each key has the config value or None if the value is not set""" |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 function={} |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 for option in ['type','category','sig_in','sig_out','doc']: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 try: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 value = self.bridge_template.get(name, option) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 except NoOptionError: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 value = None |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 function[option] = value |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 return function |
266
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
74 |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
75 def getDefault(self, name): |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
76 """Return default values of a function in a dict |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
77 @param name: Name of the function to get |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
78 @return: dict, each key is the integer param number (no key if no default value)""" |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
79 default_dict={} |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
80 def_re = re.compile(r"param_(\d+)_default") |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
81 |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
82 for option in self.bridge_template.options(name): |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
83 match = def_re.match(option) |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
84 if match: |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
85 try: |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
86 idx = int(match.group(1)) |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
87 except ValueError: |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
88 raise ParseError("Invalid value [%s] for parameter number" % match.group(1)) |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
89 default_dict[idx] = self.bridge_template.get(name, option) |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
90 |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
91 return default_dict |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 |
273
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
93 def getFlags(self, name): |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
94 """Return list of flags set for this function |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
95 @param name: Name of the function to get |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
96 @return: List of flags (string)""" |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
97 flags=[] |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
98 for option in self.bridge_template.options(name): |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
99 if option in FLAGS: |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
100 flags.append(option) |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
101 return flags |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
102 |
266
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
103 def getArgumentsDoc(self, name): |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
104 """Return documentation of arguments |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
105 @param name: Name of the function to get |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
106 @return: dict, each key is the integer param number (no key if no argument doc), value is a tuple (name, doc)""" |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
107 doc_dict={} |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
108 option_re = re.compile(r"doc_param_(\d+)") |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
109 value_re = re.compile(r"^(\w+): (.*)$", re.MULTILINE | re.DOTALL) |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
110 for option in self.bridge_template.options(name): |
273
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
111 if option == 'doc_return': |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
112 doc_dict['return'] = self.bridge_template.get(name, option) |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
113 continue |
266
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
114 match = option_re.match(option) |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
115 if match: |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
116 try: |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
117 idx = int(match.group(1)) |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
118 except ValueError: |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
119 raise ParseError("Invalid value [%s] for parameter number" % match.group(1)) |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
120 value_match = value_re.match(self.bridge_template.get(name, option)) |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
121 if not value_match: |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
122 raise ParseError("Invalid value for parameter doc [%i]" % idx) |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
123 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
|
124 return doc_dict |
273
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
125 |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
126 def getDoc(self, name): |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
127 """Return documentation of the method |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
128 @param name: Name of the function to get |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
129 @return: string documentation, or None""" |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
130 if self.bridge_template.has_option(name, "doc"): |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
131 return self.bridge_template.get(name, "doc") |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
132 return None |
266
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
133 |
267 | 134 def getArguments(self, signature, name=None, default=None, unicode_protect=False): |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 """Return arguments to user given a signature |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 @param signature: signature in the short form (using s,a,i,b etc) |
267 | 137 @param name: dictionary of arguments name like given by getArguments |
138 @param default: dictionary of default values, like given by getDefault | |
139 @param unicode_protect: activate unicode protection on strings (return strings as unicode(str)) | |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 @return: list of arguments that correspond to a signature (e.g.: "sss" return "arg1, arg2, arg3")""" |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 i=0 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 idx=0 |
267 | 143 attr_string=[] |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 while i<len(signature): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 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
|
146 raise ParseError("Unmanaged attribute type [%c]" % signature[i]) |
267 | 147 |
148 attr_string.append(("unicode(%(name)s)%(default)s" if (unicode_protect and signature[i]=='s') else "%(name)s%(default)s") % { | |
266
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
149 'name':name[idx][0] if (name and name.has_key(idx)) else "arg_%i" % idx, |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
150 'default':"="+default[idx] if (default and default.has_key(idx)) else '' |
267 | 151 }) #give arg_1, arg2, etc or name1, name2=default, etc. \ |
152 #give unicode(arg_1), unicode(arg_2), etc. if unicode_protect is set and arg is a string | |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 idx+=1 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 if signature[i] == 'a': |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 i+=1 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 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
|
158 i+=1 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 continue #we have a simple type for the array |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 opening_car = signature[i] |
266
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
161 assert(opening_car in ['{','(']) |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 closing_car = '}' if opening_car == '{' else ')' |
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 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
|
165 i+=1 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 if i>=len(signature): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 raise ParseError("missing }") |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 if signature[i] == opening_car: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 opening_count+=1 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 if signature[i] == closing_car: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 opening_count-=1 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 if opening_count == 0: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 break |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 i+=1 |
267 | 175 return ", ".join(attr_string) |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 def generateCoreSide(self): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 """create the constructor in SàT core side (backend)""" |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 raise NotImplementedError |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 |
271
0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
181 def generateFrontendSide(self): |
0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
182 """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
|
183 raise NotImplementedError |
0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
184 |
0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
185 def finalWrite(self, filename, file_buf): |
0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
186 """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
|
187 @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
|
188 @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
|
189 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
|
190 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
|
191 sys.exit(1) |
0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
192 try: |
0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
193 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
|
194 os.mkdir(DEST_DIR) |
0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
195 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
|
196 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
|
197 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
|
198 try: |
0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
199 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
|
200 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
|
201 except IOError: |
0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
202 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
|
203 except OSError: |
0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
204 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
|
205 exit(1) |
0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
206 |
273
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
207 class MediawikiConstructor(Constructor): |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
208 |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 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
|
213 |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
214 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
|
215 """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
|
216 @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
|
217 @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
|
218 @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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 wiki=[] |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 else: |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 return "\n".join(wiki) |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
234 |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
235 def _wikiReturn(self, name): |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
236 """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
|
237 @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
|
238 """ |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
239 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
|
240 wiki=[] |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
241 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
|
242 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
|
243 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
|
244 return "\n".join(wiki) |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
245 |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
246 def generateCoreSide(self): |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
247 signals_part = [] |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
248 methods_part = [] |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
249 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
|
250 sections.sort() |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
251 for section in sections: |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
252 function = self.getValues(section) |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
253 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
|
254 default = self.getDefault(section) |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
255 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
|
256 signature_signal = \ |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
257 """\ |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
258 ! scope=row | signature |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
259 | %s |
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 """ % function['sig_in'] |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
262 signature_method = \ |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
263 """\ |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
264 ! scope=row | signature in |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
265 | %s |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
266 |- |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
267 ! scope=row | signature out |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
268 | %s |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
269 |-\ |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
270 """ % (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
|
271 completion = { |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
272 '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
|
273 '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
|
274 'category':function['category'], |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
275 'name':section, |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
276 'doc':self.getDoc(section) or "FIXME: No description available", |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
277 '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
|
278 '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
|
279 '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
|
280 } |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
281 |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
282 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
|
283 dest.append("""\ |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
284 == %(name)s == |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
285 ''%(doc)s'' |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
286 %(deprecated)s |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
287 {| 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
|
288 ! scope=row | category |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
289 | %(category)s |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
290 |- |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
291 %(signature)s |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
292 ! scope=row | parameters |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
293 | |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
294 %(parameters)s%(return)s |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
295 |} |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
296 """ % completion) |
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 #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
|
299 #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
|
300 core_bridge = [] |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
301 try: |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 elif line.startswith('##TIMESTAMP##'): |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
309 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
|
310 else: |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
311 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
|
312 except IOError: |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
313 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
|
314 sys.exit(1) |
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 #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
|
317 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
|
318 |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 class DbusConstructor(Constructor): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 def __init__(self, bridge_template, options): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 Constructor.__init__(self, bridge_template, options) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 self.core_template="dbus_core_template.py" |
267 | 324 self.frontend_template="dbus_frontend_template.py" |
325 self.frontend_dest = self.core_dest="DBus.py" | |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 def generateCoreSide(self): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 signals_part = [] |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 methods_part = [] |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 direct_calls = [] |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 sections = self.bridge_template.sections() |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 sections.sort() |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 for section in sections: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 function = self.getValues(section) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 print ("Adding %s %s" % (section, function["type"])) |
266
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
336 default = self.getDefault(section) |
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
337 arg_doc = self.getArgumentsDoc(section) |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 completion = { |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 'sig_in':function['sig_in'] or '', |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 'sig_out':function['sig_out'] or '', |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
341 'category':'REQ' if function['category'] == 'request' else 'COMM', |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 'name':section, |
267 | 343 '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
|
344 } |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 if function["type"] == "signal": |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 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
|
348 signals_part.append("""\ |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 @dbus.service.signal(const_INT_PREFIX+const_%(category)s_SUFFIX, |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 signature='%(sig_in)s') |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 def %(name)s(self, %(args)s): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 %(body)s |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 """ % completion) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 direct_calls.append("""\ |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 def %(name)s(self, %(args)s): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 self.dbus_bridge.%(name)s(%(args)s) |
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 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 elif function["type"] == "method": |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 completion['debug'] = "" if not self.options.debug else 'debug ("%s")\n%s' % (section,8*' ') |
267 | 361 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc, unicode_protect=self.options.unicode) |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 methods_part.append("""\ |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 @dbus.service.method(const_INT_PREFIX+const_%(category)s_SUFFIX, |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 in_signature='%(sig_in)s', out_signature='%(sig_out)s') |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 def %(name)s(self, %(args)s): |
267 | 366 %(debug)sreturn self.cb["%(name)s"](%(args_result)s) |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 """ % completion) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 #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
|
370 #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
|
371 core_bridge = [] |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 try: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 with open(self.core_template) as core_template: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 for line in core_template: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 if line.startswith('##SIGNALS_PART##'): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 core_bridge.extend(signals_part) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
377 elif line.startswith('##METHODS_PART##'): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 core_bridge.extend(methods_part) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 elif line.startswith('##DIRECT_CALLS##'): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 core_bridge.extend(direct_calls) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 else: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 core_bridge.append(line.replace('\n','')) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 except IOError: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 print ("Can't open template file [%s]" % self.core_template) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 sys.exit(1) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 #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
|
388 self.finalWrite(self.core_dest, core_bridge) |
267 | 389 |
390 def generateFrontendSide(self): | |
391 methods_part = [] | |
392 sections = self.bridge_template.sections() | |
393 sections.sort() | |
394 for section in sections: | |
395 function = self.getValues(section) | |
396 print ("Adding %s %s" % (section, function["type"])) | |
397 default = self.getDefault(section) | |
398 arg_doc = self.getArgumentsDoc(section) | |
399 completion = { | |
400 'sig_in':function['sig_in'] or '', | |
401 'sig_out':function['sig_out'] or '', | |
402 'category':'req' if function['category'] == 'request' else 'comm', | |
403 'name':section, | |
404 'args':self.getArguments(function['sig_in'], name=arg_doc, default=default ) | |
405 } | |
406 | |
407 if function["type"] == "method": | |
408 completion['debug'] = "" if not self.options.debug else 'debug ("%s")\n%s' % (section,8*' ') | |
409 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc) | |
276
a00e87d48213
bridge, bridge constructor: fixed mix stuff
Goffi <goffi@goffi.org>
parents:
273
diff
changeset
|
410 result = "self.db_%(category)s_iface.%(name)s(%(args_result)s)" % completion |
a00e87d48213
bridge, bridge constructor: fixed mix stuff
Goffi <goffi@goffi.org>
parents:
273
diff
changeset
|
411 completion['result'] = ("unicode(%s)" if self.options.unicode and function['sig_out'] == 's' else "%s") % result |
267 | 412 methods_part.append("""\ |
413 def %(name)s(self, %(args)s): | |
276
a00e87d48213
bridge, bridge constructor: fixed mix stuff
Goffi <goffi@goffi.org>
parents:
273
diff
changeset
|
414 %(debug)sreturn %(result)s |
267 | 415 """ % completion) |
416 | |
417 #at this point, methods_part should be filled, | |
418 #we just have to place it in the right part of the template | |
419 frontend_bridge = [] | |
420 try: | |
421 with open(self.frontend_template) as frontend_template: | |
422 for line in frontend_template: | |
423 if line.startswith('##METHODS_PART##'): | |
424 frontend_bridge.extend(methods_part) | |
425 else: | |
426 frontend_bridge.append(line.replace('\n','')) | |
427 except IOError: | |
428 print ("Can't open template file [%s]" % self.frontend_template) | |
429 sys.exit(1) | |
430 | |
431 #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
|
432 self.finalWrite(self.frontend_dest, frontend_bridge) |
267 | 433 |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
434 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
435 class ConstructorError(Exception): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
436 pass |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
437 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
438 class ConstructorFactory: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
439 def create(self, bridge_template, options): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
440 if options.protocole=='dbus': |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
441 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
|
442 elif options.protocole=='mediawiki': |
3b5e856b3a32
Bridge: added mediawiki constructor in bridge constructor, usefull for documentation purpose
Goffi <goffi@goffi.org>
parents:
271
diff
changeset
|
443 return MediawikiConstructor(bridge_template, options) |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
444 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
445 raise ConstructorError('Unknown constructor type') |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
446 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
447 class BridgeConstructor: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
448 def __init__(self): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
449 self.options = None |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
450 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
451 def check_options(self): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
452 """Check command line options""" |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
453 _usage=""" |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
454 %prog [options] |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
455 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
456 %prog --help for options list |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
457 """ |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
458 parser = OptionParser(usage=_usage,version=ABOUT % VERSION) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
459 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
460 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
|
461 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
|
462 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
|
463 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
|
464 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
|
465 help="Use TEMPLATE to generate bridge (default: %default)") |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 parser.add_option("-f", "--force", action="store_true", default=False, |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 help=("Force overwritting of existing files")) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 parser.add_option("-d", "--debug", action="store_true", default=False, |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
469 help=("Add debug information printing")) |
267 | 470 parser.add_option("--no_unicode", action="store_false", dest="unicode", default=True, |
471 help=("Remove unicode type protection from string results")) | |
472 | |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
474 (self.options, args) = parser.parse_args() |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 return args |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 def go(self): |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 self.check_options() |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 self.template = Parser() |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 try: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
481 self.template.readfp(open(self.options.template)) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 except IOError: |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 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
|
484 exit(1) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
485 constructor = ConstructorFactory().create(self.template, self.options) |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
486 if self.options.side == "core": |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 constructor.generateCoreSide() |
267 | 488 elif self.options.side == "frontend": |
489 constructor.generateFrontendSide() | |
265
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
490 |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 if __name__ == "__main__": |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
492 bc = BridgeConstructor() |
b5f1f3dc9ac6
bridge: automatic bridge generator, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
493 bc.go() |