Mercurial > p > roundup > code
annotate roundup/templatebuilder.py @ 213:d45384bc6420
Added the copyright/license notice to (nearly) all files...
...at request of Bizar Software.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 07 Aug 2001 00:15:51 +0000 |
| parents | 2775f6727070 |
| children | 18134bffab37 |
| rev | line source |
|---|---|
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
1 # |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/) |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
3 # This module is free software, and you may redistribute it and/or modify |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
4 # under the same terms as Python, so long as this copyright message and |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
5 # disclaimer are retained in their original form. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
6 # |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
7 # IN NO EVENT SHALL THE BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
10 # POSSIBILITY OF SUCH DAMAGE. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
11 # |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
17 # |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
18 # $Id: templatebuilder.py,v 1.10 2001-08-07 00:15:51 richard Exp $ |
|
174
2775f6727070
htmlbase doesn't have extraneous $Foo$ in it any more
Richard Jones <richard@users.sourceforge.net>
parents:
167
diff
changeset
|
19 import errno, re |
|
113
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
20 |
|
68
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
21 preamble = """ |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
22 # Do Not Edit (Unless You Want To) |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
23 # This file automagically generated by roundup.htmldata.makeHtmlBase |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
24 # |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
25 """ |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
26 |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
27 def makeHtmlBase(templateDir): |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
28 """ make a htmlbase.py file in the given templateDir, from the |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
29 contents of templateDir/html """ |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
30 import os, glob, re |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
31 print "packing up templates in", templateDir |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
32 filelist = glob.glob(os.path.join(templateDir, 'html', '*')) |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
33 filelist = filter(os.path.isfile, filelist) # only want files |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
34 filelist.sort() |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
35 fd = open(os.path.join(templateDir, 'htmlbase.py'), 'w') |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
36 fd.write(preamble) |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
37 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
|
38 # 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
|
39 if file[-1] == '~': continue |
|
113
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
40 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
|
41 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
|
42 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
|
43 open(file).read(), re.I)) |
|
113
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
44 fd.write('"""\n\n') |
|
68
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
45 fd.close() |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
46 |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
47 def installHtmlBase(template, installDir): |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
48 """ 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
|
49 the installdir """ |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
50 import os,sys,re |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
51 |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
52 tdir = __import__('roundup.templates.%s.htmlbase'%template).templates |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
53 if hasattr(tdir, template): |
|
113
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
54 tmod = getattr(tdir, template) |
|
68
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
55 else: |
|
113
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
56 raise "TemplateError", "couldn't find roundup.template.%s.htmlbase"%template |
|
68
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
57 htmlbase = tmod.htmlbase |
|
69
0eed07d99b98
oops. Html.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
68
diff
changeset
|
58 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
|
59 try: |
|
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
60 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
|
61 except OSError, error: |
|
113
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
62 if error.errno != errno.EEXIST: raise |
|
68
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
63 |
|
114
caca379e12d3
commented out print
Richard Jones <richard@users.sourceforge.net>
parents:
113
diff
changeset
|
64 # print "installing from", htmlbase.__file__, "into", installDir |
|
68
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
65 modulecontents = dir(htmlbase) |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
66 for mangledfile in modulecontents: |
|
113
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
67 if mangledfile[0] == "_": |
|
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
68 continue |
|
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
69 filename = re.sub('DOT', '.', mangledfile) |
|
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
70 outfile = os.path.join(installDir, filename) |
|
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
71 outfd = open(outfile, 'w') |
|
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
72 data = getattr(htmlbase, mangledfile) |
|
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
73 outfd.write(data) |
|
68
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
74 |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
75 |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
76 |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
77 if __name__ == "__main__": |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
78 import sys |
|
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
79 if len(sys.argv) == 2: |
|
113
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
80 makeHtmlBase(sys.argv[1]) |
|
68
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
81 elif len(sys.argv) == 3: |
|
113
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
82 installHtmlBase(sys.argv[1], sys.argv[2]) |
|
68
5e71aaa87e5b
Added templatebuilder module.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
diff
changeset
|
83 else: |
|
113
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
84 raise "what you talkin about willis?" |
|
2ab86442799a
Replaced errno integers with their module values.
Richard Jones <richard@users.sourceforge.net>
parents:
102
diff
changeset
|
85 |
|
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
|
86 # |
|
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
|
87 # $Log: not supported by cvs2svn $ |
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
88 # Revision 1.9 2001/08/01 05:06:10 richard |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
89 # htmlbase doesn't have extraneous $Foo$ in it any more |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
174
diff
changeset
|
90 # |
|
174
2775f6727070
htmlbase doesn't have extraneous $Foo$ in it any more
Richard Jones <richard@users.sourceforge.net>
parents:
167
diff
changeset
|
91 # 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
|
92 # 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
|
93 # |
|
167
a49c8a2ddd26
Added time logging and file uploading to the templates.
Richard Jones <richard@users.sourceforge.net>
parents:
139
diff
changeset
|
94 # 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
|
95 # 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
|
96 # |
|
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
|
97 # 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
|
98 # 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
|
99 # |
|
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
|
100 # |
|
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
|
101 # |
|
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
|
102 # vim: set filetype=python ts=4 sw=4 et si |
