diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2018-03-17 11:56:47 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2018-03-17 11:56:47 +0100 |
commit | 3b0de6bf54c7ec81d704e93b0d1cd44e1c92311a (patch) | |
tree | 92c03c0fde698b8b36c57fafcaaba515c2c57f3f | |
parent | 091329c6522a6f53b6d79449693e0e4796ddab9c (diff) | |
download | psutil-3b0de6bf54c7ec81d704e93b0d1cd44e1c92311a.tar.gz |
add a script to purge installation
-rw-r--r-- | MANIFEST.in | 1 | ||||
-rw-r--r-- | Makefile | 3 | ||||
-rwxr-xr-x | scripts/internal/purge.py | 42 |
3 files changed, 45 insertions, 1 deletions
diff --git a/MANIFEST.in b/MANIFEST.in index 7a92a4e5..87d9bebb 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -110,6 +110,7 @@ include scripts/internal/download_exes.py include scripts/internal/generate_manifest.py include scripts/internal/print_announce.py include scripts/internal/print_timeline.py +include scripts/internal/purge.py include scripts/internal/winmake.py include scripts/iotop.py include scripts/killall.py @@ -76,7 +76,8 @@ install: ## Install this package as current user in "edit" mode. rm -rf tmp uninstall: ## Uninstall this package via pip. - cd ..; $(PYTHON) -m pip uninstall -y -v psutil + cd ..; $(PYTHON) -m pip uninstall -y -v psutil || true + $(PYTHON) scripts/internal/purge.py install-pip: ## Install pip (no-op if already installed). $(PYTHON) -c \ diff --git a/scripts/internal/purge.py b/scripts/internal/purge.py new file mode 100755 index 00000000..d9301719 --- /dev/null +++ b/scripts/internal/purge.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +# Copyright (c) 2009 Giampaolo Rodola'. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +Purge psutil installation by removing psutil-related files and +directories found in site-packages directories. This is needed mainly +because sometimes "import psutil" imports a leftover installation +from site-packages directory instead of the main working directory. +""" + +import os +import shutil +import site + + +PKGNAME = "psutil" + + +def rmpath(path): + if os.path.isdir(path): + print("rmdir " + path) + shutil.rmtree(path) + else: + print("rm " + path) + os.remove(path) + + +def main(): + locations = [site.getusersitepackages()] + locations.extend(site.getsitepackages()) + for root in locations: + if os.path.isdir(root): + for name in os.listdir(root): + if PKGNAME in name: + abspath = os.path.join(root, name) + rmpath(abspath) + + +main() |