comparison 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
comparison
equal deleted inserted replaced
67:5b0406c37ccd 68:5e71aaa87e5b
1 preamble = """
2 # Do Not Edit (Unless You Want To)
3 # This file automagically generated by roundup.htmldata.makeHtmlBase
4 #
5 """
6
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()
23
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
28
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
36
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)
47
48
49
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?"

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