'Descends down a directory and refactor every Python file found.
Python files are assumed to have a .py extension.
Files and subdirectories starting with \'.\' are skipped.'

def refactor_dir(self, dir_name, write=False, doctests_only=False):

    py_ext = (os.extsep + 'py')
    for (dirpath, dirnames, filenames) in os.walk(dir_name):
        self.log_debug('Descending    into    %s', dirpath)
        dirnames.sort()
        filenames.sort()
        for name in filenames:
            if ((not name.startswith('.')) and (os.path.splitext(name)[1] == py_ext)):
                fullname = os.path.join(dirpath, name)
                self.refactor_file(fullname, write, doctests_only)
        dirnames[:] = [dn for dn in dirnames if (not dn.startswith('.'))]
