Code

Added the copyright/license notice to (nearly) all files at request of
[roundup.git] / roundup / templatebuilder.py
1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # IN NO EVENT SHALL THE BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17
18 # $Id: templatebuilder.py,v 1.10 2001-08-07 00:15:51 richard Exp $
19 import errno, re
21 preamble = """ 
22 # Do Not Edit (Unless You Want To)
23 # This file automagically generated by roundup.htmldata.makeHtmlBase
24
25 """
27 def makeHtmlBase(templateDir):
28     """ make a htmlbase.py file in the given templateDir, from the
29         contents of templateDir/html """
30     import os, glob, re
31     print "packing up templates in", templateDir
32     filelist = glob.glob(os.path.join(templateDir, 'html', '*'))
33     filelist = filter(os.path.isfile, filelist) # only want files
34     filelist.sort()
35     fd = open(os.path.join(templateDir, 'htmlbase.py'), 'w')
36     fd.write(preamble)
37     for file in filelist:
38         # skip the backup files created by richard's vim
39         if file[-1] == '~': continue
40         mangled_name = os.path.basename(re.sub(r'\.', 'DOT', file))
41         fd.write('%s = """'%mangled_name)
42         fd.write(re.sub(r'\$((Id|File|Log).*?)\$', r'dollar\1dollar',
43             open(file).read(), re.I))
44         fd.write('"""\n\n')
45     fd.close()
47 def installHtmlBase(template, installDir):
48     """ passed a template package and an installDir, unpacks the html files into
49       the installdir """
50     import os,sys,re
52     tdir = __import__('roundup.templates.%s.htmlbase'%template).templates
53     if hasattr(tdir, template):
54         tmod = getattr(tdir, template)
55     else:
56         raise "TemplateError", "couldn't find roundup.template.%s.htmlbase"%template
57     htmlbase = tmod.htmlbase
58     installDir = os.path.join(installDir, 'html')
59     try:
60         os.makedirs(installDir)
61     except OSError, error:
62         if error.errno != errno.EEXIST: raise
64 #    print "installing from", htmlbase.__file__, "into", installDir
65     modulecontents = dir(htmlbase)
66     for mangledfile in modulecontents:
67         if mangledfile[0] == "_": 
68             continue
69         filename = re.sub('DOT', '.', mangledfile)
70         outfile = os.path.join(installDir, filename)
71         outfd = open(outfile, 'w')
72         data = getattr(htmlbase, mangledfile)
73         outfd.write(data)
74     
77 if __name__ == "__main__":
78     import sys
79     if len(sys.argv) == 2:
80         makeHtmlBase(sys.argv[1])
81     elif len(sys.argv) == 3:
82         installHtmlBase(sys.argv[1], sys.argv[2])
83     else:
84         raise "what you talkin about willis?"
86 #
87 # $Log: not supported by cvs2svn $
88 # Revision 1.9  2001/08/01 05:06:10  richard
89 # htmlbase doesn't have extraneous $Foo$ in it any more
90 #
91 # Revision 1.8  2001/07/30 08:12:17  richard
92 # Added time logging and file uploading to the templates.
93 #
94 # Revision 1.7  2001/07/30 00:06:52  richard
95 # Hrm - had IOError instead of OSError. Not sure why there's two. Ho hum.
96 #
97 # Revision 1.6  2001/07/29 07:01:39  richard
98 # Added vim command to all source so that we don't get no steenkin' tabs :)
99 #
102 # vim: set filetype=python ts=4 sw=4 et si