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

Function scan_entries

Scripts/Developer Base/Tree Explorer.py:334–391  ·  view source on GitHub ↗
(
    base: Path,
    *,
    dirs_only: bool,
    include_hidden: bool,
    need_sizes: bool,
    sort_by_size: bool,
    follow_symlinks: bool,
    ignore: List[str],
    only: List[str],
)

Source from the content-addressed store, hash-verified

332
333
334def scan_entries(
335 base: Path,
336 *,
337 dirs_only: bool,
338 include_hidden: bool,
339 need_sizes: bool,
340 sort_by_size: bool,
341 follow_symlinks: bool,
342 ignore: List[str],
343 only: List[str],
344) -> List[Entry]:
345 entries: List[Entry] = []
346 try:
347 with os.scandir(base) as it:
348 for de in it:
349 if de.name in (".", ".."):
350 continue
351 if not include_hidden and de.name.startswith("."):
352 continue
353
354 p = base / de.name
355
356 if match_any(p, de.name, ignore):
357 continue
358
359 if only and not match_any(p, de.name, only) and not p.is_dir():
360 continue
361
362 try:
363 st = de.stat(follow_symlinks=follow_symlinks)
364 except OSError:
365 continue
366
367 mode = st.st_mode
368 is_dir = stat.S_ISDIR(mode)
369
370 if dirs_only and not is_dir:
371 continue
372
373 size = int(st.st_size)
374
375 total = size
376 if (need_sizes or sort_by_size) and is_dir:
377 total = get_total_size(
378 p,
379 follow_symlinks=follow_symlinks,
380 ignore=ignore,
381 only=only,
382 include_hidden=include_hidden,
383 stats=None,
384 )
385
386 entries.append(Entry(de.name, p, mode, is_dir, size, int(total)))
387 except OSError:
388 return []
389
390 entries.sort(key=(lambda e: (-e.total_size, e.name.lower())) if sort_by_size else (lambda e: e.name.lower()))
391 return entries

Callers 2

_walkFunction · 0.70
build_rich_treeFunction · 0.70

Calls 3

match_anyFunction · 0.70
get_total_sizeFunction · 0.70
EntryClass · 0.70

Tested by

no test coverage detected