annotate roundup/templatebuilder.py @ 167:a49c8a2ddd26

Added time logging and file uploading to the templates.
author Richard Jones <richard@users.sourceforge.net>
date Mon, 30 Jul 2001 08:12:17 +0000
parents 16fdc86183fe
children 2775f6727070
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
167
a49c8a2ddd26 Added time logging and file uploading to the templates.
Richard Jones <richard@users.sourceforge.net>
parents: 139
diff changeset
1 # $Id: templatebuilder.py,v 1.8 2001-07-30 08:12:17 richard Exp $
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
2 import errno
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
3
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
4 preamble = """
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
5 # Do Not Edit (Unless You Want To)
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
6 # This file automagically generated by roundup.htmldata.makeHtmlBase
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
7 #
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
8 """
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
9
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
10 def makeHtmlBase(templateDir):
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
11 """ make a htmlbase.py file in the given templateDir, from the
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
12 contents of templateDir/html """
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
13 import os, glob, re
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
14 print "packing up templates in", templateDir
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
15 filelist = glob.glob(os.path.join(templateDir, 'html', '*'))
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
16 filelist = filter(os.path.isfile, filelist) # only want files
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
17 filelist.sort()
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
18 fd = open(os.path.join(templateDir, 'htmlbase.py'), 'w')
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
19 fd.write(preamble)
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
20 for file in filelist:
167
a49c8a2ddd26 Added time logging and file uploading to the templates.
Richard Jones <richard@users.sourceforge.net>
parents: 139
diff changeset
21 # skip the backup files created by richard's vim
a49c8a2ddd26 Added time logging and file uploading to the templates.
Richard Jones <richard@users.sourceforge.net>
parents: 139
diff changeset
22 if file[-1] == '~': continue
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
23 mangled_name = os.path.basename(re.sub(r'\.', 'DOT', file))
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
24 fd.write('%s = """'%mangled_name)
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
25 fd.write(open(file).read())
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
26 fd.write('"""\n\n')
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
27 fd.close()
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
28
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
29 def installHtmlBase(template, installDir):
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
30 """ passed a template package and an installDir, unpacks the html files into
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
31 the installdir """
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
32 import os,sys,re
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
33
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
34 tdir = __import__('roundup.templates.%s.htmlbase'%template).templates
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
35 if hasattr(tdir, template):
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
36 tmod = getattr(tdir, template)
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
37 else:
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
38 raise "TemplateError", "couldn't find roundup.template.%s.htmlbase"%template
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
39 htmlbase = tmod.htmlbase
69
0eed07d99b98 oops. Html.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents: 68
diff changeset
40 installDir = os.path.join(installDir, 'html')
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
41 try:
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
42 os.makedirs(installDir)
139
16fdc86183fe Hrm - had IOError instead of OSError. Not sure why there's two. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
43 except OSError, error:
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
44 if error.errno != errno.EEXIST: raise
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
45
114
caca379e12d3 commented out print
Richard Jones <richard@users.sourceforge.net>
parents: 113
diff changeset
46 # print "installing from", htmlbase.__file__, "into", installDir
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
47 modulecontents = dir(htmlbase)
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
48 for mangledfile in modulecontents:
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
49 if mangledfile[0] == "_":
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
50 continue
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
51 filename = re.sub('DOT', '.', mangledfile)
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
52 outfile = os.path.join(installDir, filename)
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
53 outfd = open(outfile, 'w')
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
54 data = getattr(htmlbase, mangledfile)
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
55 outfd.write(data)
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
56
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
57
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
58
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
59 if __name__ == "__main__":
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
60 import sys
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
61 if len(sys.argv) == 2:
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
62 makeHtmlBase(sys.argv[1])
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
63 elif len(sys.argv) == 3:
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
64 installHtmlBase(sys.argv[1], sys.argv[2])
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
65 else:
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
66 raise "what you talkin about willis?"
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
67
127
0791d13baea7 Added vim command to all source so that we don't get no steenkin' tabs :)
Richard Jones <richard@users.sourceforge.net>
parents: 114
diff changeset
68 #
0791d13baea7 Added vim command to all source so that we don't get no steenkin' tabs :)
Richard Jones <richard@users.sourceforge.net>
parents: 114
diff changeset
69 # $Log: not supported by cvs2svn $
167
a49c8a2ddd26 Added time logging and file uploading to the templates.
Richard Jones <richard@users.sourceforge.net>
parents: 139
diff changeset
70 # Revision 1.7 2001/07/30 00:06:52 richard
a49c8a2ddd26 Added time logging and file uploading to the templates.
Richard Jones <richard@users.sourceforge.net>
parents: 139
diff changeset
71 # Hrm - had IOError instead of OSError. Not sure why there's two. Ho hum.
a49c8a2ddd26 Added time logging and file uploading to the templates.
Richard Jones <richard@users.sourceforge.net>
parents: 139
diff changeset
72 #
139
16fdc86183fe Hrm - had IOError instead of OSError. Not sure why there's two. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
73 # Revision 1.6 2001/07/29 07:01:39 richard
16fdc86183fe Hrm - had IOError instead of OSError. Not sure why there's two. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
74 # Added vim command to all source so that we don't get no steenkin' tabs :)
16fdc86183fe Hrm - had IOError instead of OSError. Not sure why there's two. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
75 #
127
0791d13baea7 Added vim command to all source so that we don't get no steenkin' tabs :)
Richard Jones <richard@users.sourceforge.net>
parents: 114
diff changeset
76 #
0791d13baea7 Added vim command to all source so that we don't get no steenkin' tabs :)
Richard Jones <richard@users.sourceforge.net>
parents: 114
diff changeset
77 #
0791d13baea7 Added vim command to all source so that we don't get no steenkin' tabs :)
Richard Jones <richard@users.sourceforge.net>
parents: 114
diff changeset
78 # vim: set filetype=python ts=4 sw=4 et si

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