comparison roundup/init.py @ 4817:785bd25371d3

init.loadTemplateInfo: Cleanup code
author anatoly techtonik <techtonik@gmail.com>
date Sat, 24 Aug 2013 22:14:44 +0300
parents 6e3e4f24c753
children edb171528a7d
comparison
equal deleted inserted replaced
4816:9b3e09a50d85 4817:785bd25371d3
118 ti = loadTemplateInfo(idir) 118 ti = loadTemplateInfo(idir)
119 if ti: 119 if ti:
120 ret[ti['name']] = ti 120 ret[ti['name']] = ti
121 return ret 121 return ret
122 122
123 def loadTemplateInfo(dir): 123 def loadTemplateInfo(path):
124 ''' Attempt to load a Roundup template from the indicated directory. 124 ''' Attempt to load a Roundup template from the indicated directory.
125 125
126 Return None if there's no template, otherwise a template info 126 Return None if there's no template, otherwise a template info
127 dictionary. 127 dictionary.
128 ''' 128 '''
129 ti = os.path.join(dir, 'TEMPLATE-INFO.txt') 129 tif = os.path.join(path, 'TEMPLATE-INFO.txt')
130 if not os.path.exists(ti): 130 if not os.path.exists(tif):
131 return None 131 return None
132 132
133 if os.path.exists(os.path.join(dir, 'config.py')): 133 if os.path.exists(os.path.join(path, 'config.py')):
134 print _("WARNING: directory '%s'\n" 134 print _("WARNING: directory '%s'\n"
135 "\tcontains old-style template - ignored" 135 "\tcontains old-style template - ignored"
136 ) % os.path.abspath(dir) 136 ) % os.path.abspath(path)
137 return None 137 return None
138 138
139 # load up the template's information 139 # load up the template's information
140 f = open(ti) 140 with open(tif) as f:
141 try: 141 m = rfc822.Message(f)
142 m = rfc822.Message(open(ti))
143 ti = {} 142 ti = {}
144 ti['name'] = m['name'] 143 ti['name'] = m['name']
145 ti['description'] = m['description'] 144 ti['description'] = m['description']
146 ti['intended-for'] = m['intended-for'] 145 ti['intended-for'] = m['intended-for']
147 ti['path'] = dir 146 ti['path'] = path
148 finally:
149 f.close()
150 return ti 147 return ti
151 148
152 def writeHeader(name, value): 149 def writeHeader(name, value):
153 ''' Write an rfc822-compatible header line, making it wrap reasonably 150 ''' Write an rfc822-compatible header line, making it wrap reasonably
154 ''' 151 '''

Roundup Issue Tracker: http://roundup-tracker.org/