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/metadata_scm.bbclass | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'meta/classes/metadata_scm.bbclass') diff --git a/meta/classes/metadata_scm.bbclass b/meta/classes/metadata_scm.bbclass index e9b207c24f..8d3988ace8 100644 --- a/meta/classes/metadata_scm.bbclass +++ b/meta/classes/metadata_scm.bbclass @@ -32,10 +32,11 @@ def base_get_scmbasepath(d): def base_get_metadata_monotone_branch(path, d): monotone_branch = "" try: - monotone_branch = file( "%s/_MTN/options" % path ).read().strip() - if monotone_branch.startswith( "database" ): - monotone_branch_words = monotone_branch.split() - monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1] + with open("%s/_MTN/options" % path) as f: + monotone_branch = f.read().strip() + if monotone_branch.startswith( "database" ): + monotone_branch_words = monotone_branch.split() + monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1] except: pass return monotone_branch @@ -43,10 +44,11 @@ def base_get_metadata_monotone_branch(path, d): def base_get_metadata_monotone_revision(path, d): monotone_revision = "" try: - monotone_revision = file( "%s/_MTN/revision" % path ).read().strip() - if monotone_revision.startswith( "format_version" ): - monotone_revision_words = monotone_revision.split() - monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1] + with open("%s/_MTN/revision" % path) as f: + monotone_revision = f.read().strip() + if monotone_revision.startswith( "format_version" ): + monotone_revision_words = monotone_revision.split() + monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1] except IOError: pass return monotone_revision @@ -54,7 +56,8 @@ def base_get_metadata_monotone_revision(path, d): def base_get_metadata_svn_revision(path, d): revision = "" try: - revision = file( "%s/.svn/entries" % path ).readlines()[3].strip() + with open("%s/.svn/entries" % path) as f: + revision = f.readlines()[3].strip() except IOError: pass return revision -- cgit v1.2.3