Skip to content

Commit 733fe56

Browse files
author
Richard Jones
committed
back-port template renaming fix
1 parent fdc18d2 commit 733fe56

File tree

3 files changed

+106
-63
lines changed

3 files changed

+106
-63
lines changed

CHANGES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
This file contains the changes to the Roundup system over time. The entries
22
are given with the most recent entry first.
33

4+
2004-??-?? 0.6.8
5+
Fixed:
6+
- existing trackers (ie. live ones) may be used as templates for new
7+
trackers - the TEMPLATE-INFO.txt name entry has the tracker's dir name
8+
appended (so the demo tracker's template name is "classic-demo")
9+
10+
411
2004-03-01 0.6.7
512
Fixed:
613
- be more backward-compatible when asking for EMAIL_CHARSET

roundup/admin.py

Lines changed: 5 additions & 39 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.55.2.2 2003-08-29 12:45:54 richard Exp $
19+
# $Id: admin.py,v 1.55.2.3 2004-03-05 00:06:20 richard Exp $
2020

2121
'''Administration commands for maintaining Roundup trackers.
2222
'''
@@ -298,7 +298,7 @@ def listTemplates(self):
298298
path = os.path.dirname(path)
299299
tdir = os.path.join(path, 'share', 'roundup', 'templates')
300300
if os.path.isdir(tdir):
301-
templates = listTemplates(tdir)
301+
templates = init.listTemplates(tdir)
302302
break
303303

304304
# OK, now try as if we're in the roundup source distribution
@@ -309,13 +309,13 @@ def listTemplates(self):
309309
path = os.path.dirname(path)
310310
tdir = os.path.join(path, 'templates')
311311
if os.path.isdir(tdir):
312-
templates.update(listTemplates(tdir))
312+
templates.update(init.listTemplates(tdir))
313313

314314
# Try subdirs of the current dir
315-
templates.update(listTemplates(os.getcwd()))
315+
templates.update(init.listTemplates(os.getcwd()))
316316

317317
# Finally, try the current directory as a template
318-
template = loadTemplate(os.getcwd())
318+
template = init.loadTemplateInfo(os.getcwd())
319319
if template:
320320
templates[template['name']] = template
321321

@@ -1407,40 +1407,6 @@ def main(self):
14071407
self.db.close()
14081408

14091409

1410-
def listTemplates(dir):
1411-
''' List all the Roundup template directories in a given directory.
1412-
1413-
Find all the dirs that contain a TEMPLATE-INFO.txt and parse it.
1414-
1415-
Return a list of dicts of info about the templates.
1416-
'''
1417-
ret = {}
1418-
for idir in os.listdir(dir):
1419-
idir = os.path.join(dir, idir)
1420-
ti = loadTemplate(idir)
1421-
if ti:
1422-
ret[ti['name']] = ti
1423-
return ret
1424-
1425-
def loadTemplate(dir):
1426-
''' Attempt to load a Roundup template from the indicated directory.
1427-
1428-
Return None if there's no template, otherwise a template info
1429-
dictionary.
1430-
'''
1431-
ti = os.path.join(dir, 'TEMPLATE-INFO.txt')
1432-
if not os.path.exists(ti):
1433-
return None
1434-
1435-
# load up the template's information
1436-
m = rfc822.Message(open(ti))
1437-
ti = {}
1438-
ti['name'] = m['name']
1439-
ti['description'] = m['description']
1440-
ti['intended-for'] = m['intended-for']
1441-
ti['path'] = dir
1442-
return ti
1443-
14441410
if __name__ == '__main__':
14451411
tool = AdminTool()
14461412
sys.exit(tool.main())

roundup/init.py

Lines changed: 94 additions & 24 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.27.2.1 2004-03-05 00:06:20 richard Exp $
1919

20-
__doc__ = """
21-
Init (create) a roundup instance.
20+
"""Init (create) a roundup instance.
2221
"""
22+
__docformat__ = 'restructuredtext'
2323

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

2626
import roundup.instance, password
2727
from roundup import install_util
@@ -57,35 +57,105 @@ def copytree(src, dst, symlinks=0):
5757
def install(instance_home, template):
5858
'''Install an instance using the named template and backend.
5959
60-
instance_home - the directory to place the instance data in
61-
template - the directory holding the template to use in creating
62-
the instance data
60+
'instance_home'
61+
the directory to place the instance data in
62+
'template'
63+
the directory holding the template to use in creating the instance data
6364
6465
The instance_home directory will be created using the files found in
6566
the named template (roundup.templates.<name>). A standard instance_home
6667
contains:
67-
. config.py
68-
- simple configuration of things like the email address for the
69-
mail gateway, the mail domain, the mail host, ...
70-
. dbinit.py and select_db.py
71-
- defines the schema for the hyperdatabase and indicates which
72-
backend to use.
73-
. interfaces.py
74-
- defines the CGI Client and mail gateway MailGW classes that are
75-
used by roundup.cgi, roundup-server and roundup-mailgw.
76-
. __init__.py
77-
- ties together all the instance information into one interface
78-
. db/
79-
- the actual database that stores the instance's data
80-
. html/
81-
- the html templates that are used by the CGI Client
82-
. detectors/
83-
- the auditor and reactor modules for this instance
8468
69+
config.py
70+
simple configuration of things like the email address for the
71+
mail gateway, the mail domain, the mail host, ...
72+
dbinit.py and select_db.py
73+
defines the schema for the hyperdatabase and indicates which
74+
backend to use.
75+
interfaces.py
76+
defines the CGI Client and mail gateway MailGW classes that are
77+
used by roundup.cgi, roundup-server and roundup-mailgw.
78+
__init__.py
79+
ties together all the instance information into one interface
80+
db/
81+
the actual database that stores the instance's data
82+
html/
83+
the html templates that are used by the CGI Client
84+
detectors/
85+
the auditor and reactor modules for this instance
8586
'''
8687
# At the moment, it's just a copy
8788
copytree(template, instance_home)
8889

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

0 commit comments

Comments
 (0)