Skip to content

Commit 434f806

Browse files
author
Richard Jones
committed
moving templates around
1 parent 93c86f9 commit 434f806

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+675
-238
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ Feature:
5959
- added command-line functionality for roundup-adming (sf feature 687664)
6060
- added nicer popup windows for topic, nosy, etc (has add/remove buttons)
6161
thanks Gus Gollings
62+
- HTML templating files now have a .html extension
63+
- Roundup templates are now distributed much more sanely, allowing for
64+
3rd-party templates.
6265

6366

6467
Fixed:

MANIFEST.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
recursive-include roundup *.* home* page*
1+
recursive-include roundup *.*
22
recursive-include frontends *.*
33
recursive-include scripts *.* *-*
44
recursive-include tools *.*
55
recursive-include cgi-bin *.cgi
66
recursive-include test *.py *.txt
77
recursive-include doc *.html *.png *.txt *.css *.1
88
recursive-include detectors *.py
9+
recursive-include templates *.* home* page*
910
recursive-exclude roundup *.pyc *.pyo .cvsignore
1011
recursive-exclude frontends *.pyc *.pyo .cvsignore
12+
recursive-exclude templates *.pyc *.pyo .cvsignore
1113
include run_tests *.txt
1214
exclude BUILD.txt I18N_PROGRESS.txt TODO.txt
1315
exclude doc/security.txt doc/templating.txt

roundup/admin.py

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: admin.py,v 1.50 2003-03-27 05:23:39 richard Exp $
19+
# $Id: admin.py,v 1.51 2003-04-17 03:37:57 richard Exp $
2020

2121
'''Administration commands for maintaining Roundup trackers.
2222
'''
2323

24-
import sys, os, getpass, getopt, re, UserDict, shlex, shutil
24+
import sys, os, getpass, getopt, re, UserDict, shlex, shutil, rfc822
2525
try:
2626
import csv
2727
except ImportError:
@@ -278,10 +278,43 @@ def do_help(self, args, nl_re=re.compile('[\r\n]'),
278278
print line
279279
return 0
280280

281+
def listTemplates(self):
282+
''' List all the available templates.
283+
284+
Look in three places:
285+
<prefix>/share/roundup/templates
286+
<__file__>/../templates
287+
current dir
288+
'''
289+
# OK, try <prefix>/share/roundup/templates
290+
# -- this module (roundup.admin) will be installed in something
291+
# _like_ /usr/lib/python2.2/site-packages/roundup/admin.py, and
292+
# we're interested in where the "lib" directory is - ie. the /usr/
293+
# part
294+
path = __file__
295+
for i in range(5):
296+
path = os.path.dirname(path)
297+
tdir = os.path.join(path, 'share', 'roundup', 'templates')
298+
if os.path.isdir(tdir):
299+
templates = listTemplates(tdir)
300+
else:
301+
templates = {}
302+
303+
# OK, now try as if we're in the roundup source distribution
304+
# directory, so this module will be in .../roundup-*/roundup/admin.py
305+
# and we're interested in the .../roundup-*/ part.
306+
path = __file__
307+
for i in range(2):
308+
path = os.path.dirname(path)
309+
tdir = os.path.join(path, 'templates')
310+
if os.path.isdir(tdir):
311+
templates.update(listTemplates(tdir))
312+
313+
return templates
314+
281315
def help_initopts(self):
282-
import roundup.templates
283-
templates = roundup.templates.listTemplates()
284-
print _('Templates:'), ', '.join(templates)
316+
templates = self.listTemplates()
317+
print _('Templates:'), ', '.join(templates.keys())
285318
import roundup.backends
286319
backends = roundup.backends.__all__
287320
print _('Back ends:'), ', '.join(backends)
@@ -312,12 +345,11 @@ def do_install(self, tracker_home, args):
312345
' does not exist')%locals()
313346

314347
# select template
315-
import roundup.templates
316-
templates = roundup.templates.listTemplates()
348+
templates = self.listTemplates()
317349
template = len(args) > 1 and args[1] or ''
318-
if template not in templates:
319-
print _('Templates:'), ', '.join(templates)
320-
while template not in templates:
350+
if not templates.has_key(template):
351+
print _('Templates:'), ', '.join(templates.keys())
352+
while not templates.has_key(template):
321353
template = raw_input(_('Select template [classic]: ')).strip()
322354
if not template:
323355
template = 'classic'
@@ -335,7 +367,7 @@ def do_install(self, tracker_home, args):
335367
# XXX perform a unit test based on the user's selections
336368

337369
# install!
338-
init.install(tracker_home, template)
370+
init.install(tracker_home, templates[template]['path'])
339371
init.write_select_db(tracker_home, backend)
340372

