From a43e0a8ecd0441131e929daf998c3cd454d9c8f3 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Thu, 9 May 2013 17:05:58 +0100 Subject: class/lib: Fix up various file access methods There are various bits of cruft that have built up around our file accesses. This patch cleans some of them up, specifically: * Remove pointless "from __builtin__ import file" * Use open(), not file() * Wrap file usage in a with container to ensure files are closed * Add missing .close() calls in some cases Signed-off-by: Richard Purdie --- meta/classes/package.bbclass | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'meta/classes/package.bbclass') diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass index 7d0684c95c..36b3ae5109 100644 --- a/meta/classes/package.bbclass +++ b/meta/classes/package.bbclass @@ -1096,7 +1096,8 @@ python emit_pkgdata() { def get_directory_size(dir): if os.listdir(dir): - size = int(os.popen('du -sk %s' % dir).readlines()[0].split('\t')[0]) + with os.popen('du -sk %s' % dir) as f: + size = int(f.readlines()[0].split('\t')[0]) else: size = 0 return size @@ -1203,7 +1204,7 @@ python emit_pkgdata() { g = glob('*') if g or allow_empty == "1": packagedfile = pkgdatadir + '/runtime/%s.packaged' % pkg - file(packagedfile, 'w').close() + open(packagedfile, 'w').close() if bb.data.inherits_class('kernel', d) or bb.data.inherits_class('module-base', d): write_extra_runtime_pkgs(variants, packages, pkgdatadir) @@ -1633,7 +1634,7 @@ def read_libdep_files(d): for extension in ".shlibdeps", ".pcdeps", ".clilibdeps": depsfile = d.expand("${PKGDEST}/" + pkg + extension) if os.access(depsfile, os.R_OK): - fd = file(depsfile) + fd = open(depsfile) lines = fd.readlines() fd.close() for l in lines: -- cgit v1.2.3