mirror of
https://git.yoctoproject.org/poky
synced 2026-05-31 00:39:46 +00:00
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>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user