MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / build_tree_text

Function build_tree_text

Scripts/Developer Base/Tree Explorer.py:395–445  ·  view source on GitHub ↗
(
    path: Path,
    *,
    max_depth: int,
    dirs_only: bool,
    show_size: bool,
    sort_by_size: bool,
    no_color: bool,
    include_hidden: bool,
    follow_symlinks: bool,
    ignore: List[str],
    only: List[str],
)

Source from the content-addressed store, hash-verified

393
394# ------------------ tree output ------------------
395def build_tree_text(
396 path: Path,
397 *,
398 max_depth: int,
399 dirs_only: bool,
400 show_size: bool,
401 sort_by_size: bool,
402 no_color: bool,
403 include_hidden: bool,
404 follow_symlinks: bool,
405 ignore: List[str],
406 only: List[str],
407) -> str:
408 lines: List[str] = []
409 root_st = safe_lstat(path)
410 root_mode = root_st.st_mode if root_st else 0
411 lines.append(colorize(str(path), root_mode, no_color))
412
413 def _walk(cur: Path, depth: int, prefix: str) -> None:
414 if max_depth != -1 and depth > max_depth:
415 return
416
417 need_sizes = show_size or sort_by_size
418 ents = scan_entries(
419 cur,
420 dirs_only=dirs_only,
421 include_hidden=include_hidden,
422 need_sizes=need_sizes,
423 sort_by_size=sort_by_size,
424 follow_symlinks=follow_symlinks,
425 ignore=ignore,
426 only=only,
427 )
428
429 for idx, e in enumerate(ents):
430 last = (idx == len(ents) - 1)
431 branch = "└── " if last else "├── "
432 next_prefix = prefix + (" " if last else "│ ")
433
434 label = colorize(e.name, e.mode, no_color)
435 if show_size:
436 label += f" [{format_size(e.total_size)}]"
437 lines.append(prefix + branch + label)
438
439 if e.is_dir:
440 _walk(e.path, depth + 1, next_prefix)
441
442 if path.is_dir():
443 _walk(path, 1, "")
444
445 return "\n".join(lines)
446
447
448# ------------------ JSON output ------------------

Callers 4

run_quickFunction · 0.70
run_customFunction · 0.70
run_only_foldersFunction · 0.70
mainFunction · 0.70

Calls 3

safe_lstatFunction · 0.70
colorizeFunction · 0.70
_walkFunction · 0.70

Tested by

no test coverage detected