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