1 preamble = """
2 # Do Not Edit (Unless You Want To)
3 # This file automagically generated by roundup.htmldata.makeHtmlBase
4 #
5 """
7 def makeHtmlBase(templateDir):
8 """ make a htmlbase.py file in the given templateDir, from the
9 contents of templateDir/html """
10 import os, glob, re
11 print "packing up templates in", templateDir
12 filelist = glob.glob(os.path.join(templateDir, 'html', '*'))
13 filelist = filter(os.path.isfile, filelist) # only want files
14 filelist.sort()
15 fd = open(os.path.join(templateDir, 'htmlbase.py'), 'w')
16 fd.write(preamble)
17 for file in filelist:
18 mangled_name = os.path.basename(re.sub(r'\.', 'DOT', file))
19 fd.write('%s = """'%mangled_name)
20 fd.write(open(file).read())
21 fd.write('"""\n\n')
22 fd.close()
24 def installHtmlBase(template, installDir):
25 """ passed a template package and an installDir, unpacks the html files into
26 the installdir """
27 import os,sys,re
29 tdir = __import__('roundup.templates.%s.htmlbase'%template).templates
30 if hasattr(tdir, template):
31 tmod = getattr(tdir, template)
32 else:
33 raise "TemplateError", \
34 "couldn't find roundup.template.%s.htmlbase"%template
35 htmlbase = tmod.htmlbase
37 print "installing from", htmlbase.__file__, "into", installDir
38 modulecontents = dir(htmlbase)
39 for mangledfile in modulecontents:
40 if mangledfile[0] == "_":
41 continue
42 filename = re.sub('DOT', '.', mangledfile)
43 outfile = os.path.join(installDir, filename)
44 outfd = open(outfile, 'w')
45 data = getattr(htmlbase, mangledfile)
46 outfd.write(data)
50 if __name__ == "__main__":
51 import sys
52 if len(sys.argv) == 2:
53 makeHtmlBase(sys.argv[1])
54 elif len(sys.argv) == 3:
55 installHtmlBase(sys.argv[1], sys.argv[2])
56 else:
57 raise "what you talkin about willis?"