summaryrefslogtreecommitdiffstats
path: root/meta/classes/metadata_scm.bbclass
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-09 17:05:58 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-09 22:28:04 +0100
commit566628d8cd674a964d5824391cfd1585a1a22a87 (patch)
tree670366ee1492ff8bb18b9261dfab9d06c06b0a2d /meta/classes/metadata_scm.bbclass
parentd2ef952851d9ef16875fdbbbc6ae6eb6cfc10cc0 (diff)
downloadpoky-566628d8cd674a964d5824391cfd1585a1a22a87.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 (From OE-Core rev: a43e0a8ecd0441131e929daf998c3cd454d9c8f3) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/metadata_scm.bbclass')
-rw-r--r--meta/classes/metadata_scm.bbclass21
1 files changed, 12 insertions, 9 deletions
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):
32def base_get_metadata_monotone_branch(path, d): 32def base_get_metadata_monotone_branch(path, d):
33 monotone_branch = "<unknown>" 33 monotone_branch = "<unknown>"
34 try: 34 try:
35 monotone_branch = file( "%s/_MTN/options" % path ).read().strip() 35 with open("%s/_MTN/options" % path) as f:
36 if monotone_branch.startswith( "database" ): 36 monotone_branch = f.read().strip()
37 monotone_branch_words = monotone_branch.split() 37 if monotone_branch.startswith( "database" ):
38 monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1] 38 monotone_branch_words = monotone_branch.split()
39 monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1]
39 except: 40 except:
40 pass 41 pass
41 return monotone_branch 42 return monotone_branch
@@ -43,10 +44,11 @@ def base_get_metadata_monotone_branch(path, d):
43def base_get_metadata_monotone_revision(path, d): 44def base_get_metadata_monotone_revision(path, d):
44 monotone_revision = "<unknown>" 45 monotone_revision = "<unknown>"
45 try: 46 try:
46 monotone_revision = file( "%s/_MTN/revision" % path ).read().strip() 47 with open("%s/_MTN/revision" % path) as f:
47 if monotone_revision.startswith( "format_version" ): 48 monotone_revision = f.read().strip()
48 monotone_revision_words = monotone_revision.split() 49 if monotone_revision.startswith( "format_version" ):
49 monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1] 50 monotone_revision_words = monotone_revision.split()
51 monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1]
50 except IOError: 52 except IOError:
51 pass 53 pass
52 return monotone_revision 54 return monotone_revision
@@ -54,7 +56,8 @@ def base_get_metadata_monotone_revision(path, d):
54def base_get_metadata_svn_revision(path, d): 56def base_get_metadata_svn_revision(path, d):
55 revision = "<unknown>" 57 revision = "<unknown>"
56 try: 58 try:
57 revision = file( "%s/.svn/entries" % path ).readlines()[3].strip() 59 with open("%s/.svn/entries" % path) as f:
60 revision = f.readlines()[3].strip()
58 except IOError: 61 except IOError:
59 pass 62 pass
60 return revision 63 return revision