Mercurial > p > roundup > code
comparison roundup/templates/builder.py @ 937:fb8a8eb55aac
cleanup: moved templatebuilder into templates.builder
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 16 Aug 2002 04:25:03 +0000 |
| parents | |
| children | cf72eae57a2c |
comparison
equal
deleted
inserted
replaced
| 936:57d09949380e | 937:fb8a8eb55aac |
|---|---|
| 1 # | |
| 2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/) | |
| 3 # This module is free software, and you may redistribute it and/or modify | |
| 4 # under the same terms as Python, so long as this copyright message and | |
| 5 # disclaimer are retained in their original form. | |
| 6 # | |
| 7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR | |
| 8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING | |
| 9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE | |
| 10 # POSSIBILITY OF SUCH DAMAGE. | |
| 11 # | |
| 12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, | |
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
| 17 # | |
| 18 # $Id: builder.py,v 1.1 2002-08-16 04:25:03 richard Exp $ | |
| 19 import errno, re | |
| 20 | |
| 21 __doc__ = """ | |
| 22 Collect template parts and create instance template files. | |
| 23 """ | |
| 24 | |
| 25 preamble = """ | |
| 26 # Do Not Edit (Unless You Want To) | |
| 27 # This file automagically generated by roundup.templatebuilder.makeHtmlBase | |
| 28 # | |
| 29 """ | |
| 30 | |
| 31 def makeHtmlBase(templateDir): | |
| 32 """ make a htmlbase.py file in the given templateDir, from the | |
| 33 contents of templateDir/html """ | |
| 34 import os, glob, re | |
| 35 print "packing up templates in", templateDir | |
| 36 filelist = glob.glob(os.path.join(templateDir, 'html', '*')) | |
| 37 filelist = filter(os.path.isfile, filelist) # only want files | |
| 38 filelist.sort() | |
| 39 fd = open(os.path.join(templateDir, 'htmlbase.py'), 'w') | |
| 40 fd.write(preamble) | |
| 41 for file in filelist: | |
| 42 # skip the backup files created by richard's vim | |
| 43 if file[-1] == '~': continue | |
| 44 mangled_name = os.path.basename(file).replace('.','DOT') | |
| 45 fd.write('%s = """'%mangled_name) | |
| 46 fd.write(re.sub(r'\$((Id|File|Log).*?)\$', r'dollar\1dollar', | |
| 47 open(file).read(), re.I)) | |
| 48 fd.write('"""\n\n') | |
| 49 fd.close() | |
| 50 | |
| 51 def installHtmlBase(template, installDir): | |
| 52 """ passed a template package and an installDir, unpacks the html files into | |
| 53 the installdir """ | |
| 54 import os,sys,re | |
| 55 | |
| 56 tdir = __import__('roundup.templates.%s.htmlbase'%template).templates | |
| 57 if hasattr(tdir, template): | |
| 58 tmod = getattr(tdir, template) | |
| 59 else: | |
| 60 raise "TemplateError", "couldn't find roundup.template.%s.htmlbase"%template | |
| 61 htmlbase = tmod.htmlbase | |
| 62 installDir = os.path.join(installDir, 'html') | |
| 63 try: | |
| 64 os.makedirs(installDir) | |
| 65 except OSError, error: | |
| 66 if error.errno != errno.EEXIST: raise | |
| 67 | |
| 68 # print "installing from", htmlbase.__file__, "into", installDir | |
| 69 modulecontents = dir(htmlbase) | |
| 70 for mangledfile in modulecontents: | |
| 71 if mangledfile[0] == "_": | |
| 72 continue | |
| 73 filename = re.sub('DOT', '.', mangledfile) | |
| 74 outfile = os.path.join(installDir, filename) | |
| 75 outfd = open(outfile, 'w') | |
| 76 data = getattr(htmlbase, mangledfile) | |
| 77 outfd.write(data) | |
| 78 | |
| 79 | |
| 80 | |
| 81 if __name__ == "__main__": | |
| 82 import sys | |
| 83 if len(sys.argv) == 2: | |
| 84 makeHtmlBase(sys.argv[1]) | |
| 85 elif len(sys.argv) == 3: | |
| 86 installHtmlBase(sys.argv[1], sys.argv[2]) | |
| 87 else: | |
| 88 print "Usage: %s <template directory>"%sys.argv[0] | |
| 89 | |
| 90 # | |
| 91 # $Log: not supported by cvs2svn $ | |
| 92 # Revision 1.14 2002/02/05 09:59:05 grubert | |
| 93 # . makeHtmlBase: re.sub under python 2.2 did not replace '.', string.replace does it. | |
| 94 # | |
| 95 # Revision 1.13 2001/11/22 15:46:42 jhermann | |
| 96 # Added module docstrings to all modules. | |
| 97 # | |
| 98 # Revision 1.12 2001/11/14 21:35:21 richard | |
| 99 # . users may attach files to issues (and support in ext) through the web now | |
| 100 # | |
| 101 # Revision 1.11 2001/08/07 00:24:42 richard | |
| 102 # stupid typo | |
| 103 # | |
| 104 # Revision 1.10 2001/08/07 00:15:51 richard | |
| 105 # Added the copyright/license notice to (nearly) all files at request of | |
| 106 # Bizar Software. | |
| 107 # | |
| 108 # Revision 1.9 2001/08/01 05:06:10 richard | |
| 109 # htmlbase doesn't have extraneous $Foo$ in it any more | |
| 110 # | |
| 111 # Revision 1.8 2001/07/30 08:12:17 richard | |
| 112 # Added time logging and file uploading to the templates. | |
| 113 # | |
| 114 # Revision 1.7 2001/07/30 00:06:52 richard | |
| 115 # Hrm - had IOError instead of OSError. Not sure why there's two. Ho hum. | |
| 116 # | |
| 117 # Revision 1.6 2001/07/29 07:01:39 richard | |
| 118 # Added vim command to all source so that we don't get no steenkin' tabs :) | |
| 119 # | |
| 120 # | |
| 121 # | |
| 122 # vim: set filetype=python ts=4 sw=4 et si |