341373
print _('''
@@ -1377,6 +1409,28 @@ def main(self):
13771409
if self.db:
13781410
self.db.close()
13791411

1412+
1413+
def listTemplates(dir):
1414+
''' List all the Roundup template directories in a given directory.
1415+
1416+
Find all the dirs that contain a TEMPLATE-INFO.txt and parse it.
1417+
1418+
Return a list of dicts of info about the templates.
1419+
'''
1420+
ret = {}
1421+
for idir in os.listdir(dir):
1422+
idir = os.path.join(dir, idir)
1423+
ti = os.path.join(idir, 'TEMPLATE-INFO.txt')
1424+
if os.path.isfile(ti):
1425+
m = rfc822.Message(open(ti))
1426+
ti = {}
1427+
ti['name'] = m['name']
1428+
ti['description'] = m['description']
1429+
ti['intended-for'] = m['intended-for']
1430+
ti['path'] = idir
1431+
ret[m['name']] = ti
1432+
return ret
1433+
13801434
if __name__ == '__main__':
13811435
tool = AdminTool()
13821436
sys.exit(tool.main())

roundup/cgi/templating.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def precompileTemplates(self):
3838
if os.path.isdir(filename): continue
3939
if '.' in filename:
4040
name, extension = filename.split('.')
41-
self.getTemplate(name, extension)
41+
self.get(name, extension)
4242
else:
43-
self.getTemplate(filename, None)
43+
self.get(filename, None)
4444

4545
def get(self, name, extension=None):
4646
''' Interface to get a template, possibly loading a compiled template.
@@ -66,27 +66,31 @@ def get(self, name, extension=None):
6666
filename = name
6767

6868
src = os.path.join(self.dir, filename)
69+
if not os.path.exists(src):
70+
filename = filename + '.html'
71+
src = os.path.join(self.dir, filename)
72+
if not os.path.exists(src):
73+
if not extension:
74+
raise NoTemplate, 'Template file "%s" doesn\'t exist'%name
75+
76+
# try for a generic template
77+
generic = '_generic.%s'%extension
78+
src = os.path.join(self.dir, generic)
79+
if not os.path.exists(src):
80+
generic = '_generic.%s.html'%extension
81+
src = os.path.join(self.dir, generic)
82+
if not os.path.exists(src):
83+
raise NoTemplate, 'No template file exists for '\
84+
'templating "%s" with template "%s" (neither '\
85+
'"%s" nor "%s")'%(name, extension, filename,
86+
generic)
87+
filename = generic
88+
6989
try:
7090
stime = os.stat(src)[os.path.stat.ST_MTIME]
7191
except os.error, error:
7292
if error.errno != errno.ENOENT:
7393
raise
74-
if not extension:
75-
raise NoTemplate, 'Template file "%s" doesn\'t exist'%name
76-
77-
# try for a generic template
78-
generic = '_generic.%s'%extension
79-
src = os.path.join(self.dir, generic)
80-
try:
81-
stime = os.stat(src)[os.path.stat.ST_MTIME]
82-
except os.error, error:
83-
if error.errno != errno.ENOENT:
84-
raise
85-
# nicer error
86-
raise NoTemplate, 'No template file exists for templating '\
87-
'"%s" with template "%s" (neither "%s" nor "%s")'%(name,
88-
extension, filename, generic)
89-
filename = generic
9094

9195
if self.templates.has_key(src) and \
9296
stime < self.templates[src].mtime:

roundup/init.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: init.py,v 1.25 2003-02-25 10:19:31 richard Exp $
18+
# $Id: init.py,v 1.26 2003-04-17 03:37:58 richard Exp $
1919

2020
__doc__ = """
2121
Init (create) a roundup instance.
@@ -58,8 +58,8 @@ def install(instance_home, template):
5858
'''Install an instance using the named template and backend.
5959
6060
instance_home - the directory to place the instance data in
61-
template - the template to use in creating the instance data
62-
backend - the database to use to store the instance data
61+
template - the directory holding the template to use in creating
62+
the instance data
6363
6464
The instance_home directory will be created using the files found in
6565
the named template (roundup.templates.<name>). A standard instance_home
@@ -82,20 +82,10 @@ def install(instance_home, template):
8282
. detectors/
8383
- the auditor and reactor modules for this instance
8484
85-
The html directory is typically extracted from the htmlbase module in
86-
the template.
8785
'''
88-
# first, copy the template dir over
89-
from roundup.templates import builder
90-
91-
# copy the roundup.templates.<template> package contents to the instance dir
92-
template_dir = os.path.split(__file__)[0]
93-
template_name = template
94-
template = os.path.join(template_dir, 'templates', template)
86+
# At the moment, it's just a copy
9587
copytree(template, instance_home)
9688

97-
builder.installHtmlBase(template_name, instance_home)
98-
9989

10090
def write_select_db(instance_home, backend):
10191
''' Write the file that selects the backend for the tracker

roundup/mailgw.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.114 2003-04-10 05:12:41 richard Exp $
76+
$Id: mailgw.py,v 1.115 2003-04-17 03:37:59 richard Exp $
7777
'''
7878

7979
import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
@@ -806,6 +806,7 @@ def handle_message(self, message):
806806
# parse the body of the message, stripping out bits as appropriate
807807
summary, content = parseContent(content, keep_citations,
808808
keep_body)
809+
content = content.strip()
809810

810811
#
811812
# handle the attachments

roundup/templates/.cvsignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

roundup/templates/README.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

roundup/templates/__init__.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)