MCPcopy Create free account
hub / github.com/boostorg/build / _handle_dir

Function _handle_dir

v2/test/tree.py:209–243  ·  view source on GitHub ↗

Main recursive worker function for build_tree(). Returns a newly created tree node representing the given normalized folder path as well as the maximum file/folder modification time detected under the same path.

(path)

Source from the content-addressed store, hash-verified

207
208
209def _handle_dir(path):
210 """
211 Main recursive worker function for build_tree(). Returns a newly created
212 tree node representing the given normalized folder path as well as the
213 maximum file/folder modification time detected under the same path.
214
215 """
216 files = []
217 dirs = []
218 node = TreeNode(os.path.basename(path), children=[])
219 max_mtime = node.mtime = os.stat(path).st_mtime
220
221 # List files & folders.
222 for f in os.listdir(path):
223 f = os.path.join(path, f)
224 if os.path.isdir(f):
225 dirs.append(f)
226 elif os.path.isfile(f):
227 files.append(f)
228
229 # Add a child node for each file.
230 for f in files:
231 fcontents = _get_text(f)
232 new_file_node = TreeNode(os.path.basename(f), contents=fcontents)
233 new_file_node.mtime = os.stat(f).st_mtime
234 max_mtime = max(max_mtime, new_file_node.mtime)
235 node.add_child(new_file_node)
236
237 # For each subdir, create a node, walk its tree, add it as a child.
238 for d in dirs:
239 new_dir_node, new_max_mtime = _handle_dir(d)
240 max_mtime = max(max_mtime, new_max_mtime)
241 node.add_child(new_dir_node)
242
243 return node, max_mtime

Callers 1

build_treeFunction · 0.85

Calls 4

add_childMethod · 0.95
TreeNodeClass · 0.85
_get_textFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected