comparison scripts/list_plugins/list_plugins.py @ 45:2ff373d2571a

add decentralisation schemas + script for listing the plugins
author souliane <souliane@mailoo.org>
date Thu, 28 May 2015 00:33:02 +0200
parents
children cea50c3e94f0
comparison
equal deleted inserted replaced
44:459795d1ab31 45:2ff373d2571a
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 """
4 SàT website: Salut à Toi's presentation website
5 Copyright (C) 2015 Jérôme Poisson (goffi@goffi.org)
6 Copyright (C) 2015 Adrien Cossa (souliane@mailoo.org)
7
8 This file is part of SàT website.
9
10 SàT website is free software: you can redistribute it and/or modify
11 it under the terms of the GNU Affero General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 Foobar is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Affero General Public License for more details.
19
20 You should have received a copy of the GNU Affero General Public License
21 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
22 """
23
24
25 from sat import plugins
26 import pkgutil
27
28 WEBSITE = "/home/souliane/workspace/sat_website"
29
30 HEADER = u"""
31 {% comment %}
32 SàT website: Salut à Toi's presentation website
33 Copyright (C) 2012 Jérôme Poisson (goffi@goffi.org)
34 Copyright (C) 2015 Adrien Cossa (souliane@mailoo.org)
35
36 This file is part of SàT website.
37
38 SàT website is free software: you can redistribute it and/or modify
39 it under the terms of the GNU Affero General Public License as published by
40 the Free Software Foundation, either version 3 of the License, or
41 (at your option) any later version.
42
43 Foobar is distributed in the hope that it will be useful,
44 but WITHOUT ANY WARRANTY; without even the implied warranty of
45 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 GNU Affero General Public License for more details.
47
48 You should have received a copy of the GNU Affero General Public License
49 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
50
51
52 NOTE: this file has been automatically generated by the following script:
53 http://repos.goffi.org/sat_docs/file/tip/scripts/list_plugins/list_plugins.py
54
55 Please avoid manual modification, try to update the script instead! Before /
56 after a regeneration, don't forget to save / merge the manual modifications.
57
58 {% endcomment %}
59 {% load i18n %}
60 """
61
62 import urllib2
63 import lxml.html
64
65 # use it to retrieve the XEP name from the official list
66 XEPS_URL = "http://xmpp.org/xmpp-protocols/xmpp-extensions/"
67
68 def get_infos():
69 result = {}
70 doc = lxml.html.parse(XEPS_URL)
71
72 for loader, module_name, is_pkg in pkgutil.walk_packages(plugins.__path__):
73 module = loader.find_module(module_name).load_module(module_name)
74 infos = getattr(module, 'PLUGIN_INFO')
75
76 if infos['type'] == 'XEP':
77 name = infos['import_name']
78 url = "http://xmpp.org/extensions/%s.html" % name.lower()
79 key = "xep"
80 # use the XEP name as description
81 desc = doc.xpath("//tr[@id='%s']/td" % name.lower().replace("-", ""))[1].text
82 else:
83 name = '{% trans "' + infos['name'] + '" %}'
84 url = None
85 key = "exp"
86 desc = infos['description']
87 if desc.startswith('Implementation of '):
88 desc = desc[18:]
89 desc = '{% trans "' + desc.replace('"', '\\"') + '" %}'
90 result.setdefault(key, []).append((name, url, desc))
91
92 return result
93
94
95 def print_infos(infos, file):
96 with open(file, 'w',) as f:
97 f.write(HEADER.encode("utf-8"))
98 for name, url, desc in infos:
99 name = ('<a href="%s" target="#">%s</a>' % (url, name)) if url else name
100 entry = u"""
101 <div class="row">
102 <div class="col-md-2">%s</div>
103 <div class="col-md-7 feature">%s</div>
104 </div>""" % (name, desc)
105 f.write(entry.encode("utf-8"))
106
107 infos = get_infos()
108 for type_ in ("xep", "exp"):
109 print_infos(infos[type_], "%s/templates/sat_website/specifications_%s.html" % (WEBSITE, type_))