diff options
| author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-10-27 20:57:12 +0200 |
|---|---|---|
| committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-10-27 20:57:12 +0200 |
| commit | ed64f4a26387b12ea893157ff8f31d28d8bc71da (patch) | |
| tree | 2c1596b422cec83c18797c0f6b953d6886db11ab /scripts | |
| parent | 7f51f0074b6d727a01fea0290ed0988dd51ad288 (diff) | |
| parent | 614d45928a3ac583433d2d56e0bcd0f946658607 (diff) | |
| download | psutil-ed64f4a26387b12ea893157ff8f31d28d8bc71da.tar.gz | |
Merge branch 'master' into oneshot
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/internal/winmake.py | 78 |
1 files changed, 60 insertions, 18 deletions
diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py index 7671b735..51cc1a6f 100755 --- a/scripts/internal/winmake.py +++ b/scripts/internal/winmake.py @@ -110,6 +110,44 @@ def rm(pattern, directory=False): safe_remove(path) +def safe_remove(path): + try: + os.remove(path) + except OSError as err: + if err.errno != errno.ENOENT: + raise + else: + print("rm %s" % path) + + +def safe_rmtree(path): + def onerror(fun, path, excinfo): + exc = excinfo[1] + if exc.errno != errno.ENOENT: + raise + + existed = os.path.isdir(path) + shutil.rmtree(path, onerror=onerror) + if existed: + print("rmdir -f %s" % path) + + +def recursive_rm(*patterns): + """Recursively remove a file or dir by pattern.""" + for root, subdirs, subfiles in os.walk('.'): + root = os.path.normpath(root) + if root.startswith('.git/'): + continue + for file in subfiles: + for pattern in patterns: + if fnmatch.fnmatch(file, pattern): + safe_remove(os.path.join(root, file)) + for dir in subdirs: + for pattern in patterns: + if fnmatch.fnmatch(dir, pattern): + safe_rmtree(os.path.join(root, dir)) + + # =================================================================== # commands # =================================================================== @@ -201,24 +239,28 @@ def uninstall(): @cmd def clean(): """Deletes dev files""" - rm("*.egg-info", directory=True) - rm("*__pycache__", directory=True) - rm("build", directory=True) - rm("dist", directory=True) - rm("htmlcov", directory=True) - rm("tmp", directory=True) - - rm("*.bak") - rm("*.core") - rm("*.orig") - rm("*.pyc") - rm("*.pyd") - rm("*.pyo") - rm("*.rej") - rm("*.so") - rm("*.~") - rm(".coverage") - rm(".tox") + recursive_rm( + "$testfn*", + "*.bak", + "*.core", + "*.egg-info", + "*.orig", + "*.pyc", + "*.pyd", + "*.pyo", + "*.rej", + "*.so", + "*.~", + "*__pycache__", + ".coverage", + ".tox", + ) + safe_rmtree("build") + safe_rmtree(".coverage") + safe_rmtree("dist") + safe_rmtree("docs/_build") + safe_rmtree("htmlcov") + safe_rmtree("tmp") @cmd |
