diff --git a/tockloader/openocd.py b/tockloader/openocd.py index 0da3251..1ed50b3 100644 --- a/tockloader/openocd.py +++ b/tockloader/openocd.py @@ -16,7 +16,11 @@ from .board_interface import BoardInterface from .exceptions import TockLoaderException +# global static variable for collecting temp files for Windows +collect_temp_files = [] + class OpenOCD(BoardInterface): + def _run_openocd_commands (self, commands, binary, write=True): ''' - `commands`: String of openocd commands. Use {binary} for where the name @@ -25,7 +29,9 @@ def _run_openocd_commands (self, commands, binary, write=True): - `write`: Set to true if the command writes binaries to the board. Set to false if the command will read bits from the board. ''' - delete = True + + # in Windows, you can't mark delete bc they delete too fast + delete = platform.system() != 'Windows' if self.args.debug: delete = False @@ -38,7 +44,10 @@ def _run_openocd_commands (self, commands, binary, write=True): if platform.system() == 'Windows': # For Windows, forward slashes need to be escaped - temp_bin = temp_bin.name.replace('\\', '\\\\') + temp_bin.name = temp_bin.name.replace('\\', '\\\\\\') + # For Windows, files need to be manually deleted + global collect_temp_files + collect_temp_files += [temp_bin.name] # Update the command with the name of the binary file commands = commands.format(binary=temp_bin.name) diff --git a/tockloader/tockloader.py b/tockloader/tockloader.py index 4aa74af..4840d9f 100644 --- a/tockloader/tockloader.py +++ b/tockloader/tockloader.py @@ -8,6 +8,8 @@ import binascii import contextlib import copy +import os +import platform import string import textwrap import time @@ -18,7 +20,7 @@ from .exceptions import TockLoaderException from .tbfh import TBFHeader from .jlinkexe import JLinkExe -from .openocd import OpenOCD +from .openocd import OpenOCD, collect_temp_files class TockLoader: ''' @@ -469,6 +471,11 @@ def _start_communication_with_board (self): yield + if platform.system() == 'Windows': + for file in collect_temp_files: + os.remove(file) + + now = time.time() print('Finished in {:0.3f} seconds'.format(now-then)) except Exception as e: