forked from xbmc/repo-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-index.py
92 lines (63 loc) · 2.48 KB
/
generate-index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#! /usr/bin/python
import os
import xml.etree.ElementTree as ET
import argparse
import codecs
from jinja2 import Template
import Image
REPO_ID = 'repository.russellharrower'
tree = ET.parse("addons.xml").getroot()
template = Template(open('index_template.html').read())
def get_addons():
for addon in sorted(tree, key=lambda element: element.attrib['name']):
a = {}
module = addon.find("extension[@point='xbmc.python.module']")
if module is not None:
continue
repo = addon.find("extension[@point='xbmc.addon.repository']")
if repo is not None:
a['types'] = ['repository']
plugin = addon.find("extension[@point='xbmc.python.pluginsource']")
if plugin is not None:
a['types'] = plugin.find('provides').text.split()
script = addon.find("extension[@point='xbmc.python.script']")
if script is not None:
a['types'] = ['program']
skin = addon.find("extension[@point='xbmc.gui.skin']")
if skin is not None:
a['types'] = ['skin']
for attrib in ('id', 'name', 'version', 'provider-name'):
a[attrib] = addon.get(attrib)
a['icon'] = os.path.join(a['id'], 'icon.png')
metadata = addon.find("extension[@point='xbmc.addon.metadata']")
data = metadata.find("summary[@lang='en']")
if data is None:
data = metadata.find("summary")
if data is not None:
a['summary'] = data.text
data = metadata.find("description[@lang='en']")
if data is None:
data = metadata.find("description")
if data is not None:
a['description'] = [line for line in data.text.splitlines() if line]
for key in ('website', 'forum', 'source'):
data = metadata.find(key)
if data is not None:
a[key] = data.text
yield a
addons = {}
repo = None
for addon in get_addons():
if addon['id'] == REPO_ID:
repo = addon
else:
addon_type = addon['types'][0] # group by first type if multiple types
addons.setdefault(addon_type, []).append(addon)
print addon['name']
text = template.render(repo=repo,
categories=('program', 'video', 'audio', 'image', 'skin'), # define order of categories
addons=addons)
codecs.open('index.html', 'w', 'utf-8').write(text)
im = Image.open(repo['icon'])
im.thumbnail((32, 32), Image.ANTIALIAS)
im.save('favicon.png', 'png')