1 |
jpaalasm |
609 |
#!/usr/bin/env python |
2 |
jpaalasm |
607 |
|
3 |
jpaalasm |
609 |
import glob, os, time, string |
4 |
jpaalasm |
607 |
|
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 |
jpaalasm |
609 |
d = {} |
19 |
|
|
for line in header.split("\n"): |
20 |
|
|
name, value = line.split(": ") |
21 |
|
|
d[name] = value |
22 |
|
|
|
23 |
|
|
return d |
24 |
|
|
# import yaml |
25 |
|
|
# return yaml.load(header).next() |
26 |
|
|
|
27 |
jpaalasm |
607 |
|
28 |
|
|
|
29 |
|
|
for pagefile in pagefiles: |
30 |
|
|
destfile = os.path.splitext(os.path.split(pagefile)[-1])[0]+".html" |
31 |
|
|
destpath = os.path.join(destdir, destfile) |
32 |
|
|
|
33 |
|
|
header, body = file(pagefile).read().split("\n\n", 1) |
34 |
|
|
metadata = parseheader(header) |
35 |
|
|
pagedata = {} |
36 |
|
|
pagedata["body text"] = body |
37 |
|
|
pagedata["last updated"] = time.ctime(os.path.getmtime(pagefile)) |
38 |
|
|
pagedata["fileinfo"] = fileinfo |
39 |
|
|
pagedata["download root"] = download_root |
40 |
|
|
pagedata.update(metadata) |
41 |
|
|
|
42 |
|
|
page = template |
43 |
|
|
for type, value in pagedata.items(): |
44 |
|
|
page = page.replace(includeformat % type, value) |
45 |
|
|
|
46 |
|
|
file(destpath, "w").write(page) |
47 |
|
|
print destpath |