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) *  |
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) *  |
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) *  |
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) *  |
Date: 2011-08-06 01:37 |
I also think it sounds too specialized. |
|
|
msg141731 - (view) |
Author: Senthil Kumaran (orsenthil) *  |
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. |
|
|