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 |
610 |
if not os.path.isdir(destdir): |
28 |
|
|
os.mkdir(destdir) |
29 |
jpaalasm |
607 |
|
30 |
|
|
for pagefile in pagefiles: |
31 |
|
|
destfile = os.path.splitext(os.path.split(pagefile)[-1])[0]+".html" |
32 |
|
|
destpath = os.path.join(destdir, destfile) |
33 |
|
|
|
34 |
|
|
header, body = file(pagefile).read().split("\n\n", 1) |
35 |
|
|
metadata = parseheader(header) |
36 |
|
|
pagedata = {} |
37 |
|
|
pagedata["body text"] = body |
38 |
|
|
pagedata["last updated"] = time.ctime(os.path.getmtime(pagefile)) |
39 |
|
|
pagedata["fileinfo"] = fileinfo |
40 |
|
|
pagedata["download root"] = download_root |
41 |
|
|
pagedata.update(metadata) |
42 |
|
|
|
43 |
|
|
page = template |
44 |
|
|
for type, value in pagedata.items(): |
45 |
|
|
page = page.replace(includeformat % type, value) |
46 |
|
|
|
47 |
|
|
file(destpath, "w").write(page) |
48 |
|
|
print destpath |