diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-05-09 17:05:58 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-05-09 22:25:31 +0100 |
commit | a43e0a8ecd0441131e929daf998c3cd454d9c8f3 (patch) | |
tree | 69be538a129e3f9e985aa65d07005bf067371aa5 /meta/classes/metadata_scm.bbclass | |
parent | 4808629faa1222b31f92a3e410e06adb8e081293 (diff) | |
download | openembedded-core-contrib-a43e0a8ecd0441131e929daf998c3cd454d9c8f3.tar.gz |
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 <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/metadata_scm.bbclass')
-rw-r--r-- | meta/classes/metadata_scm.bbclass | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/meta/classes/metadata_scm.bbclass b/meta/classes/metadata_scm.bbclass index e9b207c24f0..8d3988ace8e 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 = "<unknown>" 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 = "<unknown>" 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 = "<unknown>" 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 |