-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
98 lines (83 loc) · 4.16 KB
/
build.py
File metadata and controls
98 lines (83 loc) · 4.16 KB
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
93
94
95
96
97
98
"""Generate documentation on selected F-Droid apps."""
from json import load
from glob import glob
from typing import TextIO
from pycountry import countries
# pylint:disable=unspecified-encoding
def flag(lang: str) -> str:
"""Get flag for language."""
lang = lang.upper()
if lang == 'EN':
lang = 'GB'
return countries.get(alpha_2=lang).flag
def header(mado: TextIO, references: dict, headers: dict, lang: str) -> None:
"""Write Markdown header."""
for reference, value in sorted(references.items()):
if reference != lang:
mado.write(f'_{flag(reference)} {value}'
f' [overview-{reference}.md]'
f'(overview-{reference}.md)_\n\n')
mado.write(f'{headers[lang]}\n\n')
def footer(mado: TextIO, footers: dict, lang: str) -> None:
"""Write Markdown footer."""
mado.write(f'{footers[lang]}\n\n')
def read_json() -> tuple:
"""Read the JSON file with all the data."""
with open('data.json') as file:
data = load(file)
return (data['references'], data['headers'], data['footers'],
data['categories'])
# TODO fennec addons
def generate() -> None:
"""Generate files."""
references, headers, footers, categories = read_json()
for lang in sorted(references):
with open(f'overview-{lang}.md', 'w') as mado:
header(mado, references, headers, lang)
mado.write('<table>\n')
icons = set()
for category in categories:
replaces_title = 'Replaces'
if lang == 'nl':
replaces_title = 'Vervangt'
elif lang == 'es':
pass # TODO
mado.write(f'<tr><th colspan="2"><br>{category["name"][lang]}'
f'</th><th><br>{replaces_title}</th></tr>\n')
for app in category['apps']:
icon = f'icons/{app["id"]}.png'
if lang == 'en' and icon in icons:
print(f'WARNING: Duplicate use if icon {icon}')
icons.add(icon)
url = f'https://f-droid.org/en/packages/{app["id"]}'
if 'url' in app:
url = app['url']
mado.write(f'<tr id="{app["id"]}"><td><a target="_blank"'
f' href="{url}"><img alt="icon" width="128px"'
f' src="{icon}"></a></td>\n')
mado.write('<td valign="top"><a target="_blank"'
f' href="{url}"><strong>{app["name"]}'
'</strong></a><br>\n')
links = []
if 'mobile' in app:
links.append(f'<a target="_blank" href="https://github.com/PanderMusubi/fdroid/blob/main/overview-{lang}.md#{app["mobile"]}">MB</a>')
if 'desktop' in app:
links.append(f'<a target="_blank" href="https://github.com/PanderMusubi/foss/blob/main/overview-{lang}.md#{app["desktop"]}">DT</a>')
if 'apt' in app:
links.append(f'<a target="_blank" href="{app["apt"]}">AP</a>')
if 'flathub' in app:
links.append(f'<a target="_blank" href="https://flathub.org/apps/{app["flathub"]}">FH</a>')
if 'snapcraft' in app:
links.append(f'<a target="_blank" href="https://snapcraft.io/{app["snapcraft"]}">SC</a>')
if 'alternativeto' in app:
links.append(f'<a target="_blank" href="https://alternativeto.net/software/{app["alternativeto"]}/about/">AT</a>')
mado.write(f'{app["description"][lang]}<br><small>{" ".join(links)}</small></td>\n')
replaces = app.get('replaces', '')
mado.write(f'<td valign="top"><font color="red">{replaces}</font></td></tr>\n')
mado.write('</table>\n\n')
footer(mado, footers, lang)
for file in sorted(glob('icons/*')):
if file not in icons:
print(f'WARNING: Unused icon file {file}')
if __name__ == '__main__':
generate()