Mercurial > p > roundup > code
comparison roundup/templates/builder.py @ 1055:cf72eae57a2c
Fixed instance installation
... moved the htmlbase module into templates and call it
<template>_htmlbase.py ... no more try/except in instance __init__!
Added :required to form handling.
Handle multiple values for single form items with decent error report.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 05 Sep 2002 23:39:14 +0000 |
| parents | fb8a8eb55aac |
| children | 8622dc1bcf23 |
comparison
equal
deleted
inserted
replaced
| 1054:3d8ea16347aa | 1055:cf72eae57a2c |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 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" | 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, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 18 # $Id: builder.py,v 1.1 2002-08-16 04:25:03 richard Exp $ | 18 # $Id: builder.py,v 1.2 2002-09-05 23:39:13 richard Exp $ |
| 19 import errno, re | 19 import os, sys, glob, errno, re |
| 20 | 20 |
| 21 __doc__ = """ | 21 __doc__ = """ |
| 22 Collect template parts and create instance template files. | 22 Collect template parts and create instance template files. |
| 23 """ | 23 """ |
| 24 | 24 |
| 27 # This file automagically generated by roundup.templatebuilder.makeHtmlBase | 27 # This file automagically generated by roundup.templatebuilder.makeHtmlBase |
| 28 # | 28 # |
| 29 """ | 29 """ |
| 30 | 30 |
| 31 def makeHtmlBase(templateDir): | 31 def makeHtmlBase(templateDir): |
| 32 """ make a htmlbase.py file in the given templateDir, from the | 32 ''' make a <template>_htmlbase.py file in rondup.tempaltes, from the |
| 33 contents of templateDir/html """ | 33 contents of templateDir/html |
| 34 import os, glob, re | 34 ''' |
| 35 print "packing up templates in", templateDir | 35 print "packing up templates in", templateDir |
| 36 | |
| 36 filelist = glob.glob(os.path.join(templateDir, 'html', '*')) | 37 filelist = glob.glob(os.path.join(templateDir, 'html', '*')) |
| 37 filelist = filter(os.path.isfile, filelist) # only want files | 38 filelist = filter(os.path.isfile, filelist) # only want files |
| 38 filelist.sort() | 39 filelist.sort() |
| 39 fd = open(os.path.join(templateDir, 'htmlbase.py'), 'w') | 40 |
| 41 # ok, figure the template name and templates dir | |
| 42 dir, name = os.path.split(templateDir) | |
| 43 | |
| 44 fd = open(os.path.join(dir, '%s_htmlbase.py'%name), 'w') | |
| 40 fd.write(preamble) | 45 fd.write(preamble) |
| 41 for file in filelist: | 46 for file in filelist: |
| 42 # skip the backup files created by richard's vim | 47 # skip the backup files created by richard's vim |
| 43 if file[-1] == '~': continue | 48 if file[-1] == '~': continue |
| 44 mangled_name = os.path.basename(file).replace('.','DOT') | 49 mangled_name = os.path.basename(file).replace('.','DOT') |
| 47 open(file).read(), re.I)) | 52 open(file).read(), re.I)) |
| 48 fd.write('"""\n\n') | 53 fd.write('"""\n\n') |
| 49 fd.close() | 54 fd.close() |
| 50 | 55 |
| 51 def installHtmlBase(template, installDir): | 56 def installHtmlBase(template, installDir): |
| 52 """ passed a template package and an installDir, unpacks the html files into | 57 ''' passed a template name and an installDir, unpacks the html files into |
| 53 the installdir """ | 58 the installdir |
| 54 import os,sys,re | 59 ''' |
| 55 | 60 tmod = '%s_htmlbase'%template |
| 56 tdir = __import__('roundup.templates.%s.htmlbase'%template).templates | 61 tdir = __import__('roundup.templates.'+tmod).templates |
| 57 if hasattr(tdir, template): | 62 if hasattr(tdir, tmod): |
| 58 tmod = getattr(tdir, template) | 63 htmlbase = getattr(tdir, tmod) |
| 59 else: | 64 else: |
| 60 raise "TemplateError", "couldn't find roundup.template.%s.htmlbase"%template | 65 raise "TemplateError", \ |
| 61 htmlbase = tmod.htmlbase | 66 "couldn't find roundup.templates.%s_htmlbase"%template |
| 62 installDir = os.path.join(installDir, 'html') | 67 installDir = os.path.join(installDir, 'html') |
| 63 try: | 68 try: |
| 64 os.makedirs(installDir) | 69 os.makedirs(installDir) |
| 65 except OSError, error: | 70 except OSError, error: |
| 66 if error.errno != errno.EEXIST: raise | 71 if error.errno != errno.EEXIST: raise |
| 74 outfile = os.path.join(installDir, filename) | 79 outfile = os.path.join(installDir, filename) |
| 75 outfd = open(outfile, 'w') | 80 outfd = open(outfile, 'w') |
| 76 data = getattr(htmlbase, mangledfile) | 81 data = getattr(htmlbase, mangledfile) |
| 77 outfd.write(data) | 82 outfd.write(data) |
| 78 | 83 |
| 79 | |
| 80 | |
| 81 if __name__ == "__main__": | 84 if __name__ == "__main__": |
| 82 import sys | |
| 83 if len(sys.argv) == 2: | 85 if len(sys.argv) == 2: |
| 84 makeHtmlBase(sys.argv[1]) | 86 makeHtmlBase(sys.argv[1]) |
| 85 elif len(sys.argv) == 3: | 87 elif len(sys.argv) == 3: |
| 86 installHtmlBase(sys.argv[1], sys.argv[2]) | 88 installHtmlBase(sys.argv[1], sys.argv[2]) |
| 87 else: | 89 else: |
| 88 print "Usage: %s <template directory>"%sys.argv[0] | 90 print "Usage: %s <template directory>"%sys.argv[0] |
| 89 | 91 |
| 90 # | 92 # |
| 91 # $Log: not supported by cvs2svn $ | 93 # $Log: not supported by cvs2svn $ |
| 94 # Revision 1.1 2002/08/16 04:25:03 richard | |
| 95 # cleanup: moved templatebuilder into templates.builder | |
| 96 # | |
| 92 # Revision 1.14 2002/02/05 09:59:05 grubert | 97 # 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. | 98 # . makeHtmlBase: re.sub under python 2.2 did not replace '.', string.replace does it. |
| 94 # | 99 # |
| 95 # Revision 1.13 2001/11/22 15:46:42 jhermann | 100 # Revision 1.13 2001/11/22 15:46:42 jhermann |
| 96 # Added module docstrings to all modules. | 101 # Added module docstrings to all modules. |
