1 |
jpaalasm |
607 |
#!/usr/bin/env python2 |
2 |
|
|
|
3 |
|
|
import glob, os, time |
4 |
|
|
|
5 |
|
|
pagefiles = glob.glob("pages/*.html") |
6 |
|
|
template = file("template.xhtml").read() |
7 |
|
|
includeformat = "<!--%s-->" |
8 |
|
|
destdir = "skencil" |
9 |
|
|
|
10 |
|
|
fileinfo = """\ |
11 |
|
|
<!-- |
12 |
|
|
This file was generated by updatepages.py. Please don't modify. |
13 |
|
|
-->""" |
14 |
|
|
|
15 |
|
|
download_root = "http://sketch.sourceforge.net/files" |
16 |
|
|
|
17 |
|
|
def parseheader(header): |
18 |
|
|
import yaml |
19 |
|
|
return yaml.load(header).next() |
20 |
|
|
|
21 |
|
|
|
22 |
|
|
for pagefile in pagefiles: |
23 |
|
|
destfile = os.path.splitext(os.path.split(pagefile)[-1])[0]+".html" |
24 |
|
|
destpath = os.path.join(destdir, destfile) |
25 |
|
|
|
26 |
|
|
header, body = file(pagefile).read().split("\n\n", 1) |
27 |
|
|
metadata = parseheader(header) |
28 |
|
|
pagedata = {} |
29 |
|
|
pagedata["body text"] = body |
30 |
|
|
pagedata["last updated"] = time.ctime(os.path.getmtime(pagefile)) |
31 |
|
|
pagedata["fileinfo"] = fileinfo |
32 |
|
|
pagedata["download root"] = download_root |
33 |
|
|
pagedata.update(metadata) |
34 |
|
|
|
35 |
|
|
page = template |
36 |
|
|
for type, value in pagedata.items(): |
37 |
|
|
page = page.replace(includeformat % type, value) |
38 |
|
|
|
39 |
|
|
file(destpath, "w").write(page) |
40 |
|
|
print destpath |