Mercurial > p > roundup > code
comparison roundup/templatebuilder.py @ 113:2ab86442799a
Replaced errno integers with their module values.
De-tabbed templatebuilder.py
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sat, 28 Jul 2001 07:59:53 +0000 |
| parents | 0b250446cf8b |
| children | caca379e12d3 |
comparison
equal
deleted
inserted
replaced
| 112:e4170b2b2561 | 113:2ab86442799a |
|---|---|
| 1 import errno | |
| 2 | |
| 1 preamble = """ | 3 preamble = """ |
| 2 # Do Not Edit (Unless You Want To) | 4 # Do Not Edit (Unless You Want To) |
| 3 # This file automagically generated by roundup.htmldata.makeHtmlBase | 5 # This file automagically generated by roundup.htmldata.makeHtmlBase |
| 4 # | 6 # |
| 5 """ | 7 """ |
| 13 filelist = filter(os.path.isfile, filelist) # only want files | 15 filelist = filter(os.path.isfile, filelist) # only want files |
| 14 filelist.sort() | 16 filelist.sort() |
| 15 fd = open(os.path.join(templateDir, 'htmlbase.py'), 'w') | 17 fd = open(os.path.join(templateDir, 'htmlbase.py'), 'w') |
| 16 fd.write(preamble) | 18 fd.write(preamble) |
| 17 for file in filelist: | 19 for file in filelist: |
| 18 mangled_name = os.path.basename(re.sub(r'\.', 'DOT', file)) | 20 mangled_name = os.path.basename(re.sub(r'\.', 'DOT', file)) |
| 19 fd.write('%s = """'%mangled_name) | 21 fd.write('%s = """'%mangled_name) |
| 20 fd.write(open(file).read()) | 22 fd.write(open(file).read()) |
| 21 fd.write('"""\n\n') | 23 fd.write('"""\n\n') |
| 22 fd.close() | 24 fd.close() |
| 23 | 25 |
| 24 def installHtmlBase(template, installDir): | 26 def installHtmlBase(template, installDir): |
| 25 """ passed a template package and an installDir, unpacks the html files into | 27 """ passed a template package and an installDir, unpacks the html files into |
| 26 the installdir """ | 28 the installdir """ |
| 27 import os,sys,re | 29 import os,sys,re |
| 28 | 30 |
| 29 tdir = __import__('roundup.templates.%s.htmlbase'%template).templates | 31 tdir = __import__('roundup.templates.%s.htmlbase'%template).templates |
| 30 if hasattr(tdir, template): | 32 if hasattr(tdir, template): |
| 31 tmod = getattr(tdir, template) | 33 tmod = getattr(tdir, template) |
| 32 else: | 34 else: |
| 33 raise "TemplateError", \ | 35 raise "TemplateError", "couldn't find roundup.template.%s.htmlbase"%template |
| 34 "couldn't find roundup.template.%s.htmlbase"%template | |
| 35 htmlbase = tmod.htmlbase | 36 htmlbase = tmod.htmlbase |
| 36 installDir = os.path.join(installDir, 'html') | 37 installDir = os.path.join(installDir, 'html') |
| 37 os.makedirs(installDir) | 38 try: |
| 39 os.makedirs(installDir) | |
| 40 except IOError, error: | |
| 41 if error.errno != errno.EEXIST: raise | |
| 38 | 42 |
| 39 print "installing from", htmlbase.__file__, "into", installDir | 43 print "installing from", htmlbase.__file__, "into", installDir |
| 40 modulecontents = dir(htmlbase) | 44 modulecontents = dir(htmlbase) |
| 41 for mangledfile in modulecontents: | 45 for mangledfile in modulecontents: |
| 42 if mangledfile[0] == "_": | 46 if mangledfile[0] == "_": |
| 43 continue | 47 continue |
| 44 filename = re.sub('DOT', '.', mangledfile) | 48 filename = re.sub('DOT', '.', mangledfile) |
| 45 outfile = os.path.join(installDir, filename) | 49 outfile = os.path.join(installDir, filename) |
| 46 outfd = open(outfile, 'w') | 50 outfd = open(outfile, 'w') |
| 47 data = getattr(htmlbase, mangledfile) | 51 data = getattr(htmlbase, mangledfile) |
| 48 outfd.write(data) | 52 outfd.write(data) |
| 49 | 53 |
| 50 | 54 |
| 51 | 55 |
| 52 if __name__ == "__main__": | 56 if __name__ == "__main__": |
| 53 import sys | 57 import sys |
| 54 if len(sys.argv) == 2: | 58 if len(sys.argv) == 2: |
| 55 makeHtmlBase(sys.argv[1]) | 59 makeHtmlBase(sys.argv[1]) |
| 56 elif len(sys.argv) == 3: | 60 elif len(sys.argv) == 3: |
| 57 installHtmlBase(sys.argv[1], sys.argv[2]) | 61 installHtmlBase(sys.argv[1], sys.argv[2]) |
| 58 else: | 62 else: |
| 59 raise "what you talkin about willis?" | 63 raise "what you talkin about willis?" |
| 64 |
