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