Skip to content

Commit 9c8a075

Browse files
author
Anthony Baxter
committed
Added templatebuilder module.
two functions - one to pack up the html base, one to unpack it. Packed up the two standard templates into htmlbases. Modified __init__ to install them. __init__.py magic was needed for the rather high levels of wierd import magic. Reducing level of import magic == (good, future)
1 parent 0b96279 commit 9c8a075

File tree

9 files changed

+956
-6
lines changed

9 files changed

+956
-6
lines changed

roundup/init.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: init.py,v 1.3 2001-07-23 08:45:28 richard Exp $
1+
# $Id: init.py,v 1.4 2001-07-24 10:46:22 anthonybaxter Exp $
22

33
import os, shutil, sys
44

@@ -35,10 +35,15 @@ def init(instance, template, backend, adminpw):
3535
''' initialise an instance using the named template
3636
'''
3737
# first, copy the template dir over
38+
import roundup.templatebuilder
39+
3840
template_dir = os.path.split(__file__)[0]
41+
template_name = template
3942
template = os.path.join(template_dir, 'templates', template)
4043
copytree(template, instance)
4144

45+
roundup.templatebuilder.installHtmlBase(template_name, instance)
46+
4247
# now select database
4348
db = '''# WARNING: DO NOT EDIT THIS FILE!!!
4449
from roundup.backends.back_%s import Database'''%backend
@@ -52,6 +57,11 @@ def init(instance, template, backend, adminpw):
5257

5358
#
5459
# $Log: not supported by cvs2svn $
60+
# Revision 1.3 2001/07/23 08:45:28 richard
61+
# ok, so now "./roundup-admin init" will ask questions in an attempt to get a
62+
# workable instance_home set up :)
63+
# _and_ anydbm has had its first test :)
64+
#
5565
# Revision 1.2 2001/07/22 12:09:32 richard
5666
# Final commit of Grande Splite
5767
#

roundup/templatebuilder.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
preamble = """
2+
# Do Not Edit (Unless You Want To)
3+
# This file automagically generated by roundup.htmldata.makeHtmlBase
4+
#
5+
"""
6+
7+
def makeHtmlBase(templateDir):
8+
""" make a htmlbase.py file in the given templateDir, from the
9+
contents of templateDir/html """
10+
import os, glob, re
11+
print "packing up templates in", templateDir
12+
filelist = glob.glob(os.path.join(templateDir, 'html', '*'))
13+
filelist = filter(os.path.isfile, filelist) # only want files
14+
filelist.sort()
15+
fd = open(os.path.join(templateDir, 'htmlbase.py'), 'w')
16+
fd.write(preamble)
17+
for file in filelist:
18+
mangled_name = os.path.basename(re.sub(r'\.', 'DOT', file))
19+
fd.write('%s = """'%mangled_name)
20+
fd.write(open(file).read())
21+
fd.write('"""\n\n')
22+
fd.close()
23+
24+
def installHtmlBase(template, installDir):
25+
""" passed a template package and an installDir, unpacks the html files into
26+
the installdir """
27+
import os,sys,re
28+
29+
tdir = __import__('roundup.templates.%s.htmlbase'%template).templates
30+
if hasattr(tdir, template):
31+
tmod = getattr(tdir, template)
32+
else:
33+
raise "TemplateError", \
34+
"couldn't find roundup.template.%s.htmlbase"%template
35+
htmlbase = tmod.htmlbase
36+
37+
print "installing from", htmlbase.__file__, "into", installDir
38+
modulecontents = dir(htmlbase)
39+
for mangledfile in modulecontents:
40+
if mangledfile[0] == "_":
41+
continue
42+
filename = re.sub('DOT', '.', mangledfile)
43+
outfile = os.path.join(installDir, filename)
44+
outfd = open(outfile, 'w')
45+
data = getattr(htmlbase, mangledfile)
46+
outfd.write(data)
47+
48+
49+
50+
if __name__ == "__main__":
51+
import sys
52+
if len(sys.argv) == 2:
53+
makeHtmlBase(sys.argv[1])
54+
elif len(sys.argv) == 3:
55+
installHtmlBase(sys.argv[1], sys.argv[2])
56+
else:
57+
raise "what you talkin about willis?"

roundup/templates/.cvsignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pyc

roundup/templates/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+

roundup/templates/classic/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
# $Id: __init__.py,v 1.1 2001-07-23 23:28:43 richard Exp $
1+
# $Id: __init__.py,v 1.2 2001-07-24 10:46:22 anthonybaxter Exp $
22

3+
import sys
34
from instance_config import *
4-
from dbinit import *
5+
try:
6+
from dbinit import *
7+
except:
8+
pass # in install dir (probably :)
59
from interfaces import *
610

711
#
812
# $Log: not supported by cvs2svn $
13+
# Revision 1.1 2001/07/23 23:28:43 richard
14+
# Adding the classic template
15+
#
916
# Revision 1.3 2001/07/23 23:16:01 richard
1017
# Split off the interfaces (CGI, mailgw) into a separate file from the DB stuff.
1118
#

roundup/templates/classic/dbinit.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# $Id: dbinit.py,v 1.2 2001-07-24 01:06:43 richard Exp $
1+
# $Id: dbinit.py,v 1.3 2001-07-24 10:46:22 anthonybaxter Exp $
22

33
import os
44

55
import instance_config
66
from roundup import roundupdb, cgi_client, mailgw
77
import select_db
8+
89
from roundup.roundupdb import Class, FileClass
910

1011
class Database(roundupdb.Database, select_db.Database):
@@ -106,6 +107,9 @@ def init(adminpw):
106107

107108
#
108109
# $Log: not supported by cvs2svn $
110+
# Revision 1.2 2001/07/24 01:06:43 richard
111+
# Oops - accidentally duped the keywords class
112+
#
109113
# Revision 1.1 2001/07/23 23:28:43 richard
110114
# Adding the classic template
111115
#

0 commit comments

Comments
 (0)