def recurse_tree(rootpath, excludes, opts):
<EOL>if INITPY in os.listdir(rootpath):<EOL><INDENT>root_package = rootpath.split(path.sep)[-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>root_package = None<EOL><DEDENT>toplevels = []<EOL>followlinks = getattr(opts, '<STR_LIT>', False)<EOL>includeprivate = getattr(opts, '<STR_LIT>', False)<EOL>for root, subs, files in walk(rootpath, followlinks=followlinks):<EOL><INDENT>py_files = sorted(f for f in files<EOL>if path.splitext(f)[<NUM_LIT:1>] in PY_SUFFIXES and<EOL>not is_excluded(path.join(root, f), excludes))<EOL>is_pkg = INITPY in py_files<EOL>if is_pkg:<EOL><INDENT>py_files.remove(INITPY)<EOL>py_files.insert(<NUM_LIT:0>, INITPY)<EOL><DEDENT>elif root != rootpath:<EOL><INDENT>del subs[:]<EOL>continue<EOL><DEDENT>if includeprivate:<EOL><INDENT>exclude_prefixes = ('<STR_LIT:.>',)<EOL><DEDENT>else:<EOL><INDENT>exclude_prefixes = ('<STR_LIT:.>', '<STR_LIT:_>')<EOL><DEDENT>subs[:] = sorted(sub for sub in subs if not sub.startswith(exclude_prefixes)<EOL>and not is_excluded(path.join(root, sub), excludes))<EOL>if is_pkg:<EOL><INDENT>if subs or len(py_files) > <NUM_LIT:1> or notshall_skip(path.join(root, INITPY), opts):<EOL><INDENT>subpackage = root[len(rootpath):].lstrip(path.sep).replace(path.sep, '<STR_LIT:.>')<EOL>create_package_file(root, root_package, subpackage,<EOL>py_files, opts, subs)<EOL>toplevels.append(makename(root_package, subpackage))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>assert root == rootpath and root_package is None<EOL>for py_file in py_files:<EOL><INDENT>if not shall_skip(path.join(rootpath, py_file), opts):<EOL><INDENT>module = path.splitext(py_file)[<NUM_LIT:0>]<EOL>create_module_file(root_package, module, opts)<EOL>toplevels.append(module)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return toplevels<EOL>
Look for every file in the directory tree and create the corresponding
ReST files.