Developer Reference
Module responsibilities
lsw.py contains the scanner and report logic. The published package also includes Flet for the graphical launcher.
Execution flow
flowchart TD
A[Parse CLI] --> B[Load config]
B --> C[Load user or local preset]
C --> D[Load .lswignore and CLI rules]
D --> E[Parse size and date filters]
E --> F{Output type}
F -->|txt| G[generate_text_tree]
F -->|csv/json/jsonl/markdown| H[collect_tree_items]
H --> I[Export records]
F -->|html| J[build_html_report]
J --> K[Generate tree and analytics]
K --> L[Write HTML]
L --> M[Open browser unless disabled]Inventory record contract
collect_tree_items returns dictionaries with path, name, type, size, mtime, and mtime_str. type is either file or dir. This record is the contract consumed by all structured exporters and by generate_analytics_data.
Size cache
get_folder_size stores results in the module-level _size_cache, keyed only by path. The cache is not keyed by ignore rules or depth. A long-running caller that changes those arguments should call clear_size_cache() before recalculating.
Error-handling style
Filesystem access catches OSError and PermissionError in traversal and metadata paths. Most unreadable entries are skipped. Configuration and CLI validation errors are surfaced to the user and terminate the command.
Maintenance notes
ThreadPoolExecutor,mimetypes,guess_extension,types_map, andsysare imported but unused.- The parallel CLI flags do not currently alter traversal.
show_hiddenand the configthemevalue are not wired into output generation.- HTML folder sizes use
get_folder_size, while analytics treemap sizes are independently recomputed. - The mutable default
count=[0]ingenerate_html_treeis shared across calls. Passing an explicit list is safer for repeated programmatic use. - The HTML
is_lastcalculation uses the unfiltered directory listing, so connectors can look visually inconsistent when entries are skipped by filters.
These notes describe the current implementation and are useful targets for future tests or refactoring; they are not required for normal CLI use.