1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-02 01:19:52 +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:
Richard Purdie
2013-05-09 17:05:58 +01:00
parent d2ef952851
commit 566628d8cd
12 changed files with 79 additions and 74 deletions
+30 -33
View File
@@ -561,14 +561,14 @@ def check_sanity(sanity_data):
last_sstate_dir = ""
sanityverfile = 'conf/sanity_info'
if os.path.exists(sanityverfile):
f = open(sanityverfile, 'r')
for line in f:
if line.startswith('SANITY_VERSION'):
last_sanity_version = int(line.split()[1])
if line.startswith('TMPDIR'):
last_tmpdir = line.split()[1]
if line.startswith('SSTATE_DIR'):
last_sstate_dir = line.split()[1]
with open(sanityverfile, 'r') as f:
for line in f:
if line.startswith('SANITY_VERSION'):
last_sanity_version = int(line.split()[1])
if line.startswith('TMPDIR'):
last_tmpdir = line.split()[1]
if line.startswith('SSTATE_DIR'):
last_sstate_dir = line.split()[1]
sanity_version = int(sanity_data.getVar('SANITY_VERSION', True) or 1)
network_error = False
@@ -584,25 +584,24 @@ def check_sanity(sanity_data):
if last_sstate_dir != sstate_dir:
messages = messages + check_sanity_sstate_dir_change(sstate_dir, sanity_data)
if os.path.exists("conf") and not messages:
f = open(sanityverfile, 'w')
f.write("SANITY_VERSION %s\n" % sanity_version)
f.write("TMPDIR %s\n" % tmpdir)
f.write("SSTATE_DIR %s\n" % sstate_dir)
with open(sanityverfile, 'w') as f:
f.write("SANITY_VERSION %s\n" % sanity_version)
f.write("TMPDIR %s\n" % tmpdir)
f.write("SSTATE_DIR %s\n" % sstate_dir)
#
# Check that TMPDIR hasn't changed location since the last time we were run
#
checkfile = os.path.join(tmpdir, "saved_tmpdir")
if os.path.exists(checkfile):
f = open(checkfile, "r")
saved_tmpdir = f.read().strip()
if (saved_tmpdir != tmpdir):
messages = messages + "Error, TMPDIR has changed location. You need to either move it back to %s or rebuild\n" % saved_tmpdir
with open(checkfile, "r") as f:
saved_tmpdir = f.read().strip()
if (saved_tmpdir != tmpdir):
messages = messages + "Error, TMPDIR has changed location. You need to either move it back to %s or rebuild\n" % saved_tmpdir
else:
bb.utils.mkdirhier(tmpdir)
f = open(checkfile, "w")
f.write(tmpdir)
f.close()
with open(checkfile, "w") as f:
f.write(tmpdir)
#
# Check the 'ABI' of TMPDIR
@@ -610,33 +609,32 @@ def check_sanity(sanity_data):
current_abi = sanity_data.getVar('OELAYOUT_ABI', True)
abifile = sanity_data.getVar('SANITY_ABIFILE', True)
if os.path.exists(abifile):
f = open(abifile, "r")
abi = f.read().strip()
with open(abifile, "r") as f:
abi = f.read().strip()
if not abi.isdigit():
f = open(abifile, "w")
f.write(current_abi)
with open(abifile, "w") as f:
f.write(current_abi)
elif abi == "2" and current_abi == "3":
bb.note("Converting staging from layout version 2 to layout version 3")
subprocess.call(sanity_data.expand("mv ${TMPDIR}/staging ${TMPDIR}/sysroots"), shell=True)
subprocess.call(sanity_data.expand("ln -s sysroots ${TMPDIR}/staging"), shell=True)
subprocess.call(sanity_data.expand("cd ${TMPDIR}/stamps; for i in */*do_populate_staging; do new=`echo $i | sed -e 's/do_populate_staging/do_populate_sysroot/'`; mv $i $new; done"), shell=True)
f = open(abifile, "w")
f.write(current_abi)
with open(abifile, "w") as f:
f.write(current_abi)
elif abi == "3" and current_abi == "4":
bb.note("Converting staging layout from version 3 to layout version 4")
if os.path.exists(sanity_data.expand("${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS}")):
subprocess.call(sanity_data.expand("mv ${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS} ${STAGING_BINDIR_CROSS}"), shell=True)
subprocess.call(sanity_data.expand("ln -s ${STAGING_BINDIR_CROSS} ${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS}"), shell=True)
f = open(abifile, "w")
f.write(current_abi)
with open(abifile, "w") as f:
f.write(current_abi)
elif abi == "4":
messages = messages + "Staging layout has changed. The cross directory has been deprecated and cross packages are now built under the native sysroot.\nThis requires a rebuild.\n"
elif abi == "5" and current_abi == "6":
bb.note("Converting staging layout from version 5 to layout version 6")
subprocess.call(sanity_data.expand("mv ${TMPDIR}/pstagelogs ${SSTATE_MANIFESTS}"), shell=True)
f = open(abifile, "w")
f.write(current_abi)
with open(abifile, "w") as f:
f.write(current_abi)
elif abi == "7" and current_abi == "8":
messages = messages + "Your configuration is using stamp files including the sstate hash but your build directory was built with stamp files that do not include this.\nTo continue, either rebuild or switch back to the OEBasic signature handler with BB_SIGNATURE_HANDLER = 'OEBasic'.\n"
elif (abi != current_abi and current_abi == "9"):
@@ -645,9 +643,8 @@ def check_sanity(sanity_data):
# Code to convert from one ABI to another could go here if possible.
messages = messages + "Error, TMPDIR has changed its layout version number (%s to %s) and you need to either rebuild, revert or adjust it at your own risk.\n" % (abi, current_abi)
else:
f = open(abifile, "w")
f.write(current_abi)
f.close()
with open(abifile, "w") as f:
f.write(current_abi)
oeroot = sanity_data.getVar('COREBASE')
if oeroot.find ('+') != -1: