Skip to content

Commit

Permalink
Merge pull request #632 from OP2/connorjward/fix-pyop2clean
Browse files Browse the repository at this point in the history
Fix pyop2-clean
  • Loading branch information
dham authored Jul 27, 2021
2 parents ec55e8e + 6e00f49 commit 117e4b7
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions pyop2/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@


import os
import shutil
import subprocess
import sys
import ctypes
Expand Down Expand Up @@ -500,31 +501,27 @@ def clear_cache(prompt=False):
:arg prompt: if ``True`` prompt before removing any files
"""
cachedir = configuration['cache_dir']

if not os.path.exists(cachedir):
print("Cache directory could not be found")
return

files = [os.path.join(cachedir, f) for f in os.listdir(cachedir)
if os.path.isfile(os.path.join(cachedir, f))]
nfiles = len(files)

if nfiles == 0:
if len(os.listdir(cachedir)) == 0:
print("No cached libraries to remove")
return

remove = True
if prompt:

user = input("Remove %d cached libraries from %s? [Y/n]: " % (nfiles, cachedir))
user = input(f"Remove cached libraries from {cachedir}? [Y/n]: ")

while user.lower() not in ['', 'y', 'n']:
print("Please answer y or n.")
user = input("Remove %d cached libraries from %s? [Y/n]: " % (nfiles, cachedir))
user = input(f"Remove cached libraries from {cachedir}? [Y/n]: ")

if user.lower() == 'n':
remove = False

if remove:
print("Removing %d cached libraries from %s" % (nfiles, cachedir))
[os.remove(f) for f in files]
print(f"Removing cached libraries from {cachedir}")
shutil.rmtree(cachedir)
else:
print("Not removing cached libraries")

0 comments on commit 117e4b7

Please sign in to comment.