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 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.14 2002-02-05 09:59:05 grubert Exp $
19 import errno, re
21 __doc__ = """
22 Collect template parts and create instance template files.
23 """
25 preamble = """
26 # Do Not Edit (Unless You Want To)
27 # This file automagically generated by roundup.templatebuilder.makeHtmlBase
28 #
29 """
31 def makeHtmlBase(templateDir):
32 """ make a htmlbase.py file in the given templateDir, from the
33 contents of templateDir/html """
34 import os, glob, re
35 print "packing up templates in", templateDir
36 filelist = glob.glob(os.path.join(templateDir, 'html', '*'))
37 filelist = filter(os.path.isfile, filelist) # only want files
38 filelist.sort()
39 fd = open(os.path.join(templateDir, 'htmlbase.py'), 'w')
40 fd.write(preamble)
41 for file in filelist:
42 # skip the backup files created by richard's vim
43 if file[-1] == '~': continue
44 mangled_name = os.path.basename(file).replace('.','DOT')
45 fd.write('%s = """'%mangled_name)
46 fd.write(re.sub(r'\$((Id|File|Log).*?)\$', r'dollar\1dollar',
47 open(file).read(), re.I))
48 fd.write('"""\n\n')
49 fd.close()
51 def installHtmlBase(template, installDir):
52 """ passed a template package and an installDir, unpacks the html files into
53 the installdir """
54 import os,sys,re
56 tdir = __import__('roundup.templates.%s.htmlbase'%template).templates
57 if hasattr(tdir, template):
58 tmod = getattr(tdir, template)
59 else:
60 raise "TemplateError", "couldn't find roundup.template.%s.htmlbase"%template
61 htmlbase = tmod.htmlbase
62 installDir = os.path.join(installDir, 'html')
63 try:
64 os.makedirs(installDir)
65 except OSError, error:
66 if error.errno != errno.EEXIST: raise
68 # print "installing from", htmlbase.__file__, "into", installDir
69 modulecontents = dir(htmlbase)
70 for mangledfile in modulecontents:
71 if mangledfile[0] == "_":
72 continue
73 filename = re.sub('DOT', '.', mangledfile)
74 outfile = os.path.join(installDir, filename)
75 outfd = open(outfile, 'w')
76 data = getattr(htmlbase, mangledfile)
77 outfd.write(data)
81 if __name__ == "__main__":
82 import sys
83 if len(sys.argv) == 2:
84 makeHtmlBase(sys.argv[1])
85 elif len(sys.argv) == 3:
86 installHtmlBase(sys.argv[1], sys.argv[2])
87 else:
88 print "Usage: %s <template directory>"%sys.argv[0]
90 #
91 # $Log: not supported by cvs2svn $
92 # Revision 1.13 2001/11/22 15:46:42 jhermann
93 # Added module docstrings to all modules.
94 #
95 # Revision 1.12 2001/11/14 21:35:21 richard
96 # . users may attach files to issues (and support in ext) through the web now
97 #
98 # Revision 1.11 2001/08/07 00:24:42 richard
99 # stupid typo
100 #
101 # Revision 1.10 2001/08/07 00:15:51 richard
102 # Added the copyright/license notice to (nearly) all files at request of
103 # Bizar Software.
104 #
105 # Revision 1.9 2001/08/01 05:06:10 richard
106 # htmlbase doesn't have extraneous $Foo$ in it any more
107 #
108 # Revision 1.8 2001/07/30 08:12:17 richard
109 # Added time logging and file uploading to the templates.
110 #
111 # Revision 1.7 2001/07/30 00:06:52 richard
112 # Hrm - had IOError instead of OSError. Not sure why there's two. Ho hum.
113 #
114 # Revision 1.6 2001/07/29 07:01:39 richard
115 # Added vim command to all source so that we don't get no steenkin' tabs :)
116 #
117 #
118 #
119 # vim: set filetype=python ts=4 sw=4 et si