diff -r 5fa855d20624 Lib/shutil.py --- a/Lib/shutil.py Thu Dec 03 22:26:36 2015 +0200 +++ b/Lib/shutil.py Thu Dec 03 17:04:08 2015 -0600 @@ -5,6 +5,7 @@ """ import os +import os.path import sys import stat import fnmatch @@ -1004,7 +1005,21 @@ return _ntuple_diskusage(total, used, free) -def chown(path, user=None, group=None): +def _dir_walk(path): + ''' Get All Directories & Files for chown() ''' + + for dir_path, dir_names, file_names in os.walk(path): + + # Directories + for dir_name in dir_names: + yield os.path.join(dir_path, dir_name) + + # Files + for file_name in file_names: + yield os.path.join(dir_path, file_name) + + +def chown(path, user=None, group=None, recursive=False): """Change owner user and group of the given path. user and group can be the uid/gid or the user/group names, and in that case, @@ -1033,7 +1048,13 @@ if _group is None: raise LookupError("no such group: {!r}".format(group)) - os.chown(path, _user, _group) + # Do Default First + if not recursive: + os.chown(path, _user, _group) + else: + for recursive_path in _dir_walk(path): + os.chown(recursive_path, _user, _group) + def get_terminal_size(fallback=(80, 24)): """Get the size of the terminal window.