Skip to content

Commit 6dc0692

Browse files
author
Richard Jones
committed
implemented munging of template name for installed trackers
1 parent 1238b12 commit 6dc0692

File tree

3 files changed

+79
-42
lines changed

3 files changed

+79
-42
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Feature:
1212
- all RDBMS backends now have indexes on several columns
1313
- Change nosymessage and send_message to accept msgid=None (RFE #707235).
1414
- Handle Resent-From: headers (sf bug 841151)
15+
- Existing trackers (ie. live ones) may be used as templates for new
16+
trackers - the TEMPLATE-INFO.txt name entry has the tracker's dir name
17+
appended (so the demo tracker's template name is "classic-demo")
1518

1619
Fixed:
1720
- mysql documentation fixed to note requirement of 4.0+ and InnoDB

roundup/admin.py

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: admin.py,v 1.60 2003-11-11 00:35:13 richard Exp $
19+
# $Id: admin.py,v 1.61 2003-11-13 04:12:10 richard Exp $
2020

2121
'''Administration commands for maintaining Roundup trackers.
2222
'''
@@ -305,7 +305,7 @@ def listTemplates(self):
305305
path = os.path.dirname(path)
306306
tdir = os.path.join(path, 'share', 'roundup', 'templates')
307307
if os.path.isdir(tdir):
308-
templates = listTemplates(tdir)
308+
templates = init.listTemplates(tdir)
309309
break
310310

311311
# OK, now try as if we're in the roundup source distribution
@@ -316,13 +316,13 @@ def listTemplates(self):
316316
path = os.path.dirname(path)
317317
tdir = os.path.join(path, 'templates')
318318
if os.path.isdir(tdir):
319-
templates.update(listTemplates(tdir))
319+
templates.update(init.listTemplates(tdir))
320320

321321
# Try subdirs of the current dir
322-
templates.update(listTemplates(os.getcwd()))
322+
templates.update(init.listTemplates(os.getcwd()))
323323

324324
# Finally, try the current directory as a template
325-
template = loadTemplate(os.getcwd())
325+
template = init.loadTemplateInfo(os.getcwd())
326326
if template:
327327
templates[template['name']] = template
328328

@@ -1344,41 +1344,6 @@ def main(self):
13441344
if self.db:
13451345
self.db.close()
13461346

1347-
1348-
def listTemplates(dir):
1349-
''' List all the Roundup template directories in a given directory.
1350-
1351-
Find all the dirs that contain a TEMPLATE-INFO.txt and parse it.
1352-
1353-
Return a list of dicts of info about the templates.
1354-
'''
1355-
ret = {}
1356-
for idir in os.listdir(dir):
1357-
idir = os.path.join(dir, idir)
1358-
ti = loadTemplate(idir)
1359-
if ti:
1360-
ret[ti['name']] = ti
1361-
return ret
1362-
1363-
def loadTemplate(dir):
1364-
''' Attempt to load a Roundup template from the indicated directory.
1365-
1366-
Return None if there's no template, otherwise a template info
1367-
dictionary.
1368-
'''
1369-
ti = os.path.join(dir, 'TEMPLATE-INFO.txt')
1370-
if not os.path.exists(ti):
1371-
return None
1372-
1373-
# load up the template's information
1374-
m = rfc822.Message(open(ti))
1375-
ti = {}
1376-
ti['name'] = m['name']
1377-
ti['description'] = m['description']
1378-
ti['intended-for'] = m['intended-for']
1379-
ti['path'] = dir
1380-
return ti
1381-
13821347
if __name__ == '__main__':
13831348
tool = AdminTool()
13841349
sys.exit(tool.main())

roundup/init.py

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: init.py,v 1.27 2003-07-28 23:19:21 richard Exp $
18+
# $Id: init.py,v 1.28 2003-11-13 04:12:10 richard Exp $
1919

2020
__doc__ = """
2121
Init (create) a roundup instance.
2222
"""
2323

24-
import os, sys, errno
24+
import os, sys, errno, rfc822
2525

2626
import roundup.instance, password
2727
from roundup import install_util
@@ -86,6 +86,75 @@ def install(instance_home, template):
8686
# At the moment, it's just a copy
8787
copytree(template, instance_home)
8888

89+
# rename the tempate in the TEMPLATE-INFO.txt file
90+
ti = loadTemplateInfo(instance_home)
91+
ti['name'] = ti['name'] + '-' + os.path.split(instance_home)[1]
92+
saveTemplateInfo(instance_home, ti)
93+
94+
95+
def listTemplates(dir):
96+
''' List all the Roundup template directories in a given directory.
97+
98+
Find all the dirs that contain a TEMPLATE-INFO.txt and parse it.
99+
100+
Return a list of dicts of info about the templates.
101+
'''
102+
ret = {}
103+
for idir in os.listdir(dir):
104+
idir = os.path.join(dir, idir)
105+
ti = loadTemplateInfo(idir)
106+
if ti:
107+
ret[ti['name']] = ti
108+
return ret
109+
110+
def loadTemplateInfo(dir):
111+
''' Attempt to load a Roundup template from the indicated directory.
112+
113+
Return None if there's no template, otherwise a template info
114+
dictionary.
115+
'''
116+
ti = os.path.join(dir, 'TEMPLATE-INFO.txt')
117+
if not os.path.exists(ti):
118+
return None
119+
120+
# load up the template's information
121+
f = open(ti)
122+
try:
123+
m = rfc822.Message(open(ti))
124+
ti = {}
125+
ti['name'] = m['name']
126+
ti['description'] = m['description']
127+
ti['intended-for'] = m['intended-for']
128+
ti['path'] = dir
129+
finally:
130+
f.close()
131+
return ti
132+
133+
def writeHeader(name, value):
134+
''' Write an rfc822-compatible header line, making it wrap reasonably
135+
'''
136+
out = [name.capitalize() + ':']
137+
n = len(out[0])
138+
for word in value.split():
139+
if len(word) + n > 74:
140+
out.append('\n')
141+
n = 0
142+
out.append(' ' + word)
143+
n += len(out[-1])
144+
return ''.join(out) + '\n'
145+
146+
def saveTemplateInfo(dir, info):
147+
''' Save the template info (dict of values) to the TEMPLATE-INFO.txt
148+
file in the indicated directory.
149+
'''
150+
ti = os.path.join(dir, 'TEMPLATE-INFO.txt')
151+
f = open(ti, 'w')
152+
try:
153+
for name in 'name description intended-for path'.split():
154+
f.write(writeHeader(name, info[name]))
155+
finally:
156+
f.close()
157+
89158
def write_select_db(instance_home, backend):
90159
''' Write the file that selects the backend for the tracker
91160
'''

0 commit comments

Comments
 (0)