-
Notifications
You must be signed in to change notification settings - Fork 388
/
make_html.py
30 lines (25 loc) · 919 Bytes
/
make_html.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
import html
import datetime
import repo
INPUT = './repo/Packages'
TEMPLATE = './index.html'
OUTPUT = './repo/index.html'
result = []
site = repo.Site()
site.add(INPUT)
site.open(False)
for name in (x for meta in site.meta_list for x in meta if x.endswith('.deepin')):
for _, pkg in site.get_package_entries(name):
url = '%s://%s' % tuple(pkg['Filename'].split('/', 1))
result.append((url, pkg['Package'], pkg['Version'], pkg['Description']))
site.close()
with open(TEMPLATE) as f:
template = f.read()
before_t, the_t, after_t = template.split('<!--template-->')
result.sort(key=lambda x: x[1])
with open(OUTPUT, 'wt') as f:
f.write(before_t)
for x in result:
f.write(the_t % tuple(map(html.escape, x)))
update_time = (datetime.datetime.utcnow() + datetime.timedelta(hours=8)).strftime('%Y-%m-%d %H:%M:%S')
f.write(after_t.replace('<!--update_time-->', update_time))