<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 29 May 2018 at 06:23, Giampaolo Rodola' <span dir="ltr"><<a href="mailto:g.rodola@gmail.com" target="_blank">g.rodola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div>...as in (not tested):</div><div><br></div><div>    def _rchown(dir, user, group):</div><div>        for root, dirs, files in os.walk(dir, topdown=False):</div><div>            for name in files:</div><div>                chown(os.path.join(root, name), user, group)</div><div><br></div><div>    def chown(path, user=None, group=None, recursive=False):</div><div>        if recursive and os.path.isdir(path):</div><div>            _rchown(dir, user, group)</div><div>        ...</div><div><br></div><div>It appears like a common enough use case to me ("chown -R path"). </div><div>Thoughts?</div></div></div></div></blockquote><div><br></div><a href="https://bugs.python.org/issue13033">https://bugs.python.org/issue13033</a> is a long-open RFE for this, proposing to add it as "shutil.chowntree" (naming inspired by "shutil.rmtree" and "shutil.copytree").</div><div class="gmail_quote"><br></div><div class="gmail_quote">The "walkdir" project I mention on that PR has been on hiatus for a few years now (aside from a bit of activity to get a new release out in 2016 with several contributed fixes), but the main point of the comment where I mentioned it still stands: the hard part of designing recursive state modification APIs is deciding what to do when an operation fails after you've already made changes to the state of the disk.</div><div class="gmail_quote"><br></div><div class="gmail_quote">shutil.rmtree fortunately provides some good precedent there, but it does mean this feature would need to be implemented as its own API, rather than as an option on shutil.chown.<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">Cheers,</div><div class="gmail_quote">Nick.<br></div><br>-- <br><div class="gmail_signature">Nick Coghlan   |   <a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>   |   Brisbane, Australia</div>
</div></div>