Skip to content

Commit

Permalink
Merge pull request #39 from helium/Windows-fix
Browse files Browse the repository at this point in the history
Windows delete file fix and proper amount of slash escaping
  • Loading branch information
bradjc authored Nov 12, 2018
2 parents a06e7e5 + cefa45a commit ab71202
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 11 additions & 2 deletions tockloader/openocd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion tockloader/tockloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import binascii
import contextlib
import copy
import os
import platform
import string
import textwrap
import time
Expand All @@ -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:
'''
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ab71202

Please sign in to comment.