Mercurial > p > roundup > code
comparison roundup/init.py @ 1916:d157b9b56ebf
implemented munging of template name for installed trackers
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 13 Nov 2003 04:12:10 +0000 |
| parents | 1f8bbdff56b9 |
| children | fc52d57c6c3e |
comparison
equal
deleted
inserted
replaced
| 1915:20cfd25cffda | 1916:d157b9b56ebf |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 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.28 2003-11-13 04:12:10 richard Exp $ |
| 19 | 19 |
| 20 __doc__ = """ | 20 __doc__ = """ |
| 21 Init (create) a roundup instance. | 21 Init (create) a roundup instance. |
| 22 """ | 22 """ |
| 23 | 23 |
| 24 import os, sys, errno | 24 import os, sys, errno, rfc822 |
| 25 | 25 |
| 26 import roundup.instance, password | 26 import roundup.instance, password |
| 27 from roundup import install_util | 27 from roundup import install_util |
| 28 | 28 |
| 29 def copytree(src, dst, symlinks=0): | 29 def copytree(src, dst, symlinks=0): |
| 84 | 84 |
| 85 ''' | 85 ''' |
| 86 # At the moment, it's just a copy | 86 # At the moment, it's just a copy |
| 87 copytree(template, instance_home) | 87 copytree(template, instance_home) |
| 88 | 88 |
| 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 | |
| 89 def write_select_db(instance_home, backend): | 158 def write_select_db(instance_home, backend): |
| 90 ''' Write the file that selects the backend for the tracker | 159 ''' Write the file that selects the backend for the tracker |
| 91 ''' | 160 ''' |
| 92 # now select database | 161 # now select database |
| 93 db = '''# WARNING: DO NOT EDIT THIS FILE!!! | 162 db = '''# WARNING: DO NOT EDIT THIS FILE!!! |
