Purge temp at the start of every run if it exists.

This commit is contained in:
mrg 2020-12-02 11:09:40 -08:00
parent 0250d9add7
commit edf3d9557d
1 changed files with 29 additions and 22 deletions

View File

@ -354,6 +354,21 @@ def end_openram():
verify.print_pex_stats() verify.print_pex_stats()
def purge_temp():
""" Remove the temp directory. """
debug.info(1,
"Purging temp directory: {}".format(OPTS.openram_temp))
# This annoyingly means you have to re-cd into
# the directory each debug iteration
# shutil.rmtree(OPTS.openram_temp, ignore_errors=True)
contents = [os.path.join(OPTS.openram_temp, i) for i in os.listdir(OPTS.openram_temp)]
for i in contents:
if os.path.isfile(i) or os.path.islink(i):
os.remove(i)
else:
shutil.rmtree(i)
def cleanup_paths(): def cleanup_paths():
""" """
We should clean up the temp directory after execution. We should clean up the temp directory after execution.
@ -364,17 +379,7 @@ def cleanup_paths():
"Preserving temp directory: {}".format(OPTS.openram_temp)) "Preserving temp directory: {}".format(OPTS.openram_temp))
return return
elif os.path.exists(OPTS.openram_temp): elif os.path.exists(OPTS.openram_temp):
debug.info(1, purge_temp()
"Purging temp directory: {}".format(OPTS.openram_temp))
# This annoyingly means you have to re-cd into
# the directory each debug iteration
# shutil.rmtree(OPTS.openram_temp, ignore_errors=True)
contents = [os.path.join(OPTS.openram_temp, i) for i in os.listdir(OPTS.openram_temp)]
for i in contents:
if os.path.isfile(i) or os.path.islink(i):
os.remove(i)
else:
shutil.rmtree(i)
def setup_paths(): def setup_paths():
@ -427,15 +432,17 @@ def find_exe(check_exe):
def init_paths(): def init_paths():
""" Create the temp and output directory if it doesn't exist """ """ Create the temp and output directory if it doesn't exist """
if os.path.exists(OPTS.openram_temp):
# make the directory if it doesn't exist purge_temp()
try: else:
debug.info(1, # make the directory if it doesn't exist
"Creating temp directory: {}".format(OPTS.openram_temp)) try:
os.makedirs(OPTS.openram_temp, 0o750) debug.info(1,
except OSError as e: "Creating temp directory: {}".format(OPTS.openram_temp))
if e.errno == 17: # errno.EEXIST os.makedirs(OPTS.openram_temp, 0o750)
os.chmod(OPTS.openram_temp, 0o750) except OSError as e:
if e.errno == 17: # errno.EEXIST
os.chmod(OPTS.openram_temp, 0o750)
# Don't delete the output dir, it may have other files! # Don't delete the output dir, it may have other files!
# make the directory if it doesn't exist # make the directory if it doesn't exist