/[skencil]/website/trunk/updatepages.py
ViewVC logotype

Contents of /website/trunk/updatepages.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 658 - (show annotations)
Tue Apr 11 08:22:48 2006 UTC (18 years, 10 months ago) by torsten
File MIME type: text/x-python
File size: 3007 byte(s)
Continued restructuring of the repository. Moved folder from skencil.org into the trunk folder.

1 #!/usr/bin/env python
2
3 # updatepages.py - Simple web site templating system
4 # Copyright (C) 2004 Joonas Paalasmaa
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 """Format webpages from templates.
20
21 Update a file only if it does not exist or when the sources are newer.
22 You can also use "-f" or "--force" which does what you think it does.
23 """
24 __version__="$Revison:$"[9:-1]
25
26
27 import glob, os, time, string, getopt, sys
28
29 templatefile = "template.xhtml"
30
31 pagefiles = glob.glob("pages/*.html")
32 template = file(templatefile).read()
33 includeformat = "<!--%s-->"
34 destdir = "skencil"
35
36 globaldata = {
37 "fileinfo":
38 "<!-- This file was generated by updatepages.py. Please don't modify. -->",
39 "download root":
40 "http://sketch.sourceforge.net/files"}
41
42 def newer(filename1, filename2):
43 """Check if filename1 was modified after filename2."""
44 if not os.path.isfile(filename2):
45 return True
46 return ( os.path.getmtime(filename1) > os.path.getmtime(filename2) )
47
48 def parseheader(header):
49 d = {}
50 for line in header.split("\n"):
51 name, value = line.split(": ")
52 d[name] = value
53
54 return d
55 # import yaml
56 # return yaml.load(header).next()
57
58 def doit(force=False):
59 if not os.path.isdir(destdir):
60 os.mkdir(destdir)
61
62 for pagefile in pagefiles:
63 destfile = os.path.splitext(os.path.split(pagefile)[-1])[0]+".html"
64 destpath = os.path.join(destdir, destfile)
65
66 if newer(templatefile, destpath) or newer(pagefile, destpath) or force:
67
68 header, body = file(pagefile).read().split("\n\n", 1)
69 metadata = parseheader(header)
70 pagedata = {}
71 pagedata["body text"] = body
72 pagedata["last updated"] = time.ctime(os.path.getmtime(pagefile))
73 pagedata.update(globaldata)
74 pagedata.update(metadata)
75
76 page = template
77 for type, value in pagedata.items():
78 page = page.replace(includeformat % type, value)
79
80 file(destpath, "w").write(page)
81 print destpath
82
83 def main():
84 try:
85 opts, args = getopt.getopt(sys.argv[1:], "f", ["force"])
86 except getopt.GetoptError:
87 sys.exit(2)
88 force = False
89 for o, a in opts:
90 if o in ("-f", "--force"):
91 force = True
92 doit(force)
93
94 if __name__ == "__main__":
95 main()
96

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26