From ffea9a17d775005539692b1516eb4178d6c5234a Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Fri, 26 Jun 2015 20:48:43 +0200 Subject: [PATCH 1/1] build:wafsamba: Close file handles in the build scripts too Signed-off-by: Thomas Nagy Reviewed-by: Michael Adam Reviewed-by: Andrew Bartlett --- buildtools/wafsamba/configure_file.py | 10 ++-------- buildtools/wafsamba/pkgconfig.py | 10 ++-------- buildtools/wafsamba/samba_abi.py | 4 +--- buildtools/wafsamba/samba_conftests.py | 25 ++++++------------------- buildtools/wafsamba/samba_patterns.py | 5 +---- buildtools/wafsamba/samba_version.py | 5 +---- buildtools/wafsamba/wafsamba.py | 4 +--- docs-xml/wscript_build | 4 +--- 8 files changed, 15 insertions(+), 52 deletions(-) diff --git a/buildtools/wafsamba/configure_file.py b/buildtools/wafsamba/configure_file.py index 8e2ba3bc23f..21264cfca5c 100644 --- a/buildtools/wafsamba/configure_file.py +++ b/buildtools/wafsamba/configure_file.py @@ -7,12 +7,8 @@ def subst_at_vars(task): '''substiture @VAR@ style variables in a file''' env = task.env - src = task.inputs[0].srcpath(env) - tgt = task.outputs[0].bldpath(env) + s = task.inputs[0].read() - f = open(src, 'r') - s = f.read() - f.close() # split on the vars a = re.split('(@\w+@)', s) out = [] @@ -27,9 +23,7 @@ def subst_at_vars(task): v = SUBST_VARS_RECURSIVE(task.env[vname], task.env) out.append(v) contents = ''.join(out) - f = open(tgt, 'w') - s = f.write(contents) - f.close() + task.outputs[0].write(contents) return 0 def CONFIGURE_FILE(bld, in_file, **kwargs): diff --git a/buildtools/wafsamba/pkgconfig.py b/buildtools/wafsamba/pkgconfig.py index 8a3f807dc55..c837804ee8e 100644 --- a/buildtools/wafsamba/pkgconfig.py +++ b/buildtools/wafsamba/pkgconfig.py @@ -5,12 +5,8 @@ from samba_utils import * def subst_at_vars(task): '''substiture @VAR@ style variables in a file''' - src = task.inputs[0].srcpath(task.env) - tgt = task.outputs[0].bldpath(task.env) - f = open(src, 'r') - s = f.read() - f.close() + s = task.inputs[0].read() # split on the vars a = re.split('(@\w+@)', s) out = [] @@ -37,9 +33,7 @@ def subst_at_vars(task): break out.append(v) contents = ''.join(out) - f = open(tgt, 'w') - s = f.write(contents) - f.close() + task.outputs[0].write(contents) return 0 diff --git a/buildtools/wafsamba/samba_abi.py b/buildtools/wafsamba/samba_abi.py index 76acd006777..3ff6d77811c 100644 --- a/buildtools/wafsamba/samba_abi.py +++ b/buildtools/wafsamba/samba_abi.py @@ -147,12 +147,10 @@ def abi_check(self): def abi_process_file(fname, version, symmap): '''process one ABI file, adding new symbols to the symmap''' - f = open(fname, mode='r') - for line in f: + for line in Utils.readf(fname).splitlines(): symname = line.split(":")[0] if not symname in symmap: symmap[symname] = version - f.close() def abi_write_vscript(f, libname, current_version, versions, symmap, abi_match): diff --git a/buildtools/wafsamba/samba_conftests.py b/buildtools/wafsamba/samba_conftests.py index 96fead58128..fe8c30bef01 100644 --- a/buildtools/wafsamba/samba_conftests.py +++ b/buildtools/wafsamba/samba_conftests.py @@ -216,9 +216,7 @@ def CHECK_NEED_LC(conf, msg): os.makedirs(subdir) - dest = open(os.path.join(subdir, 'liblc1.c'), 'w') - dest.write('#include \nint lib_func(void) { FILE *f = fopen("foo", "r");}\n') - dest.close() + Utils.writef(os.path.join(subdir, 'liblc1.c'), '#include \nint lib_func(void) { FILE *f = fopen("foo", "r");}\n') bld = Build.BuildContext() bld.log = conf.log @@ -291,13 +289,8 @@ def CHECK_LIBRARY_SUPPORT(conf, rpath=False, version_script=False, msg=None): os.makedirs(subdir) - dest = open(os.path.join(subdir, 'lib1.c'), 'w') - dest.write('int lib_func(void) { return 42; }\n') - dest.close() - - dest = open(os.path.join(dir, 'main.c'), 'w') - dest.write('int main(void) {return !(lib_func() == 42);}\n') - dest.close() + Utils.writef(os.path.join(subdir, 'lib1.c'), 'int lib_func(void) { return 42; }\n') + Utils.writef(os.path.join(dir, 'main.c'), 'int main(void) {return !(lib_func() == 42);}\n') bld = Build.BuildContext() bld.log = conf.log @@ -311,9 +304,7 @@ def CHECK_LIBRARY_SUPPORT(conf, rpath=False, version_script=False, msg=None): ldflags = [] if version_script: ldflags.append("-Wl,--version-script=%s/vscript" % bld.path.abspath()) - dest = open(os.path.join(dir,'vscript'), 'w') - dest.write('TEST_1.0A2 { global: *; };\n') - dest.close() + Utils.writef(os.path.join(dir,'vscript'), 'TEST_1.0A2 { global: *; };\n') bld(features='cc cshlib', source='libdir/lib1.c', @@ -383,15 +374,13 @@ def CHECK_PERL_MANPAGE(conf, msg=None, section=None): if not os.path.exists(bdir): os.makedirs(bdir) - dest = open(os.path.join(bdir, 'Makefile.PL'), 'w') - dest.write(""" + Utils.writef(os.path.join(bdir, 'Makefile.PL'), """ use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'WafTest', 'EXE_FILES' => [ 'WafTest' ] ); """) - dest.close() back = os.path.abspath('.') os.chdir(bdir) proc = Utils.pproc.Popen(['perl', 'Makefile.PL'], @@ -406,9 +395,7 @@ WriteMakefile( return if section: - f = open(os.path.join(bdir,'Makefile'), 'r') - man = f.read() - f.close() + man = Utils.readf(os.path.join(bdir,'Makefile')) m = re.search('MAN%sEXT\s+=\s+(\w+)' % section, man) if not m: conf.check_message_2('not found', color='YELLOW') diff --git a/buildtools/wafsamba/samba_patterns.py b/buildtools/wafsamba/samba_patterns.py index 04699927624..5183e865745 100644 --- a/buildtools/wafsamba/samba_patterns.py +++ b/buildtools/wafsamba/samba_patterns.py @@ -8,14 +8,11 @@ from wafsamba import samba_version_file def write_version_header(task): '''print version.h contents''' src = task.inputs[0].srcpath(task.env) - tgt = task.outputs[0].bldpath(task.env) version = samba_version_file(src, task.env.srcdir, env=task.env, is_install=task.env.is_install) string = str(version) - f = open(tgt, 'w') - s = f.write(string) - f.close() + task.outputs[0].write(string) return 0 diff --git a/buildtools/wafsamba/samba_version.py b/buildtools/wafsamba/samba_version.py index bb0be96f869..950a855c1ef 100644 --- a/buildtools/wafsamba/samba_version.py +++ b/buildtools/wafsamba/samba_version.py @@ -42,12 +42,10 @@ def git_version_summary(path, env=None): def distversion_version_summary(path): #get version from .distversion file - f = open(path + '/.distversion', 'r') suffix = None fields = {} - for line in f: - line = line.strip() + for line in Utils.readf(path + '/.distversion').splitlines(): if line == '': continue if line.startswith("#"): @@ -64,7 +62,6 @@ def distversion_version_summary(path): except: print("Failed to parse line %s from .distversion file." % (line)) raise - f.close() if "COMMIT_TIME" in fields: fields["COMMIT_TIME"] = int(fields["COMMIT_TIME"]) diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py index c27241eff8d..078e411db25 100644 --- a/buildtools/wafsamba/wafsamba.py +++ b/buildtools/wafsamba/wafsamba.py @@ -95,9 +95,7 @@ Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION def generate_empty_file(task): - target_fname = installed_location=task.outputs[0].bldpath(task.env) - target_file = open(installed_location, 'w') - target_file.close() + task.outputs[0].write('') return 0 ################################################################# diff --git a/docs-xml/wscript_build b/docs-xml/wscript_build index 515746075ac..568eba1d66d 100644 --- a/docs-xml/wscript_build +++ b/docs-xml/wscript_build @@ -111,9 +111,7 @@ def smbdotconf_generate_parameter_list(task): t += "]>\n" t += "
\n" for article in articles: - f = open(article.abspath(task.env), 'r') - t += f.read() - f.close() + t += article.read() t += "
\n" save_file(parameter_all, t , create_dir=True) -- 2.34.1