1 # $Id: templatebuilder.py,v 1.9 2001-08-01 05:06:10 richard Exp $
2 import errno, re
4 preamble = """
5 # Do Not Edit (Unless You Want To)
6 # This file automagically generated by roundup.htmldata.makeHtmlBase
7 #
8 """
10 def makeHtmlBase(templateDir):
11 """ make a htmlbase.py file in the given templateDir, from the
12 contents of templateDir/html """
13 import os, glob, re
14 print "packing up templates in", templateDir
15 filelist = glob.glob(os.path.join(templateDir, 'html', '*'))
16 filelist = filter(os.path.isfile, filelist) # only want files
17 filelist.sort()
18 fd = open(os.path.join(templateDir, 'htmlbase.py'), 'w')
19 fd.write(preamble)
20 for file in filelist:
21 # skip the backup files created by richard's vim
22 if file[-1] == '~': continue
23 mangled_name = os.path.basename(re.sub(r'\.', 'DOT', file))
24 fd.write('%s = """'%mangled_name)
25 fd.write(re.sub(r'\$((Id|File|Log).*?)\$', r'dollar\1dollar',
26 open(file).read(), re.I))
27 fd.write('"""\n\n')
28 fd.close()
30 def installHtmlBase(template, installDir):
31 """ passed a template package and an installDir, unpacks the html files into
32 the installdir """
33 import os,sys,re
35 tdir = __import__('roundup.templates.%s.htmlbase'%template).templates
36 if hasattr(tdir, template):
37 tmod = getattr(tdir, template)
38 else:
39 raise "TemplateError", "couldn't find roundup.template.%s.htmlbase"%template
40 htmlbase = tmod.htmlbase
41 installDir = os.path.join(installDir, 'html')
42 try:
43 os.makedirs(installDir)
44 except OSError, error:
45 if error.errno != errno.EEXIST: raise
47 # print "installing from", htmlbase.__file__, "into", installDir
48 modulecontents = dir(htmlbase)
49 for mangledfile in modulecontents:
50 if mangledfile[0] == "_":
51 continue
52 filename = re.sub('DOT', '.', mangledfile)
53 outfile = os.path.join(installDir, filename)
54 outfd = open(outfile, 'w')
55 data = getattr(htmlbase, mangledfile)
56 outfd.write(data)
60 if __name__ == "__main__":
61 import sys
62 if len(sys.argv) == 2:
63 makeHtmlBase(sys.argv[1])
64 elif len(sys.argv) == 3:
65 installHtmlBase(sys.argv[1], sys.argv[2])
66 else:
67 raise "what you talkin about willis?"
69 #
70 # $Log: not supported by cvs2svn $
71 # Revision 1.8 2001/07/30 08:12:17 richard
72 # Added time logging and file uploading to the templates.
73 #
74 # Revision 1.7 2001/07/30 00:06:52 richard
75 # Hrm - had IOError instead of OSError. Not sure why there's two. Ho hum.
76 #
77 # Revision 1.6 2001/07/29 07:01:39 richard
78 # Added vim command to all source so that we don't get no steenkin' tabs :)
79 #
80 #
81 #
82 # vim: set filetype=python ts=4 sw=4 et si