Skip to content

Commit 39544cd

Browse files
committed
init.loadTemplateInfo: Cleanup code
1 parent 3a461c2 commit 39544cd

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

roundup/init.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,33 +120,30 @@ def listTemplates(dir):
120120
ret[ti['name']] = ti
121121
return ret
122122

123-
def loadTemplateInfo(dir):
123+
def loadTemplateInfo(path):
124124
''' Attempt to load a Roundup template from the indicated directory.
125125
126126
Return None if there's no template, otherwise a template info
127127
dictionary.
128128
'''
129-
ti = os.path.join(dir, 'TEMPLATE-INFO.txt')
130-
if not os.path.exists(ti):
129+
tif = os.path.join(path, 'TEMPLATE-INFO.txt')
130+
if not os.path.exists(tif):
131131
return None
132132

133-
if os.path.exists(os.path.join(dir, 'config.py')):
133+
if os.path.exists(os.path.join(path, 'config.py')):
134134
print _("WARNING: directory '%s'\n"
135135
"\tcontains old-style template - ignored"
136-
) % os.path.abspath(dir)
136+
) % os.path.abspath(path)
137137
return None
138138

139139
# load up the template's information
140-
f = open(ti)
141-
try:
142-
m = rfc822.Message(open(ti))
140+
with open(tif) as f:
141+
m = rfc822.Message(f)
143142
ti = {}
144143
ti['name'] = m['name']
145144
ti['description'] = m['description']
146145
ti['intended-for'] = m['intended-for']
147-
ti['path'] = dir
148-
finally:
149-
f.close()
146+
ti['path'] = path
150147
return ti
151148

152149
def writeHeader(name, value):

0 commit comments

Comments
 (0)