From: Gui Chen Date: Thu, 15 Aug 2013 08:02:23 +0000 (-0400) Subject: setup_qemu_emulator: replace open/close with with_statement X-Git-Tag: 0.21~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8760d7edc9da346c8c8a14facc04d65dcf7e6c9e;p=tools%2Fmic.git setup_qemu_emulator: replace open/close with with_statement to avoid unexpected IOError caused by open/close Signed-off-by: Gui Chen --- diff --git a/mic/utils/misc.py b/mic/utils/misc.py index 6302434..8930939 100644 --- a/mic/utils/misc.py +++ b/mic/utils/misc.py @@ -15,6 +15,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # Temple Place - Suite 330, Boston, MA 02111-1307, USA. +from __future__ import with_statement import os import sys import time @@ -988,16 +989,14 @@ def setup_qemu_emulator(rootdir, arch): node = "/proc/sys/fs/binfmt_misc/arm" if os.path.exists(node): qemu_unregister_string = "-1\n" - fd = open("/proc/sys/fs/binfmt_misc/arm", "w") - fd.write(qemu_unregister_string) - fd.close() + with open("/proc/sys/fs/binfmt_misc/arm", "w") as fd: + fd.write(qemu_unregister_string) # register qemu emulator for interpreting other arch executable file if not os.path.exists(node): qemu_arm_string = ":arm:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfa\\xff\\xff\\xff:%s:\n" % qemu_emulator - fd = open("/proc/sys/fs/binfmt_misc/register", "w") - fd.write(qemu_arm_string) - fd.close() + with open("/proc/sys/fs/binfmt_misc/register", "w") as fd: + fd.write(qemu_arm_string) return qemu_emulator