#!/usr/bin/env python3

import os
import os.path
import stat

# Recursively descend through a directory structure
# and make all directories world-readable and executable,
# and each file world readable. 
# Make all files writeable by owner.

def correct(directory):
    STARTDIR = os.getcwd()
    os.chdir(directory)
    for file in os.listdir(directory):
        if os.path.isdir(file):
            os.chmod(file, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | \
                stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
            correct(os.path.join(directory, file))
        else:
            mode = os.stat(file).st_mode | stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH
            os.chmod(file, mode)
    os.chdir(STARTDIR)

correct(os.getcwd())
