Mercurial > p > roundup > code
view roundup/templates/builder.py @ 1281:284a9d6b3cf9
bugfixes to pipe bugfix
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 15 Oct 2002 07:25:49 +0000 |
| parents | efaabc87f02e |
| children |
line wrap: on
line source
# # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/) # This module is free software, and you may redistribute it and/or modify # under the same terms as Python, so long as this copyright message and # disclaimer are retained in their original form. # # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # # $Id: builder.py,v 1.4 2002-09-13 04:39:12 richard Exp $ import os, sys, glob, errno, re __doc__ = """ Collect template parts and create instance template files. """ preamble = """ # Do Not Edit (Unless You Want To) # This file automagically generated by roundup.templatebuilder.makeHtmlBase # """ def makeHtmlBase(templateDir): ''' make a <template>_htmlbase.py file in rondup.tempaltes, from the contents of templateDir/html ''' print "packing up templates in", templateDir filelist = glob.glob(os.path.join(templateDir, 'html', '*')) filelist = filter(os.path.isfile, filelist) # only want files filelist.sort() # ok, figure the template name and templates dir dir, name = os.path.split(templateDir) fd = open(os.path.join(dir, '%s_htmlbase.py'%name), 'w') fd.write(preamble) for file in filelist: # skip the backup files created by richard's vim if file[-1] == '~': continue mangled_name = os.path.basename(file).replace('.','DOT') fd.write('%s = """'%mangled_name) fd.write(re.sub(r'\$((Id|File|Log).*?)\$', r'dollar\1dollar', open(file).read(), re.I)) fd.write('"""\n\n') fd.close() def installHtmlBase(template, installDir): ''' passed a template name and an installDir, unpacks the html files into the installdir ''' tmod = '%s_htmlbase'%template tdir = __import__('roundup.templates.'+tmod).templates if hasattr(tdir, tmod): htmlbase = getattr(tdir, tmod) else: raise "TemplateError", \ "couldn't find roundup.templates.%s_htmlbase"%template installDir = os.path.join(installDir, 'html') try: os.makedirs(installDir) except OSError, error: if error.errno != errno.EEXIST: raise # print "installing from", htmlbase.__file__, "into", installDir modulecontents = dir(htmlbase) for mangledfile in modulecontents: if mangledfile.startswith('__') and mangledfile.endswith('__'): continue filename = re.sub('DOT', '.', mangledfile) outfile = os.path.join(installDir, filename) outfd = open(outfile, 'w') data = getattr(htmlbase, mangledfile) outfd.write(data) if __name__ == "__main__": if len(sys.argv) == 2: makeHtmlBase(sys.argv[1]) elif len(sys.argv) == 3: installHtmlBase(sys.argv[1], sys.argv[2]) else: print "Usage: %s <template directory>"%sys.argv[0] # vim: set filetype=python ts=4 sw=4 et si
