tenseleyflow/sultree / 9301005

Browse files

'renderer'

Authored by espadonne
SHA
93010058264df03ac4813a33742d8a8acf4e067a
Parents
6b40f91
Tree
e9de9c7

2 changed files

StatusFile+-
M src/sultree/cli.py 10 7
M src/sultree/traversal.py 4 3
src/sultree/cli.pymodified
@@ -18,7 +18,7 @@ from typing import List, Optional
1818
 
1919
 from .args import parse_arguments
2020
 from .traversal import SecureTraverser, FileEntry
21
-from .formatting import TreeFormatter
21
+from .tree_renderer import TreeRenderer, build_tree_structure
2222
 from .selinux import is_selinux_enabled, SELinuxQueryError
2323
 from .constants import CONFIG
2424
 
@@ -46,7 +46,7 @@ def setup_logging(verbose: bool = False) -> None:
4646
 
4747
 
4848
 def process_directory(directory: Path, traverser: SecureTraverser, 
49
-                     formatter: TreeFormatter) -> bool:
49
+                     renderer: TreeRenderer) -> bool:
5050
     """
5151
     Process a single directory and display its tree.
5252
     
@@ -66,9 +66,12 @@ def process_directory(directory: Path, traverser: SecureTraverser,
6666
         for entry in traverser.traverse(directory):
6767
             entries.append(entry)
6868
             
69
-        # Format and display the tree
69
+        # Build proper tree structure
70
+        root_node = build_tree_structure(entries, directory)
71
+        
72
+        # Render the tree
7073
         show_report = True  # Could be made configurable
71
-        formatter.format_tree(directory, entries, show_report)
74
+        renderer.render_tree(directory, root_node, show_report)
7275
         
7376
         return True
7477
         
@@ -137,13 +140,13 @@ def main() -> int:
137140
         # Setup logging if needed (could add --verbose flag)
138141
         setup_logging(verbose=False)
139142
         
140
-        # Create traverser and formatter
143
+        # Create traverser and renderer
141144
         traverser = SecureTraverser(options)
142145
         
143146
         # Determine if SELinux context should be shown
144147
         show_selinux = options.selinux_filter is not None
145148
         
146
-        formatter = TreeFormatter(
149
+        renderer = TreeRenderer(
147150
             show_full_path=options.show_full_path,
148151
             show_selinux=show_selinux,
149152
             use_ascii=False  # Could be made configurable
@@ -159,7 +162,7 @@ def main() -> int:
159162
                 print()  # Empty line between directories
160163
                 
161164
             # Process directory
162
-            if process_directory(directory, traverser, formatter):
165
+            if process_directory(directory, traverser, renderer):
163166
                 success_count += 1
164167
             else:
165168
                 logger.warning(f"Failed to process directory: {directory}")
src/sultree/traversal.pymodified
@@ -136,7 +136,7 @@ class SecureTraverser:
136136
             
137137
         try:
138138
             # Get directory contents
139
-            entries = self._get_directory_entries(current_path)
139
+            entries = self._get_directory_entries(current_path, depth)
140140
             
141141
             # Apply file limit if specified
142142
             if self.options.file_limit is not None:
@@ -169,12 +169,13 @@ class SecureTraverser:
169169
         except OSError as e:
170170
             logger.warning(f"Error accessing {current_path}: {e}")
171171
             
172
-    def _get_directory_entries(self, dir_path: Path) -> List[FileEntry]:
172
+    def _get_directory_entries(self, dir_path: Path, depth: int = 0) -> List[FileEntry]:
173173
         """
174174
         Get entries in a directory with error handling.
175175
         
176176
         Args:
177177
             dir_path: Directory to read
178
+            depth: Current depth in traversal
178179
             
179180
         Returns:
180181
             List of FileEntry objects
@@ -204,7 +205,7 @@ class SecureTraverser:
204205
                         path=item,
205206
                         name=item.name,
206207
                         is_dir=is_dir,
207
-                        depth=0  # Will be set by caller
208
+                        depth=depth + 1  # Set correct depth
208209
                     ))
209210
                     
210211
                 except (OSError, RuntimeError) as e: