Issue 12661: Add a new shutil.cleartree function to shutil module (original) (raw)

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:20 admin set github: 56870
2011-08-11 10:45:12 chin set resolution: not a bug -> rejected
2011-08-11 10:45:04 chin set status: open -> closedresolution: not a bugmessages: +
2011-08-07 00:20:20 orsenthil set messages: +
2011-08-06 01:37:18 pitrou set nosy: + pitroumessages: +
2011-08-05 16:28:23 eric.araujo set nosy: + eric.araujomessages: +
2011-07-31 06:00:26 chin set files: + example.pymessages: +
2011-07-31 01:36:41 orsenthil set title: [new function] shutil.cleartree -> Add a new shutil.cleartree function to shutil module
2011-07-31 01:36:10 orsenthil set nosy: + orsenthilmessages: +
2011-07-31 00:30:41 r.david.murray set nosy: + r.david.murraymessages: +
2011-07-30 17:52:52 chin create