From 3672525c4b672983b961cbab8a9751a6fda66989 Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 13 Nov 2003 04:12:10 +0000 Subject: [PATCH] implemented munging of template name for installed trackers git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1984 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 3 ++ roundup/admin.py | 45 ++++------------------------- roundup/init.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 79 insertions(+), 42 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index c26a27c..4cd4ff7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -12,6 +12,9 @@ Feature: - all RDBMS backends now have indexes on several columns - Change nosymessage and send_message to accept msgid=None (RFE #707235). - Handle Resent-From: headers (sf bug 841151) +- Existing trackers (ie. live ones) may be used as templates for new + trackers - the TEMPLATE-INFO.txt name entry has the tracker's dir name + appended (so the demo tracker's template name is "classic-demo") Fixed: - mysql documentation fixed to note requirement of 4.0+ and InnoDB diff --git a/roundup/admin.py b/roundup/admin.py index 107e639..9ae6ba3 100644 --- a/roundup/admin.py +++ b/roundup/admin.py @@ -16,7 +16,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: admin.py,v 1.60 2003-11-11 00:35:13 richard Exp $ +# $Id: admin.py,v 1.61 2003-11-13 04:12:10 richard Exp $ '''Administration commands for maintaining Roundup trackers. ''' @@ -305,7 +305,7 @@ Command help: path = os.path.dirname(path) tdir = os.path.join(path, 'share', 'roundup', 'templates') if os.path.isdir(tdir): - templates = listTemplates(tdir) + templates = init.listTemplates(tdir) break # OK, now try as if we're in the roundup source distribution @@ -316,13 +316,13 @@ Command help: path = os.path.dirname(path) tdir = os.path.join(path, 'templates') if os.path.isdir(tdir): - templates.update(listTemplates(tdir)) + templates.update(init.listTemplates(tdir)) # Try subdirs of the current dir - templates.update(listTemplates(os.getcwd())) + templates.update(init.listTemplates(os.getcwd())) # Finally, try the current directory as a template - template = loadTemplate(os.getcwd()) + template = init.loadTemplateInfo(os.getcwd()) if template: templates[template['name']] = template @@ -1344,41 +1344,6 @@ 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 = loadTemplate(idir) - if ti: - ret[ti['name']] = ti - return ret - -def loadTemplate(dir): - ''' Attempt to load a Roundup template from the indicated directory. - - Return None if there's no template, otherwise a template info - dictionary. - ''' - ti = os.path.join(dir, 'TEMPLATE-INFO.txt') - if not os.path.exists(ti): - return None - - # load up the template's information - m = rfc822.Message(open(ti)) - ti = {} - ti['name'] = m['name'] - ti['description'] = m['description'] - ti['intended-for'] = m['intended-for'] - ti['path'] = dir - return ti - if __name__ == '__main__': tool = AdminTool() sys.exit(tool.main()) diff --git a/roundup/init.py b/roundup/init.py index 804ed31..25668c5 100644 --- a/roundup/init.py +++ b/roundup/init.py @@ -15,13 +15,13 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: init.py,v 1.27 2003-07-28 23:19:21 richard Exp $ +# $Id: init.py,v 1.28 2003-11-13 04:12:10 richard Exp $ __doc__ = """ Init (create) a roundup instance. """ -import os, sys, errno +import os, sys, errno, rfc822 import roundup.instance, password from roundup import install_util @@ -86,6 +86,75 @@ def install(instance_home, template): # At the moment, it's just a copy copytree(template, instance_home) + # rename the tempate in the TEMPLATE-INFO.txt file + ti = loadTemplateInfo(instance_home) + ti['name'] = ti['name'] + '-' + os.path.split(instance_home)[1] + saveTemplateInfo(instance_home, ti) + + +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 = loadTemplateInfo(idir) + if ti: + ret[ti['name']] = ti + return ret + +def loadTemplateInfo(dir): + ''' Attempt to load a Roundup template from the indicated directory. + + Return None if there's no template, otherwise a template info + dictionary. + ''' + ti = os.path.join(dir, 'TEMPLATE-INFO.txt') + if not os.path.exists(ti): + return None + + # load up the template's information + f = open(ti) + try: + m = rfc822.Message(open(ti)) + ti = {} + ti['name'] = m['name'] + ti['description'] = m['description'] + ti['intended-for'] = m['intended-for'] + ti['path'] = dir + finally: + f.close() + return ti + +def writeHeader(name, value): + ''' Write an rfc822-compatible header line, making it wrap reasonably + ''' + out = [name.capitalize() + ':'] + n = len(out[0]) + for word in value.split(): + if len(word) + n > 74: + out.append('\n') + n = 0 + out.append(' ' + word) + n += len(out[-1]) + return ''.join(out) + '\n' + +def saveTemplateInfo(dir, info): + ''' Save the template info (dict of values) to the TEMPLATE-INFO.txt + file in the indicated directory. + ''' + ti = os.path.join(dir, 'TEMPLATE-INFO.txt') + f = open(ti, 'w') + try: + for name in 'name description intended-for path'.split(): + f.write(writeHeader(name, info[name])) + finally: + f.close() + def write_select_db(instance_home, backend): ''' Write the file that selects the backend for the tracker ''' -- 2.30.2