From 7bdf373b95de58f3b7e9857449d81652b7ed36f2 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Mon, 16 May 2016 21:30:16 +0200 Subject: [PATCH] flash: close files (c.f. #256) --- artiq/frontend/artiq_flash.py | 3 ++- artiq/frontend/bit2bin.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/artiq/frontend/artiq_flash.py b/artiq/frontend/artiq_flash.py index 8c0090187..b43ee473b 100755 --- a/artiq/frontend/artiq_flash.py +++ b/artiq/frontend/artiq_flash.py @@ -97,7 +97,8 @@ def main(): elif action == "gateware": bin = os.path.join(opts.dir, "top.bin") if not os.access(bin, os.R_OK): - bin = tempfile.mkstemp()[1] + bin_handle, bin = tempfile.mkstemp() + bin_handle.close() bit = os.path.join(opts.dir, "top.bit") conv = True prog.append("jtagspi_program {} 0x{:x}".format( diff --git a/artiq/frontend/bit2bin.py b/artiq/frontend/bit2bin.py index a537fc209..ded87a0b3 100755 --- a/artiq/frontend/bit2bin.py +++ b/artiq/frontend/bit2bin.py @@ -60,7 +60,8 @@ def bit2bin(bit, bin, flip=False): d = bitfile.read(l) if flip: d = flip32(d) - open(bin, "wb").write(d) + with open(bin, "wb") as f: + f.write(d) else: d = bitfile.read(*struct.unpack(">H", bitfile.read(2))) print("Unexpected key: ", key, d)