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

Annotation of /website/trunk/updatepages.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 612 - (hide annotations)
Fri Mar 26 18:15:13 2004 UTC (20 years, 11 months ago) by jpaalasm
Original Path: website/trunk/skencil.org/updatepages.py
File MIME type: text/x-python
File size: 2015 byte(s)
GPL license comment block added.

1 jpaalasm 609 #!/usr/bin/env python
2 jpaalasm 607
3 jpaalasm 612 # 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    
20    
21 jpaalasm 609 import glob, os, time, string
22 jpaalasm 607
23     pagefiles = glob.glob("pages/*.html")
24     template = file("template.xhtml").read()
25     includeformat = "<!--%s-->"
26     destdir = "skencil"
27    
28 jpaalasm 612 globaldata = {
29     "fileinfo":
30     "<!-- This file was generated by updatepages.py. Please don't modify. -->",
31     "download root":
32     "http://sketch.sourceforge.net/files"}
33 jpaalasm 607
34     def parseheader(header):
35 jpaalasm 609 d = {}
36     for line in header.split("\n"):
37     name, value = line.split(": ")
38     d[name] = value
39    
40     return d
41     # import yaml
42     # return yaml.load(header).next()
43    
44 jpaalasm 610 if not os.path.isdir(destdir):
45     os.mkdir(destdir)
46 jpaalasm 607
47     for pagefile in pagefiles:
48     destfile = os.path.splitext(os.path.split(pagefile)[-1])[0]+".html"
49     destpath = os.path.join(destdir, destfile)
50    
51     header, body = file(pagefile).read().split("\n\n", 1)
52     metadata = parseheader(header)
53     pagedata = {}
54     pagedata["body text"] = body
55     pagedata["last updated"] = time.ctime(os.path.getmtime(pagefile))
56 jpaalasm 612 pagedata.update(globaldata)
57 jpaalasm 607 pagedata.update(metadata)
58    
59     page = template
60     for type, value in pagedata.items():
61     page = page.replace(includeformat % type, value)
62    
63     file(destpath, "w").write(page)
64     print destpath

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