This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add a new shutil.cleartree function to shutil module
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: chin, eric.araujo, orsenthil, pitrou, r.david.murray
Priority: normal Keywords: patch

Created on 2011-07-30 17:52 by chin, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
shutil.cleartree.patch chin, 2011-07-30 17:52 shutil.cleartree.patch review
example.py chin, 2011-07-31 06:00 sample shutil.cleartree usage
Messages (8)
msg141450 - (view) Author: Leonid Vasilev (chin) Date: 2011-07-30 17:52
Hello,

This patch adds new function to shutil.
I think it's quite generic, and it fits shutil purpose.

Sample usage:
shutil.cleartree(path='/home/chin/Dev/python-hg-dev', ignore=shutil.ignore_pattterns('*.py'))

removes all files from path, except *.py files. 

and

shutil.cleartree(path='/home/chin/Dev/python-hg-dev', ignore=shutil.ignore_pattterns('*.pyc'), invert=True)

is equivalent to `find /home/chin/Dev/python-hg-dev -name "*.pyc" -delete`
msg141454 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-07-31 00:30
My immediate reaction is that this is too specialized.  We'll see what others think.
msg141455 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-07-31 01:36
Cleartree seems more equivalent to a shell expression, as you pointed out to find and -delete,than a utility. We might find those useful when work on CLI as opposed to programmatically needing them via APIs. (Won't you agree?) Chin, can you suggest certain use cases while writing programs that you would need to use cleartree api? While I like that function, I am  not sure if shutil should need that.
msg141458 - (view) Author: Leonid Vasilev (chin) Date: 2011-07-31 06:00
Added file with sample usage (extracted from real application).

the main purpose of shutil.cleartree()
is to remove unnecessary files from tree, where
patterns of ignored or deleted files are computed
dynamically.

Yes I agree, that it might be done by shell expression, but in case of dynamic patterns it will be hacky.
msg141667 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-08-05 16:28
It looks like this new function would just replace a loop using os.walk and fnmatch.  Is it really needed?
msg141700 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-08-06 01:37
I also think it sounds too specialized.
msg141731 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-08-07 00:20
Hello Leonid, I think the best way forward would be post it as a recipe in active state cookbook if you have not already and see the adoption. If there is enough, then it can be added to shutil module. AFAIK, a couple of shutil features have gained entry in this way.
msg141899 - (view) Author: Leonid Vasilev (chin) Date: 2011-08-11 10:45
yup, it's really to specific.
History
Date User Action Args
2022-04-11 14:57:20adminsetgithub: 56870
2011-08-11 10:45:12chinsetresolution: not a bug -> rejected
2011-08-11 10:45:04chinsetstatus: open -> closed
resolution: not a bug
messages: + msg141899
2011-08-07 00:20:20orsenthilsetmessages: + msg141731
2011-08-06 01:37:18pitrousetnosy: + pitrou
messages: + msg141700
2011-08-05 16:28:23eric.araujosetnosy: + eric.araujo
messages: + msg141667
2011-07-31 06:00:26chinsetfiles: + example.py

messages: + msg141458
2011-07-31 01:36:41orsenthilsettitle: [new function] shutil.cleartree -> Add a new shutil.cleartree function to shutil module
2011-07-31 01:36:10orsenthilsetnosy: + orsenthil
messages: + msg141455
2011-07-31 00:30:41r.david.murraysetnosy: + r.david.murray
messages: + msg141454
2011-07-30 17:52:52chincreate