diff roundup/templatebuilder.py @ 68:5e71aaa87e5b

Added templatebuilder module. two functions - one to pack up the html base, one to unpack it. Packed up the two standard templates into htmlbases. Modified __init__ to install them. __init__.py magic was needed for the rather high levels of wierd import magic. Reducing level of import magic == (good, future)
author Anthony Baxter <anthonybaxter@users.sourceforge.net>
date Tue, 24 Jul 2001 10:46:22 +0000
parents
children 0eed07d99b98
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roundup/templatebuilder.py	Tue Jul 24 10:46:22 2001 +0000
@@ -0,0 +1,57 @@
+preamble = """ 
+# Do Not Edit (Unless You Want To)
+# This file automagically generated by roundup.htmldata.makeHtmlBase
+# 
+"""
+
+def makeHtmlBase(templateDir):
+    """ make a htmlbase.py file in the given templateDir, from the
+        contents of templateDir/html """
+    import os, glob, re
+    print "packing up templates in", templateDir
+    filelist = glob.glob(os.path.join(templateDir, 'html', '*'))
+    filelist = filter(os.path.isfile, filelist) # only want files
+    filelist.sort()
+    fd = open(os.path.join(templateDir, 'htmlbase.py'), 'w')
+    fd.write(preamble)
+    for file in filelist:
+	mangled_name = os.path.basename(re.sub(r'\.', 'DOT', file))
+	fd.write('%s = """'%mangled_name)
+	fd.write(open(file).read())
+	fd.write('"""\n\n')
+    fd.close()
+
+def installHtmlBase(template, installDir):
+    """ passed a template package and an installDir, unpacks the html files into
+      the installdir """
+    import os,sys,re
+
+    tdir = __import__('roundup.templates.%s.htmlbase'%template).templates
+    if hasattr(tdir, template):
+	tmod = getattr(tdir, template)
+    else:
+	raise "TemplateError", \
+		"couldn't find roundup.template.%s.htmlbase"%template
+    htmlbase = tmod.htmlbase
+
+    print "installing from", htmlbase.__file__, "into", installDir
+    modulecontents = dir(htmlbase)
+    for mangledfile in modulecontents:
+	if mangledfile[0] == "_": 
+	    continue
+	filename = re.sub('DOT', '.', mangledfile)
+	outfile = os.path.join(installDir, filename)
+	outfd = open(outfile, 'w')
+	data = getattr(htmlbase, mangledfile)
+	outfd.write(data)
+    
+
+
+if __name__ == "__main__":
+    import sys
+    if len(sys.argv) == 2:
+	makeHtmlBase(sys.argv[1])
+    elif len(sys.argv) == 3:
+	installHtmlBase(sys.argv[1], sys.argv[2])
+    else:
+	raise "what you talkin about willis?"

Roundup Issue Tracker: http://roundup-tracker.org/