X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/a6bb85c11b83e759dd74a58a1003fb16ab151d70..2f8140f93e6672705e378e4588b21657f3098034:/mdwsetup.py diff --git a/mdwsetup.py b/mdwsetup.py index 9ce67e6..7b864c8 100644 --- a/mdwsetup.py +++ b/mdwsetup.py @@ -7,22 +7,24 @@ ###----- Licensing notice --------------------------------------------------- ### -### This file is part of the Python interface to mLib. +### This file is part of the Common Files Distribution (`common') ### -### mLib/Python is free software; you can redistribute it and/or modify +### `Common' is free software; you can redistribute it and/or modify ### it under the terms of the GNU General Public License as published by ### the Free Software Foundation; either version 2 of the License, or ### (at your option) any later version. ### -### mLib/Python is distributed in the hope that it will be useful, +### `Common' is distributed in the hope that it will be useful, ### but WITHOUT ANY WARRANTY; without even the implied warranty of ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ### GNU General Public License for more details. ### ### You should have received a copy of the GNU General Public License -### along with mLib/Python; if not, write to the Free Software Foundation, +### 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 @@ -143,16 +145,10 @@ def derive(target, source, substmap): 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): @@ -167,11 +163,8 @@ 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) @@ -188,11 +181,7 @@ def auto_version(writep = True): """ 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