'Given a destination file/dir (recursively) set the permissions on
all the files and directories to the max allowed by running umask.'

def _set_umask_perms(self, dest):

    umask = os.umask(0)
    os.umask(umask)
    max_privs = (511 & (~ umask))
    def set_file_privs(filename):
        file_stat = os.stat(filename)
        file_privs = max_privs
        if (not (file_stat.st_mode & 73)):
            file_privs &= (~ 73)
        os.chmod(filename, file_privs)
    for (root, dirs, files) in os.walk(dest, topdown=False):
        for dirname in dirs:
            os.chmod(os.path.join(root, dirname), max_privs)
        for filename in files:
            set_file_privs(os.path.join(root, filename))
    if os.path.isdir(dest):
        os.chmod(dest, max_privs)
    else:
        set_file_privs(dest)
