diff --git a/src/ducktools/pythonfinder/__main__.py b/src/ducktools/pythonfinder/__main__.py index 2265cf0..2864543 100644 --- a/src/ducktools/pythonfinder/__main__.py +++ b/src/ducktools/pythonfinder/__main__.py @@ -28,6 +28,7 @@ from ducktools.lazyimporter import LazyImporter, ModuleImport, FromImport from ducktools.pythonfinder import list_python_installs, __version__ +from ducktools.pythonfinder.shared import purge_caches _laz = LazyImporter( [ @@ -122,6 +123,11 @@ def get_parser(): subparsers = parser.add_subparsers(dest="command", required=False) + clear_cache = subparsers.add_parser( + "clear-cache", + help="Clear the cache of Python install details" + ) + online = subparsers.add_parser( "online", help="Get links to binaries from python.org" @@ -305,7 +311,9 @@ def main(): parser = get_parser() vals = parser.parse_args(sys.argv[1:]) - if vals.command == "online": + if vals.command == "clear-cache": + purge_caches() + elif vals.command == "online": system = vals.system if vals.system else _laz.platform.system() machine = vals.machine if vals.machine else _laz.platform.machine() try: diff --git a/src/ducktools/pythonfinder/shared.py b/src/ducktools/pythonfinder/shared.py index 0fb031e..8405135 100644 --- a/src/ducktools/pythonfinder/shared.py +++ b/src/ducktools/pythonfinder/shared.py @@ -39,6 +39,7 @@ ModuleImport("json"), ModuleImport("platform"), ModuleImport("re"), + ModuleImport("shutil"), ModuleImport("subprocess"), ModuleImport("tempfile"), ModuleImport("zipfile"), @@ -84,6 +85,10 @@ INSTALLER_CACHE_PATH = os.path.join(CACHE_FOLDER, "installer_details.json") +def purge_caches(cache_folder=CACHE_FOLDER): + _laz.shutil.rmtree(cache_folder, ignore_errors=True) + + def version_str_to_tuple(version): parsed_version = _laz.re.fullmatch(FULL_PY_VER_RE, version)