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