chiark
/
gitweb
/
~mdw
/
cfd
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f0c2c8a
)
mdwsetup.py: Use `with open(...) as f' instead of `try'/`finally'.
author
Mark Wooding
<mdw@distorted.org.uk>
Sat, 15 Jun 2013 21:02:50 +0000
(22:02 +0100)
committer
Mark Wooding
<mdw@distorted.org.uk>
Sat, 15 Jun 2013 21:02:50 +0000
(22:02 +0100)
mdwsetup.py
patch
|
blob
|
blame
|
history
diff --git
a/mdwsetup.py
b/mdwsetup.py
index b423c2a799d6270bfd39d12616f4fbef495b748d..7b864c8a7aeabae1abf60c093d8f02df01da7888 100644
(file)
--- a/
mdwsetup.py
+++ b/
mdwsetup.py
@@
-23,6
+23,8
@@
### along with `common'; if not, write to the Free Software Foundation,
### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
### 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
import sys as SYS
import os as OS
import re as RE
@@
-143,16
+145,10
@@
def derive(target, source, substmap):
return False
print "making `%s' from `%s'" % (target, source)
temp = target + '.new'
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))
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):
OS.rename(temp, target)
def generate(target, source = None):
@@
-167,11
+163,8
@@
def generate(target, source = None):
return
print "making `%s' using `%s'" % (target, source)
temp = target + '.new'
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)
rc = SUB.call([SYS.executable, source], stdout = ft)
- finally:
- ft.close()
if rc != 0:
raise SubprocessFailure, (source, rc)
OS.rename(temp, target)
if rc != 0:
raise SubprocessFailure, (source, rc)
OS.rename(temp, target)
@@
-188,11
+181,7
@@
def auto_version(writep = True):
"""
version = progoutput(['./auto-version'])
if writep:
"""
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
OS.rename('RELEASE.new', 'RELEASE')
return version