annotate roundup/templatebuilder.py @ 175:2a33ac3e807d

changes
author Richard Jones <richard@users.sourceforge.net>
date Wed, 01 Aug 2001 05:06:41 +0000
parents 2775f6727070
children d45384bc6420
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
174
2775f6727070 htmlbase doesn't have extraneous $Foo$ in it any more
Richard Jones <richard@users.sourceforge.net>
parents: 167
diff changeset
1 # $Id: templatebuilder.py,v 1.9 2001-08-01 05:06:10 richard Exp $
2775f6727070 htmlbase doesn't have extraneous $Foo$ in it any more
Richard Jones <richard@users.sourceforge.net>
parents: 167
diff changeset
2 import errno, re
113
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)
174
2775f6727070 htmlbase doesn't have extraneous $Foo$ in it any more
Richard Jones <richard@users.sourceforge.net>
parents: 167
diff changeset
25 fd.write(re.sub(r'\$((Id|File|Log).*?)\$', r'dollar\1dollar',
2775f6727070 htmlbase doesn't have extraneous $Foo$ in it any more
Richard Jones <richard@users.sourceforge.net>
parents: 167
diff changeset
26 open(file).read(), re.I))
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
27 fd.write('"""\n\n')
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
28 fd.close()
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
29
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
30 def installHtmlBase(template, installDir):
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
31 """ 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
32 the installdir """
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
33 import os,sys,re
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
34
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
35 tdir = __import__('roundup.templates.%s.htmlbase'%template).templates
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
36 if hasattr(tdir, template):
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
37 tmod = getattr(tdir, template)
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
38 else:
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
39 raise "TemplateError", "couldn't find roundup.template.%s.htmlbase"%template
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
40 htmlbase = tmod.htmlbase
69
0eed07d99b98 oops. Html.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents: 68
diff changeset
41 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
42 try:
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
43 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
44 except OSError, error:
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
45 if error.errno != errno.EEXIST: raise
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
46
114
caca379e12d3 commented out print
Richard Jones <richard@users.sourceforge.net>
parents: 113
diff changeset
47 # print "installing from", htmlbase.__file__, "into", installDir
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
48 modulecontents = dir(htmlbase)
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
49 for mangledfile in modulecontents:
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
50 if mangledfile[0] == "_":
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
51 continue
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
52 filename = re.sub('DOT', '.', mangledfile)
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
53 outfile = os.path.join(installDir, filename)
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
54 outfd = open(outfile, 'w')
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
55 data = getattr(htmlbase, mangledfile)
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
56 outfd.write(data)
68
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
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
60 if __name__ == "__main__":
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
61 import sys
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
62 if len(sys.argv) == 2:
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
63 makeHtmlBase(sys.argv[1])
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
64 elif len(sys.argv) == 3:
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
65 installHtmlBase(sys.argv[1], sys.argv[2])
68
5e71aaa87e5b Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff changeset
66 else:
113
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
67 raise "what you talkin about willis?"
2ab86442799a Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents: 102
diff changeset
68
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
69 #
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
70 # $Log: not supported by cvs2svn $
174
2775f6727070 htmlbase doesn't have extraneous $Foo$ in it any more
Richard Jones <richard@users.sourceforge.net>
parents: 167
diff changeset
71 # Revision 1.8 2001/07/30 08:12:17 richard
2775f6727070 htmlbase doesn't have extraneous $Foo$ in it any more
Richard Jones <richard@users.sourceforge.net>
parents: 167
diff changeset
72 # Added time logging and file uploading to the templates.
2775f6727070 htmlbase doesn't have extraneous $Foo$ in it any more
Richard Jones <richard@users.sourceforge.net>
parents: 167
diff changeset
73 #
167
a49c8a2ddd26 Added time logging and file uploading to the templates.
Richard Jones <richard@users.sourceforge.net>
parents: 139
diff changeset
74 # 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
75 # 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
76 #
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
77 # 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
78 # 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
79 #
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
80 #
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
81 #
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
82 # vim: set filetype=python ts=4 sw=4 et si

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