[Python-ideas] Add shutil.chown(..., recursive=False)
Wes Turner
wes.turner at gmail.com
Mon May 28 19:07:29 EDT 2018
path.py Path.choen supports names in addition to the uid/gid numbers which
os.chown supports:
https://pathpy.readthedocs.io/en/stable/api.html#path.Path.chown
https://github.com/jaraco/path.py/blob/master/path.py#L1176
https://pathpy.readthedocs.io/en/stable/api.html#path.Path.walk
On Monday, May 28, 2018, Giampaolo Rodola' <g.rodola at gmail.com> wrote:
>
>
> On Mon, May 28, 2018 at 11:13 PM, Barry <barry at barrys-emacs.org> wrote:
>
>>
>> On 28 May 2018, at 21:23, Giampaolo Rodola' <g.rodola at gmail.com> wrote:
>>
>> ...as in (not tested):
>>
>> def _rchown(dir, user, group):
>> for root, dirs, files in os.walk(dir, topdown=False):
>> for name in files:
>> chown(os.path.join(root, name), user, group)
>>
>> def chown(path, user=None, group=None, recursive=False):
>> if recursive and os.path.isdir(path):
>> _rchown(dir, user, group)
>> ...
>>
>> It appears like a common enough use case to me ("chown -R path").
>> Thoughts?
>>
>>
>> I wonder if it is very common.
>> Don’t you have to be root or use sudo chown?
>> In which case it is only python code running as root that could use this.
>>
>> Barry
>>
>
> You're right, I didn't think about that. I remember myself doing "chown -R
> dir" every once in a while but didn't recall I prepended "sudo". =)
>
> --
> Giampaolo - http://grodola.blogspot.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180528/52342423/attachment-0001.html>
More information about the Python-ideas
mailing list