From ade2b8b84eee1b055043145f715717b24a0c4bcb Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 17 Apr 2003 03:38:00 +0000 Subject: [PATCH] moving templates around git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1663 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 3 + MANIFEST.in | 4 +- roundup/admin.py | 76 ++- roundup/cgi/templating.py | 40 +- roundup/init.py | 18 +- roundup/mailgw.py | 3 +- roundup/templates/.cvsignore | 5 - roundup/templates/README.txt | 14 - roundup/templates/__init__.py | 32 -- roundup/templates/builder.py | 92 --- setup.py | 56 +- .../classic/.cvsignore | 0 templates/classic/TEMPLATE-INFO.txt | 7 + .../classic/__init__.py | 2 +- .../templates => templates}/classic/config.py | 2 +- .../templates => templates}/classic/dbinit.py | 2 +- .../classic/detectors/.cvsignore | 0 .../classic/detectors/__init__.py | 2 +- .../classic/detectors/messagesummary.py | 2 +- .../classic/detectors/nosyreaction.py | 2 +- .../classic/detectors/statusauditor.py | 2 +- .../classic/html/_generic.help.html | 0 .../classic/html/_generic.index.html | 0 .../classic/html/_generic.item.html | 0 .../classic/html/file.index.html | 0 .../classic/html/file.item.html | 0 .../classic/html/home.classlist.html | 0 .../home => templates/classic/html/home.html | 0 .../classic/html/issue.index.html | 0 .../classic/html/issue.item.html | 0 .../classic/html/issue.search.html | 0 .../classic/html/keyword.item.html | 0 .../classic/html/msg.index.html | 0 .../classic/html/msg.item.html | 0 .../page => templates/classic/html/page.html | 0 .../classic/html/query.item.html | 0 .../classic/html/style.css | 0 .../classic/html/user.forgotten.html | 0 .../classic/html/user.index.html | 0 .../classic/html/user.item.html | 0 .../classic/html/user.register.html | 0 .../classic/html/user.rego_progress.html | 0 templates/classic/htmlbase.py | 529 ++++++++++++++++++ .../classic}/interfaces.py | 2 +- .../minimal/.cvsignore | 0 templates/minimal/TEMPLATE-INFO.txt | 8 + .../minimal/__init__.py | 2 +- .../templates => templates}/minimal/config.py | 2 +- .../templates => templates}/minimal/dbinit.py | 2 +- .../minimal/detectors/.cvsignore | 0 .../minimal/detectors/__init__.py | 2 +- .../minimal/html/_generic.help.html | 0 .../minimal/html/_generic.index.html | 0 .../minimal/html/_generic.item.html | 0 .../minimal/html/home.classlist.html | 0 .../home => templates/minimal/html/home.html | 0 .../page => templates/minimal/html/page.html | 0 .../minimal/html/style.css | 0 .../minimal/html/user.index.html | 0 .../minimal/html/user.item.html | 0 .../minimal/html/user.register.html | 0 .../minimal}/interfaces.py | 2 +- 62 files changed, 675 insertions(+), 238 deletions(-) delete mode 100644 roundup/templates/.cvsignore delete mode 100644 roundup/templates/README.txt delete mode 100644 roundup/templates/__init__.py delete mode 100644 roundup/templates/builder.py rename {roundup/templates => templates}/classic/.cvsignore (100%) create mode 100644 templates/classic/TEMPLATE-INFO.txt rename {roundup/templates => templates}/classic/__init__.py (94%) rename {roundup/templates => templates}/classic/config.py (98%) rename {roundup/templates => templates}/classic/dbinit.py (99%) rename {roundup/templates => templates}/classic/detectors/.cvsignore (100%) rename {roundup/templates => templates}/classic/detectors/__init__.py (96%) rename {roundup/templates => templates}/classic/detectors/messagesummary.py (88%) rename {roundup/templates => templates}/classic/detectors/nosyreaction.py (98%) rename {roundup/templates => templates}/classic/detectors/statusauditor.py (97%) rename roundup/templates/classic/html/_generic.help => templates/classic/html/_generic.help.html (100%) rename roundup/templates/classic/html/_generic.index => templates/classic/html/_generic.index.html (100%) rename roundup/templates/classic/html/_generic.item => templates/classic/html/_generic.item.html (100%) rename roundup/templates/classic/html/file.index => templates/classic/html/file.index.html (100%) rename roundup/templates/classic/html/file.item => templates/classic/html/file.item.html (100%) rename roundup/templates/classic/html/home.classlist => templates/classic/html/home.classlist.html (100%) rename roundup/templates/classic/html/home => templates/classic/html/home.html (100%) rename roundup/templates/classic/html/issue.index => templates/classic/html/issue.index.html (100%) rename roundup/templates/classic/html/issue.item => templates/classic/html/issue.item.html (100%) rename roundup/templates/classic/html/issue.search => templates/classic/html/issue.search.html (100%) rename roundup/templates/classic/html/keyword.item => templates/classic/html/keyword.item.html (100%) rename roundup/templates/classic/html/msg.index => templates/classic/html/msg.index.html (100%) rename roundup/templates/classic/html/msg.item => templates/classic/html/msg.item.html (100%) rename roundup/templates/classic/html/page => templates/classic/html/page.html (100%) rename roundup/templates/classic/html/query.item => templates/classic/html/query.item.html (100%) mode change 100755 => 100644 rename {roundup/templates => templates}/classic/html/style.css (100%) rename roundup/templates/classic/html/user.forgotten => templates/classic/html/user.forgotten.html (100%) rename roundup/templates/classic/html/user.index => templates/classic/html/user.index.html (100%) rename roundup/templates/classic/html/user.item => templates/classic/html/user.item.html (100%) rename roundup/templates/classic/html/user.register => templates/classic/html/user.register.html (100%) rename roundup/templates/classic/html/user.rego_progress => templates/classic/html/user.rego_progress.html (100%) create mode 100644 templates/classic/htmlbase.py rename {roundup/templates/minimal => templates/classic}/interfaces.py (95%) rename {roundup/templates => templates}/minimal/.cvsignore (100%) create mode 100644 templates/minimal/TEMPLATE-INFO.txt rename {roundup/templates => templates}/minimal/__init__.py (94%) rename {roundup/templates => templates}/minimal/config.py (98%) rename {roundup/templates => templates}/minimal/dbinit.py (98%) rename {roundup/templates => templates}/minimal/detectors/.cvsignore (100%) rename {roundup/templates => templates}/minimal/detectors/__init__.py (96%) rename roundup/templates/minimal/html/_generic.help => templates/minimal/html/_generic.help.html (100%) rename roundup/templates/minimal/html/_generic.index => templates/minimal/html/_generic.index.html (100%) rename roundup/templates/minimal/html/_generic.item => templates/minimal/html/_generic.item.html (100%) rename roundup/templates/minimal/html/home.classlist => templates/minimal/html/home.classlist.html (100%) rename roundup/templates/minimal/html/home => templates/minimal/html/home.html (100%) rename roundup/templates/minimal/html/page => templates/minimal/html/page.html (100%) rename {roundup/templates => templates}/minimal/html/style.css (100%) rename roundup/templates/minimal/html/user.index => templates/minimal/html/user.index.html (100%) rename roundup/templates/minimal/html/user.item => templates/minimal/html/user.item.html (100%) rename roundup/templates/minimal/html/user.register => templates/minimal/html/user.register.html (100%) rename {roundup/templates/classic => templates/minimal}/interfaces.py (95%) diff --git a/CHANGES.txt b/CHANGES.txt index fc64ee6..900ea99 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -59,6 +59,9 @@ Feature: - added command-line functionality for roundup-adming (sf feature 687664) - added nicer popup windows for topic, nosy, etc (has add/remove buttons) thanks Gus Gollings +- HTML templating files now have a .html extension +- Roundup templates are now distributed much more sanely, allowing for + 3rd-party templates. Fixed: diff --git a/MANIFEST.in b/MANIFEST.in index a0cbe81..26aa1a6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -recursive-include roundup *.* home* page* +recursive-include roundup *.* recursive-include frontends *.* recursive-include scripts *.* *-* recursive-include tools *.* @@ -6,8 +6,10 @@ recursive-include cgi-bin *.cgi recursive-include test *.py *.txt recursive-include doc *.html *.png *.txt *.css *.1 recursive-include detectors *.py +recursive-include templates *.* home* page* recursive-exclude roundup *.pyc *.pyo .cvsignore recursive-exclude frontends *.pyc *.pyo .cvsignore +recursive-exclude templates *.pyc *.pyo .cvsignore include run_tests *.txt exclude BUILD.txt I18N_PROGRESS.txt TODO.txt exclude doc/security.txt doc/templating.txt diff --git a/roundup/admin.py b/roundup/admin.py index 65bfa8c..fda6e46 100644 --- a/roundup/admin.py +++ b/roundup/admin.py @@ -16,12 +16,12 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: admin.py,v 1.50 2003-03-27 05:23:39 richard Exp $ +# $Id: admin.py,v 1.51 2003-04-17 03:37:57 richard Exp $ '''Administration commands for maintaining Roundup trackers. ''' -import sys, os, getpass, getopt, re, UserDict, shlex, shutil +import sys, os, getpass, getopt, re, UserDict, shlex, shutil, rfc822 try: import csv except ImportError: @@ -278,10 +278,43 @@ Command help: print line return 0 + def listTemplates(self): + ''' List all the available templates. + + Look in three places: + /share/roundup/templates + <__file__>/../templates + current dir + ''' + # OK, try /share/roundup/templates + # -- this module (roundup.admin) will be installed in something + # _like_ /usr/lib/python2.2/site-packages/roundup/admin.py, and + # we're interested in where the "lib" directory is - ie. the /usr/ + # part + path = __file__ + for i in range(5): + path = os.path.dirname(path) + tdir = os.path.join(path, 'share', 'roundup', 'templates') + if os.path.isdir(tdir): + templates = listTemplates(tdir) + else: + templates = {} + + # OK, now try as if we're in the roundup source distribution + # directory, so this module will be in .../roundup-*/roundup/admin.py + # and we're interested in the .../roundup-*/ part. + path = __file__ + for i in range(2): + path = os.path.dirname(path) + tdir = os.path.join(path, 'templates') + if os.path.isdir(tdir): + templates.update(listTemplates(tdir)) + + return templates + def help_initopts(self): - import roundup.templates - templates = roundup.templates.listTemplates() - print _('Templates:'), ', '.join(templates) + templates = self.listTemplates() + print _('Templates:'), ', '.join(templates.keys()) import roundup.backends backends = roundup.backends.__all__ print _('Back ends:'), ', '.join(backends) @@ -312,12 +345,11 @@ Command help: ' does not exist')%locals() # select template - import roundup.templates - templates = roundup.templates.listTemplates() + templates = self.listTemplates() template = len(args) > 1 and args[1] or '' - if template not in templates: - print _('Templates:'), ', '.join(templates) - while template not in templates: + if not templates.has_key(template): + print _('Templates:'), ', '.join(templates.keys()) + while not templates.has_key(template): template = raw_input(_('Select template [classic]: ')).strip() if not template: template = 'classic' @@ -335,7 +367,7 @@ Command help: # XXX perform a unit test based on the user's selections # install! - init.install(tracker_home, template) + init.install(tracker_home, templates[template]['path']) init.write_select_db(tracker_home, backend) print _(''' @@ -1377,6 +1409,28 @@ Date format is "YYYY-MM-DD" eg: if self.db: self.db.close() + +def listTemplates(dir): + ''' List all the Roundup template directories in a given directory. + + Find all the dirs that contain a TEMPLATE-INFO.txt and parse it. + + Return a list of dicts of info about the templates. + ''' + ret = {} + for idir in os.listdir(dir): + idir = os.path.join(dir, idir) + ti = os.path.join(idir, 'TEMPLATE-INFO.txt') + if os.path.isfile(ti): + m = rfc822.Message(open(ti)) + ti = {} + ti['name'] = m['name'] + ti['description'] = m['description'] + ti['intended-for'] = m['intended-for'] + ti['path'] = idir + ret[m['name']] = ti + return ret + if __name__ == '__main__': tool = AdminTool() sys.exit(tool.main()) diff --git a/roundup/cgi/templating.py b/roundup/cgi/templating.py index e2d2b6c..4eacc8c 100644 --- a/roundup/cgi/templating.py +++ b/roundup/cgi/templating.py @@ -38,9 +38,9 @@ class Templates: if os.path.isdir(filename): continue if '.' in filename: name, extension = filename.split('.') - self.getTemplate(name, extension) + self.get(name, extension) else: - self.getTemplate(filename, None) + self.get(filename, None) def get(self, name, extension=None): ''' Interface to get a template, possibly loading a compiled template. @@ -66,27 +66,31 @@ class Templates: filename = name src = os.path.join(self.dir, filename) + if not os.path.exists(src): + filename = filename + '.html' + src = os.path.join(self.dir, filename) + if not os.path.exists(src): + if not extension: + raise NoTemplate, 'Template file "%s" doesn\'t exist'%name + + # try for a generic template + generic = '_generic.%s'%extension + src = os.path.join(self.dir, generic) + if not os.path.exists(src): + generic = '_generic.%s.html'%extension + src = os.path.join(self.dir, generic) + if not os.path.exists(src): + raise NoTemplate, 'No template file exists for '\ + 'templating "%s" with template "%s" (neither '\ + '"%s" nor "%s")'%(name, extension, filename, + generic) + filename = generic + try: stime = os.stat(src)[os.path.stat.ST_MTIME] except os.error, error: if error.errno != errno.ENOENT: raise - if not extension: - raise NoTemplate, 'Template file "%s" doesn\'t exist'%name - - # try for a generic template - generic = '_generic.%s'%extension - src = os.path.join(self.dir, generic) - try: - stime = os.stat(src)[os.path.stat.ST_MTIME] - except os.error, error: - if error.errno != errno.ENOENT: - raise - # nicer error - raise NoTemplate, 'No template file exists for templating '\ - '"%s" with template "%s" (neither "%s" nor "%s")'%(name, - extension, filename, generic) - filename = generic if self.templates.has_key(src) and \ stime < self.templates[src].mtime: diff --git a/roundup/init.py b/roundup/init.py index 9a7ffc5..fd7124c 100644 --- a/roundup/init.py +++ b/roundup/init.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: init.py,v 1.25 2003-02-25 10:19:31 richard Exp $ +# $Id: init.py,v 1.26 2003-04-17 03:37:58 richard Exp $ __doc__ = """ Init (create) a roundup instance. @@ -58,8 +58,8 @@ def install(instance_home, template): '''Install an instance using the named template and backend. instance_home - the directory to place the instance data in - template - the template to use in creating the instance data - backend - the database to use to store the instance data + template - the directory holding the template to use in creating + the instance data The instance_home directory will be created using the files found in the named template (roundup.templates.). A standard instance_home @@ -82,20 +82,10 @@ def install(instance_home, template): . detectors/ - the auditor and reactor modules for this instance - The html directory is typically extracted from the htmlbase module in - the template. ''' - # first, copy the template dir over - from roundup.templates import builder - - # copy the roundup.templates.