### along with `common'; if not, write to the Free Software Foundation,
### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+from __future__ import with_statement
+
import sys as SYS
import os as OS
import re as RE
return False
print "making `%s' from `%s'" % (target, source)
temp = target + '.new'
- ft = open(temp, 'w')
- try:
- fs = open(source, 'r')
- try:
+ with open(temp, 'w') as ft:
+ with open(source, 'r') as fs:
for line in fs:
ft.write(RX_SUBST.sub((lambda m: substmap[m.group(1)]), line))
- finally:
- fs.close()
- finally:
- ft.close()
OS.rename(temp, target)
def generate(target, source = None):
return
print "making `%s' using `%s'" % (target, source)
temp = target + '.new'
- ft = open(temp, 'w')
- try:
+ with open(temp, 'w') as ft:
rc = SUB.call([SYS.executable, source], stdout = ft)
- finally:
- ft.close()
if rc != 0:
raise SubprocessFailure, (source, rc)
OS.rename(temp, target)
"""
version = progoutput(['./auto-version'])
if writep:
- ft = open('RELEASE.new', 'w')
- try:
- ft.write('%s\n' % version)
- finally:
- ft.close()
+ with open('RELEASE.new', 'w') as ft: ft.write('%s\n' % version)
OS.rename('RELEASE.new', 'RELEASE')
return version