From 3ae44e762f24f478d895999e7c42a993d06eb584 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 78cd60235..3f9207d72 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 dba87159c..d2ff9affb 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)