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 /scripts | |
parent | 091329c6522a6f53b6d79449693e0e4796ddab9c (diff) | |
download | psutil-3b0de6bf54c7ec81d704e93b0d1cd44e1c92311a.tar.gz |
add a script to purge installation
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/internal/purge.py | 42 |
1 files changed, 42 insertions, 0 deletions
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() |