]> git.0d.be Git - empathy.git/blob - ubuntu-online-accounts/cc-plugins/generate-plugins.py
UOA account plugins: move shared code to a shared lib
[empathy.git] / ubuntu-online-accounts / cc-plugins / generate-plugins.py
1 #!/usr/bin/env python
2
3 # (name, CM, protocol, icon)
4 ALL = [
5         ('AIM', 'haze', 'aim', 'aim'),
6         ('GaduGadu', 'haze', 'gadugadu', 'gadugadu'),
7         ('Groupwise', 'haze', 'groupwise', 'groupwise'),
8         ('ICQ', 'haze', 'icq', 'icq'),
9         ('IRC', 'idle', 'irc', 'irc'),
10         ('Jabber', 'gabble', 'jabber', 'jabber'),
11         ('Mxit', 'haze', 'mxit', 'mxit'),
12         ('Myspace', 'haze', 'myspace', 'myspace'),
13         ('SIP', 'sofiasip', 'sip', 'sip'),
14         ('Salut', 'salut', 'local-xmpp', 'people-nearby'),
15         ('Sametime', 'haze', 'sametime', 'sametime'),
16         ('Yahoo Japan', 'haze', 'yahoojp', 'yahoo'),
17         ('Yahoo!', 'haze', 'yahoo', 'yahoo'),
18         ('Zephyr', 'haze', 'zephyr', 'zephyr'),
19       ]
20
21 class Plugin:
22     def __init__(self, name, cm, protocol, icon):
23         self.name = name
24         self.cm = cm
25         self.protocol = protocol
26         self.icon = icon
27
28 ##### account-plugins/ #####
29
30 def magic_replace(text, protocol):
31     p = protocol.replace('-', '_')
32
33     l = protocol.split('-')
34     l = map(str.title, l)
35     camel = ''.join(l)
36
37     text = text.replace('$lower', p)
38     text = text.replace('$UPPER', p.upper())
39     text = text.replace('$Camel', camel)
40
41     return text
42
43 def generate_plugin_header(p):
44     # header
45     f = open('account-plugins/empathy-accounts-plugin-%s.h' % p.protocol, 'w')
46
47     tmp = '''/* # Generated using empathy/ubuntu-online-accounts/cc-plugins/generate-plugins.py
48  * Do NOT edit manually */
49
50 /*
51  * empathy-accounts-plugin-%s.h
52  *
53  * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/>
54  *
55  * This library is free software; you can redistribute it and/or
56  * modify it under the terms of the GNU Lesser General Public
57  * License as published by the Free Software Foundation; either
58  * version 2.1 of the License, or (at your option) any later version.
59  *
60  * This library is distributed in the hope that it will be useful,
61  * but WITHOUT ANY WARRANTY; without even the implied warranty of
62  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
63  * Lesser General Public License for more details.
64  *
65  * You should have received a copy of the GNU Lesser General Public
66  * License along with this library; if not, write to the Free Software
67  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
68  */
69
70
71 #ifndef __EMPATHY_ACCOUNTS_PLUGIN_$UPPER_H__
72 #define __EMPATHY_ACCOUNTS_PLUGIN_$UPPER_H__
73
74 #include "empathy-accounts-plugin.h"
75
76 G_BEGIN_DECLS
77
78 typedef struct _EmpathyAccountsPlugin$Camel EmpathyAccountsPlugin$Camel;
79 typedef struct _EmpathyAccountsPlugin$CamelClass EmpathyAccountsPlugin$CamelClass;
80
81 struct _EmpathyAccountsPlugin$CamelClass
82 {
83   /*<private>*/
84   EmpathyAccountsPluginClass parent_class;
85 };
86
87 struct _EmpathyAccountsPlugin$Camel
88 {
89   /*<private>*/
90   EmpathyAccountsPlugin parent;
91 };
92
93 GType empathy_accounts_plugin_$lower_get_type (void);
94
95 /* TYPE MACROS */
96 #define EMPATHY_TYPE_ACCOUNTS_PLUGIN_$UPPER \\
97   (empathy_accounts_plugin_$lower_get_type ())
98 #define EMPATHY_ACCOUNTS_PLUGIN_$UPPER(obj) \\
99   (G_TYPE_CHECK_INSTANCE_CAST((obj), \\
100     EMPATHY_TYPE_ACCOUNTS_PLUGIN_$UPPER, \\
101     EmpathyAccountsPlugin$Camel))
102 #define EMPATHY_ACCOUNTS_PLUGIN_$UPPER_CLASS(klass) \\
103   (G_TYPE_CHECK_CLASS_CAST((klass), \\
104     EMPATHY_TYPE_ACCOUNTS_PLUGIN_$UPPER, \\
105     EmpathyAccountsPlugin$CamelClass))
106 #define EMPATHY_IS_ACCOUNTS_PLUGIN_$UPPER(obj) \\
107   (G_TYPE_CHECK_INSTANCE_TYPE((obj), \\
108     EMPATHY_TYPE_ACCOUNTS_PLUGIN_$UPPER))
109 #define EMPATHY_IS_ACCOUNTS_PLUGIN_$UPPER_CLASS(klass) \\
110   (G_TYPE_CHECK_CLASS_TYPE((klass), \\
111     EMPATHY_TYPE_ACCOUNTS_PLUGIN_$UPPER))
112 #define EMPATHY_ACCOUNTS_PLUGIN_$UPPER_GET_CLASS(obj) \\
113   (G_TYPE_INSTANCE_GET_CLASS ((obj), \\
114     EMPATHY_TYPE_ACCOUNTS_PLUGIN_$UPPER, \\
115     EmpathyAccountsPlugin$CamelClass))
116
117 GType ap_module_get_object_type (void);
118
119 G_END_DECLS
120
121 #endif /* #ifndef __EMPATHY_ACCOUNTS_PLUGIN_$UPPER_H__*/''' % (p.protocol)
122
123     f.write(magic_replace (tmp, p.protocol))
124
125 def generate_plugin_code(p):
126     # header
127     f = open('account-plugins/empathy-accounts-plugin-%s.c' % p.protocol, 'w')
128
129     tmp = '''/* # Generated using empathy/ubuntu-online-accounts/cc-plugins/generate-plugins.py
130  * Do NOT edit manually */
131
132 /*
133  * empathy-accounts-plugin-%s.c
134  *
135  * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/>
136  *
137  * This library is free software; you can redistribute it and/or
138  * modify it under the terms of the GNU Lesser General Public
139  * License as published by the Free Software Foundation; either
140  * version 2.1 of the License, or (at your option) any later version.
141  *
142  * This library is distributed in the hope that it will be useful,
143  * but WITHOUT ANY WARRANTY; without even the implied warranty of
144  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
145  * Lesser General Public License for more details.
146  *
147  * You should have received a copy of the GNU Lesser General Public
148  * License along with this library; if not, write to the Free Software
149  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
150  */
151
152 #include "config.h"
153
154 #include "empathy-accounts-plugin-%s.h"
155
156 G_DEFINE_TYPE (EmpathyAccountsPlugin$Camel, empathy_accounts_plugin_$lower,\\
157         EMPATHY_TYPE_ACCOUNTS_PLUGIN)
158
159 static void
160 empathy_accounts_plugin_$lower_class_init (
161     EmpathyAccountsPlugin$CamelClass *klass)
162 {
163 }
164
165 static void
166 empathy_accounts_plugin_$lower_init (EmpathyAccountsPlugin$Camel *self)
167 {
168 }
169
170 GType
171 ap_module_get_object_type (void)
172 {
173   return EMPATHY_TYPE_ACCOUNTS_PLUGIN_$UPPER;
174 }''' % (p.protocol, p.protocol)
175
176     f.write(magic_replace (tmp, p.protocol))
177
178 def generate_build_block(p):
179     la = 'lib%s_la' % p.protocol.replace('-', '_')
180
181     output = '''%s_SOURCES = \\
182         empathy-accounts-plugin-%s.c \\
183         empathy-accounts-plugin-%s.h
184 %s_LDFLAGS = -module -avoid-version
185 %s_LIBADD = \\
186         libempathy-uoa-account-plugin.la \\
187         $(top_builddir)/libempathy/libempathy.la \\
188         $(top_builddir)/libempathy-gtk/libempathy-gtk.la
189 ''' % (la, p.protocol, p.protocol, la, la)
190
191     return output
192
193
194 def generate_account_plugins(plugins):
195     '''account-plugins/'''
196     libs = []
197     build_blocks = []
198
199     for p in plugins:
200         # empathy-accounts-plugin-$protocol.[ch]'''
201         generate_plugin_header(p)
202         generate_plugin_code(p)
203
204         name = '        lib%s.la' % p.protocol
205         libs.append(name)
206
207         build_blocks.append(generate_build_block(p))
208
209     # Makefile.am
210     f = open('account-plugins/Makefile.am', 'w')
211
212     f.write(
213 '''# Generated using empathy/ubuntu-online-accounts/cc-plugins/generate-plugins.py
214 # Do NOT edit manually
215 plugindir = $(ACCOUNTS_PROVIDER_PLUGIN_DIR)
216
217 INCLUDES =                                      \\
218         -I$(top_builddir)                       \\
219         -I$(top_srcdir)                         \\
220         -DLOCALEDIR=\\""$(datadir)/locale"\\"   \\
221         $(UOA_CFLAGS)                           \\
222         $(WARN_CFLAGS)                          \\
223         $(ERROR_CFLAGS)                         \\
224         $(DISABLE_DEPRECATED)                   \\
225         $(EMPATHY_CFLAGS)
226
227 pkglib_LTLIBRARIES = libempathy-uoa-account-plugin.la
228
229 # this API is not stable and will never be, so use -release to make the
230 # SONAME of the plugin library change with every Empathy release.
231 libempathy_uoa_account_plugin_la_LDFLAGS = \\
232    -no-undefined \\
233    -release $(VERSION)
234
235 libempathy_uoa_account_plugin_la_SOURCES = \\
236         empathy-accounts-plugin.c \\
237         empathy-accounts-plugin.h \\
238         empathy-accounts-plugin-widget.c \\
239         empathy-accounts-plugin-widget.h
240
241 libempathy_uoa_account_plugin_la_LIBADD = \\
242         $(UOA_LIBS)
243
244 plugin_LTLIBRARIES = \\
245 %s \\
246         $(NULL)
247
248 %s''' % ('\\\n'.join(libs), '\n\n'.join(build_blocks)))
249
250 ##### providers/ #####
251
252 def generate_provider_file(p):
253     f = open('providers/%s.provider' % p.protocol, 'w')
254
255     f.write(
256 '''<?xml version="1.0" encoding="UTF-8" ?>
257 <!-- Generated using empathy/ubuntu-online-accounts/cc-plugins/generate-plugins.py
258      Do NOT edit manually -->
259 <provider id="%s">
260   <name>%s</name>
261   <icon>%s</icon>
262 </provider>
263 ''' % (p.protocol, p.name, p.icon))
264
265 def generate_providers(plugins):
266     '''generate providers/*.provider files and providers/Makefile.am'''
267
268     providers = []
269     for p in plugins:
270         providers.append('      %s.provider' % p.protocol)
271
272         generate_provider_file(p)
273
274     # providers/Makefile.am
275     f = open('providers/Makefile.am', 'w')
276     f.write(
277 '''# Generated using empathy/ubuntu-online-accounts/cc-plugins/generate-plugins.py
278 # Do NOT edit manually
279 providersdir = $(ACCOUNTS_PROVIDER_FILES_DIR)
280
281 providers_DATA = \\
282 %s \\
283         $(NULL)
284
285 EXTRA_DIST = $(providers_DATA)
286 ''' % ('\\\n'.join(providers)))
287
288 ##### services/ #####
289
290 def generate_service_file(p):
291     f = open('services/%s-im.service' % p.protocol, 'w')
292
293     f.write(
294 '''<?xml version="1.0" encoding="UTF-8" ?>
295 <!-- Generated using empathy/ubuntu-online-accounts/cc-plugins/generate-plugins.py
296      Do NOT edit manually -->
297 <service id="%s-im">
298   <type>IM</type>
299   <name>%s</name>
300   <icon>%s</icon>
301   <provider>%s</provider>
302
303   <!-- default settings (account settings have precedence over these) -->
304   <template>
305     <group name="telepathy">
306       <setting name="manager">%s</setting>
307       <setting name="protocol">%s</setting>
308     </group>
309     <group name="auth">
310       <setting name="method">password</setting>
311       <setting name="mechanism">password</setting>
312     </group>
313   </template>
314
315 </service>
316 ''' % (p.protocol, p.name, p.icon, p.protocol, p.cm, p.protocol))
317
318 def generate_services(plugins):
319     '''generate services/*-im.service files and services/Makefile.am'''
320
321     services = []
322     for p in plugins:
323         services.append('       %s-im.service' % p.protocol)
324
325         generate_service_file(p)
326
327     # providers/Makefile.am
328     f = open('services/Makefile.am', 'w')
329     f.write(
330 '''# Generated using empathy/ubuntu-online-accounts/cc-plugins/generate-plugins.py
331 # Do NOT edit manually
332 servicesdir = $(ACCOUNTS_SERVICE_FILES_DIR)
333
334 services_DATA = \\
335 %s \\
336         $(NULL)
337
338 EXTRA_DIST = $(services_DATA)
339 ''' % ('\\\n'.join(services)))
340
341 def generate_all():
342     plugins = []
343
344     for name, cm, protocol, icon in ALL:
345         plugins.append(Plugin(name, cm, protocol, icon))
346
347     generate_account_plugins(plugins)
348     generate_providers(plugins)
349     generate_services(plugins)
350
351 if __name__ == '__main__':
352     generate_all()