]> git.0d.be Git - empathy.git/blob - ubuntu-online-accounts/cc-plugins/generate-plugins.py
Merge remote-tracking branch 'burton/aggregator'
[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 ##### The plugin itself #####
29
30 def generate_build_block(p):
31     la = 'lib%s_la' % p.protocol.replace('-', '_')
32
33     output = '''%s_SOURCES = \\
34         empathy-accounts-plugin.c \\
35         empathy-accounts-plugin.h \\
36         empathy-accounts-plugin-widget.c \\
37         empathy-accounts-plugin-widget.h
38 %s_LDFLAGS = -module -avoid-version
39 %s_LIBADD = \\
40         $(UOA_LIBS)                                     \\
41         $(top_builddir)/libempathy/libempathy.la \\
42         $(top_builddir)/libempathy-gtk/libempathy-gtk.la
43 ''' % (la, la, la)
44
45     return output
46
47 def generate_makefile_am(plugins):
48     '''Generate Makefile.am'''
49     libs = []
50     build_blocks = []
51
52     for p in plugins:
53         name = '        lib%s.la' % p.protocol
54         libs.append(name)
55
56         build_blocks.append(generate_build_block(p))
57
58     f = open('Makefile.am', 'w')
59
60     f.write(
61 '''# Generated using empathy/ubuntu-online-accounts/cc-plugins/generate-plugins.py
62 # Do NOT edit manually
63 SUBDIRS = providers services app-plugin
64
65 plugindir = $(ACCOUNTS_PROVIDER_PLUGIN_DIR)
66
67 INCLUDES =                                      \\
68         -I$(top_builddir)                       \\
69         -I$(top_srcdir)                         \\
70         -DLOCALEDIR=\\""$(datadir)/locale"\\"   \\
71         $(UOA_CFLAGS)                           \\
72         $(WARN_CFLAGS)                          \\
73         $(ERROR_CFLAGS)                         \\
74         $(DISABLE_DEPRECATED)                   \\
75         $(EMPATHY_CFLAGS)
76
77 plugin_LTLIBRARIES = \\
78 %s \\
79         $(NULL)
80
81 %s''' % ('\\\n'.join(libs), '\n\n'.join(build_blocks)))
82
83 ##### Providers #####
84
85 def generate_provider_file(p):
86     f = open('providers/%s.provider' % p.protocol, 'w')
87
88     f.write(
89 '''<?xml version="1.0" encoding="UTF-8" ?>
90 <!-- Generated using empathy/ubuntu-online-accounts/cc-plugins/generate-plugins.py
91      Do NOT edit manually -->
92 <provider id="%s">
93   <name>%s</name>
94   <icon>%s</icon>
95 </provider>
96 ''' % (p.protocol, p.name, p.icon))
97
98 def generate_providers(plugins):
99     '''generate providers/*.provider files and providers/Makefile.am'''
100
101     providers = []
102     for p in plugins:
103         providers.append('      %s.provider' % p.protocol)
104
105         generate_provider_file(p)
106
107     # providers/Makefile.am
108     f = open('providers/Makefile.am', 'w')
109     f.write(
110 '''# Generated using empathy/ubuntu-online-accounts/cc-plugins/generate-plugins.py
111 # Do NOT edit manually
112 providersdir = $(ACCOUNTS_PROVIDER_FILES_DIR)
113
114 providers_DATA = \\
115 %s \\
116         $(NULL)
117
118 EXTRA_DIST = $(providers_DATA)
119 ''' % ('\\\n'.join(providers)))
120
121 ##### Services #####
122
123 def generate_service_file(p):
124     f = open('services/%s-im.service' % p.protocol, 'w')
125
126     f.write(
127 '''<?xml version="1.0" encoding="UTF-8" ?>
128 <!-- Generated using empathy/ubuntu-online-accounts/cc-plugins/generate-plugins.py
129      Do NOT edit manually -->
130 <service id="%s-im">
131   <type>IM</type>
132   <name>%s</name>
133   <icon>%s</icon>
134   <provider>%s</provider>
135
136   <!-- default settings (account settings have precedence over these) -->
137   <template>
138     <group name="telepathy">
139       <setting name="manager">%s</setting>
140       <setting name="protocol">%s</setting>
141     </group>
142   </template>
143
144 </service>
145 ''' % (p.protocol, p.name, p.icon, p.protocol, p.cm, p.protocol))
146
147 def generate_services(plugins):
148     '''generate services/*-im.service files and services/Makefile.am'''
149
150     services = []
151     for p in plugins:
152         services.append('       %s-im.service' % p.protocol)
153
154         generate_service_file(p)
155
156     # providers/Makefile.am
157     f = open('services/Makefile.am', 'w')
158     f.write(
159 '''# Generated using empathy/ubuntu-online-accounts/cc-plugins/generate-plugins.py
160 # Do NOT edit manually
161 servicesdir = $(ACCOUNTS_SERVICE_FILES_DIR)
162
163 services_DATA = \\
164 %s \\
165         $(NULL)
166
167 EXTRA_DIST = $(services_DATA)
168 ''' % ('\\\n'.join(services)))
169
170 def generate_all():
171     plugins = []
172
173     for name, cm, protocol, icon in ALL:
174         plugins.append(Plugin(name, cm, protocol, icon))
175
176     generate_makefile_am(plugins)
177     generate_providers(plugins)
178     generate_services(plugins)
179
180 if __name__ == '__main__':
181     generate_all()