Code

Added time logging and file uploading to the templates.
[roundup.git] / roundup / templatebuilder.py
1 # $Id: templatebuilder.py,v 1.8 2001-07-30 08:12:17 richard Exp $
2 import errno
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(open(file).read())
26         fd.write('"""\n\n')
27     fd.close()
29 def installHtmlBase(template, installDir):
30     """ passed a template package and an installDir, unpacks the html files into
31       the installdir """
32     import os,sys,re
34     tdir = __import__('roundup.templates.%s.htmlbase'%template).templates
35     if hasattr(tdir, template):
36         tmod = getattr(tdir, template)
37     else:
38         raise "TemplateError", "couldn't find roundup.template.%s.htmlbase"%template
39     htmlbase = tmod.htmlbase
40     installDir = os.path.join(installDir, 'html')
41     try:
42         os.makedirs(installDir)
43     except OSError, error:
44         if error.errno != errno.EEXIST: raise
46 #    print "installing from", htmlbase.__file__, "into", installDir
47     modulecontents = dir(htmlbase)
48     for mangledfile in modulecontents:
49         if mangledfile[0] == "_": 
50             continue
51         filename = re.sub('DOT', '.', mangledfile)
52         outfile = os.path.join(installDir, filename)
53         outfd = open(outfile, 'w')
54         data = getattr(htmlbase, mangledfile)
55         outfd.write(data)
56     
59 if __name__ == "__main__":
60     import sys
61     if len(sys.argv) == 2:
62         makeHtmlBase(sys.argv[1])
63     elif len(sys.argv) == 3:
64         installHtmlBase(sys.argv[1], sys.argv[2])
65     else:
66         raise "what you talkin about willis?"
68 #
69 # $Log: not supported by cvs2svn $
70 # Revision 1.7  2001/07/30 00:06:52  richard
71 # Hrm - had IOError instead of OSError. Not sure why there's two. Ho hum.
72 #
73 # Revision 1.6  2001/07/29 07:01:39  richard
74 # Added vim command to all source so that we don't get no steenkin' tabs :)
75 #
76 #
77 #
78 # vim: set filetype=python ts=4 sw=4 et si