|
15 | 15 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
16 | 16 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
17 | 17 | # |
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 $ |
19 | 19 |
|
20 | | -__doc__ = """ |
21 | | -Init (create) a roundup instance. |
| 20 | +"""Init (create) a roundup instance. |
22 | 21 | """ |
| 22 | +__docformat__ = 'restructuredtext' |
23 | 23 |
|
24 | | -import os, sys, errno |
| 24 | +import os, sys, errno, rfc822 |
25 | 25 |
|
26 | 26 | import roundup.instance, password |
27 | 27 | from roundup import install_util |
@@ -57,35 +57,105 @@ def copytree(src, dst, symlinks=0): |
57 | 57 | def install(instance_home, template): |
58 | 58 | '''Install an instance using the named template and backend. |
59 | 59 |
|
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 |
63 | 64 |
|
64 | 65 | The instance_home directory will be created using the files found in |
65 | 66 | the named template (roundup.templates.<name>). A standard instance_home |
66 | 67 | 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 |
84 | 68 |
|
| 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 |
85 | 86 | ''' |
86 | 87 | # At the moment, it's just a copy |
87 | 88 | copytree(template, instance_home) |
88 | 89 |
|
| 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 | + |
89 | 159 | def write_select_db(instance_home, backend): |
90 | 160 | ''' Write the file that selects the backend for the tracker |
91 | 161 | ''' |
|
0 commit comments