ptdu 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ptdu/utils.py ADDED
@@ -0,0 +1,80 @@
1
+ """Utility classes for PTDU."""
2
+
3
+ from __future__ import annotations
4
+
5
+
6
+ class SizeCalculator:
7
+ """Utility class for size calculations and formatting."""
8
+
9
+ # Size units in bytes
10
+ UNITS: list[tuple[str, int]] = [
11
+ ("B", 1),
12
+ ("KB", 1024),
13
+ ("MB", 1024**2),
14
+ ("GB", 1024**3),
15
+ ("TB", 1024**4),
16
+ ("PB", 1024**5),
17
+ ]
18
+
19
+ @classmethod
20
+ def format_size(cls, size_bytes: int) -> str:
21
+ """Format byte size to human-readable string.
22
+
23
+ Args:
24
+ size_bytes: Size in bytes
25
+
26
+ Returns:
27
+ Human-readable size string (e.g., "1.5 MB", "512 B")
28
+ """
29
+ if size_bytes < 0:
30
+ raise ValueError("Size cannot be negative")
31
+
32
+ if size_bytes == 0:
33
+ return "0 B"
34
+
35
+ # Find appropriate unit
36
+ for unit_name, unit_bytes in reversed(cls.UNITS):
37
+ if size_bytes >= unit_bytes:
38
+ value = size_bytes / unit_bytes
39
+ # Use integer for bytes, one decimal for KB, two for larger
40
+ if unit_name == "B":
41
+ return f"{int(value)} {unit_name}"
42
+ elif unit_name == "KB":
43
+ return f"{value:.1f} {unit_name}"
44
+ else:
45
+ return f"{value:.2f} {unit_name}"
46
+
47
+ return f"{size_bytes} B"
48
+
49
+ @classmethod
50
+ def format_percentage(cls, part: int, total: int) -> str:
51
+ """Calculate and format percentage.
52
+
53
+ Args:
54
+ part: The partial size
55
+ total: The total size
56
+
57
+ Returns:
58
+ Percentage string (e.g., "45.2%")
59
+ """
60
+ if total <= 0:
61
+ return "0.0%"
62
+
63
+ percentage = (part / total) * 100
64
+ return f"{percentage:.1f}%"
65
+
66
+ @classmethod
67
+ def calculate_percentage(cls, part: int, total: int) -> float:
68
+ """Calculate percentage as float.
69
+
70
+ Args:
71
+ part: The partial size
72
+ total: The total size
73
+
74
+ Returns:
75
+ Percentage value (0-100)
76
+ """
77
+ if total <= 0:
78
+ return 0.0
79
+
80
+ return (part / total) * 100
@@ -0,0 +1,341 @@
1
+ Metadata-Version: 2.4
2
+ Name: ptdu
3
+ Version: 0.1.0
4
+ Summary: Python Tkinter Disk Usage analyzer - an ncdu-like tool with vim keybindings
5
+ Project-URL: Homepage, https://github.com/cosmez/ptdu
6
+ Project-URL: Repository, https://github.com/cosmez/ptdu
7
+ Project-URL: Issues, https://github.com/cosmez/ptdu/issues
8
+ Author: Cosme Zamudio
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: analyzer,disk,ncdu,tkinter,tui,usage,vim
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: X11 Applications
14
+ Classifier: Intended Audience :: End Users/Desktop
15
+ Classifier: Intended Audience :: System Administrators
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: System :: Filesystems
25
+ Classifier: Topic :: Utilities
26
+ Requires-Python: >=3.8
27
+ Requires-Dist: send2trash>=2.1.0
28
+ Description-Content-Type: text/markdown
29
+
30
+ # PTDU - Python Tkinter Disk Usage
31
+
32
+ PTDU is a graphical disk usage analyzer built with Python and Tkinter, inspired by ncdu (NCurses Disk Usage). It provides an interactive, navigable tree view of directory sizes with full recursive scanning, vim-like keyboard navigation, SQLite caching, and comprehensive error handling.
33
+
34
+ ## Features
35
+
36
+ - **Interactive Tree View**: Navigate directories with an intuitive tree interface
37
+ - **Full Recursive Scan**: Complete directory tree scanning for accurate size information
38
+ - **Background Scanning**: All filesystem operations run in separate threads
39
+ - **Vim-like Navigation**: Keyboard-first interface (j/k navigation, h/l expand/collapse)
40
+ - **Human-readable Sizes**: Automatic conversion (B, KB, MB, GB, TB)
41
+ - **SQLite Caching**: Persistent cache for faster subsequent scans
42
+ - **Virtual Scrolling**: Optimized handling of large directories (100k+ items)
43
+ - **Export**: Save scan results to JSON or CSV
44
+ - **Safe Delete**: Move to trash with confirmation
45
+ - **Cross-platform**: Linux, macOS, and Windows support
46
+
47
+ ## Requirements
48
+
49
+ - Python 3.8+
50
+ - Tkinter (usually included with Python)
51
+ - send2trash (optional, for safer file deletion)
52
+
53
+ ## Installation
54
+
55
+ ### From Source
56
+
57
+ ```bash
58
+ # Clone the repository
59
+ git clone https://github.com/cosmez/ptdu.git
60
+ cd ptdu
61
+
62
+ # Install in editable mode
63
+ pip install -e .
64
+ ```
65
+
66
+ ### Using pip
67
+
68
+ ```bash
69
+ pip install ptdu
70
+ ```
71
+
72
+ ## Usage
73
+
74
+ ### Basic Usage
75
+
76
+ ```bash
77
+ # Analyze current directory
78
+ ptdu
79
+
80
+ # Analyze specific directory
81
+ ptdu /path/to/directory
82
+
83
+ # Show help
84
+ ptdu --help
85
+ ```
86
+
87
+ ### Command-Line Options
88
+
89
+ ```bash
90
+ ptdu [path] [options]
91
+
92
+ Options:
93
+ path Directory to analyze (default: current directory)
94
+ --follow-symlinks Follow symbolic links when scanning
95
+ --exclude, -e Additional patterns to exclude (multiple allowed)
96
+ --max-depth, -d Maximum scan depth
97
+ --no-cache Disable SQLite caching
98
+ --clear-cache Clear cache before starting
99
+ --version Show version information
100
+ --help Show help message
101
+ ```
102
+
103
+ ### Examples
104
+
105
+ ```bash
106
+ # Analyze home directory, excluding node_modules and .git
107
+ ptdu ~ -e node_modules -e .git
108
+
109
+ # Scan with limited depth for faster results
110
+ ptdu /var -d 3
111
+
112
+ # Clear cache and rescan
113
+ ptdu --clear-cache /path/to/dir
114
+
115
+ # Follow symbolic links
116
+ ptdu --follow-symlinks /path/to/dir
117
+ ```
118
+
119
+ ## Keyboard Shortcuts
120
+
121
+ ### Navigation
122
+
123
+ | Key | Action |
124
+ |-----|--------|
125
+ | `j` or `↓` | Move down |
126
+ | `k` or `↑` | Move up |
127
+ | `h` or `←` | Collapse directory |
128
+ | `l` or `→` | Expand directory |
129
+ | `Enter` | Toggle expand/collapse |
130
+ | `g` | Jump to top |
131
+ | `G` | Jump to bottom |
132
+ | `u` | Go to parent directory |
133
+
134
+ ### Actions
135
+
136
+ | Key | Action |
137
+ |-----|--------|
138
+ | `q` | Quit application |
139
+ | `r` | Rescan current directory |
140
+ | `d` | Delete selected item (with confirmation) |
141
+ | `b` | Toggle breadcrumb/path bar |
142
+ | `o` | Open folder in file manager |
143
+ | `e` | Export scan results (JSON/CSV) |
144
+
145
+ ### View Options
146
+
147
+ | Key | Action |
148
+ |-----|--------|
149
+ | `.` | Toggle hidden files (dotfiles) |
150
+ | `s` | Cycle sort mode (Size → Name → Items) |
151
+ | `Ctrl + Plus` | Increase font size |
152
+ | `Ctrl + Minus` | Decrease font size |
153
+ | `Ctrl + 0` | Reset font size |
154
+
155
+ ## Display
156
+
157
+ ### Columns
158
+
159
+ 1. **Name** - File or directory name with icon (📁/📂/📄)
160
+ 2. **Size** - Human-readable size
161
+ 3. **Size Bar** - Visual representation of relative size
162
+ 4. **Percent** - Percentage of parent directory
163
+ 5. **Items** - Number of items (directories only)
164
+
165
+ ### Color Coding
166
+
167
+ - **Blue** - Directories
168
+ - **Black** - Regular files
169
+ - **Gray** - Hidden files (starting with `.`)
170
+ - **Orange** - Medium files (10-100 MB)
171
+ - **Red** - Large files (>100 MB)
172
+
173
+ ## Caching
174
+
175
+ PTDU automatically caches scan results to speed up subsequent scans:
176
+
177
+ - Cache location: `~/.cache/ptdu/cache.db`
178
+ - Automatic invalidation when directories are modified
179
+ - Thread-safe operations
180
+
181
+ To disable caching:
182
+ ```bash
183
+ ptdu --no-cache /path/to/dir
184
+ ```
185
+
186
+ To clear the cache:
187
+ ```bash
188
+ ptdu --clear-cache
189
+ ```
190
+
191
+ ## Development
192
+
193
+ ### Setup Development Environment
194
+
195
+ ```bash
196
+ # Create virtual environment
197
+ python -m venv .venv
198
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
199
+
200
+ # Install in editable mode with dev dependencies
201
+ pip install -e ".[dev]"
202
+ ```
203
+
204
+ ### Running Tests
205
+
206
+ ```bash
207
+ pytest
208
+ ```
209
+
210
+ ### Type Checking
211
+
212
+ ```bash
213
+ mypy --strict ptdu/
214
+ ```
215
+
216
+ ### Running the Application
217
+
218
+ ```bash
219
+ # Run in development mode
220
+ python -m ptdu.main
221
+
222
+ # Or use the installed command
223
+ ptdu
224
+ ```
225
+
226
+ ## Project Structure
227
+
228
+ ```
229
+ ptdu/
230
+ ├── ptdu/ # Main package
231
+ │ ├── __init__.py # Package exports
232
+ │ ├── cache.py # SQLite caching
233
+ │ ├── errors.py # Error handling
234
+ │ ├── fonts.py # OS-aware font configuration
235
+ │ ├── main.py # Entry point with CLI args
236
+ │ ├── models.py # DirNode data model
237
+ │ ├── performance.py # Virtual scrolling, memory optimization
238
+ │ ├── scanner.py # Directory scanning
239
+ │ ├── threads.py # Background threading
240
+ │ ├── treeview.py # Directory tree view widget
241
+ │ ├── ui.py # Main window
242
+ │ └── utils.py # SizeCalculator utility
243
+ ├── tests/ # Test suite
244
+ │ ├── __init__.py
245
+ │ ├── test_models.py
246
+ │ ├── test_scanner.py
247
+ │ ├── test_threads.py
248
+ │ ├── test_treeview.py
249
+ │ ├── test_ui.py
250
+ │ └── test_utils.py
251
+ ├── docs/ # Documentation
252
+ │ ├── user_guide.md # User documentation
253
+ │ └── developer.md # Developer documentation
254
+ ├── README.md # This file
255
+ └── pyproject.toml # Project configuration
256
+ ```
257
+
258
+ ## Modules Overview
259
+
260
+ ### `ptdu.models`
261
+ - **DirNode**: Tree node representing files and directories
262
+ - Parent-child relationships with size propagation
263
+ - Expand/collapse state tracking
264
+
265
+ ### `ptdu.scanner`
266
+ - **Scanner**: High-performance directory scanner using `os.scandir()`
267
+ - **ScanResult**: Dataclass for scanned entries
268
+ - **MemoryMonitor**: Memory usage tracking
269
+ - Pattern-based filtering (skip/exclude)
270
+ - Recursive scanning with configurable depth
271
+
272
+ ### `ptdu.cache`
273
+ - **ScanCache**: SQLite-based caching with mtime invalidation
274
+ - Thread-safe operations with locking
275
+ - Automatic cache validation
276
+
277
+ ### `ptdu.performance`
278
+ - **VirtualScroller**: Efficient handling of large directories
279
+ - **MemoryOptimizer**: Memory usage optimization
280
+ - **LargeDirectoryHandler**: Special handling for huge directories
281
+
282
+ ### `ptdu.errors`
283
+ - **ErrorHandler**: Centralized error handling with dialogs
284
+ - **PathValidator**: Path validation and sanitization
285
+ - User-friendly error messages with suggestions
286
+
287
+ ### `ptdu.threads`
288
+ - **ScanThread**: Background scanning thread
289
+ - **ScanThreadManager**: Thread lifecycle management
290
+ - Queue-based message passing
291
+
292
+ ### `ptdu.treeview`
293
+ - **DirectoryTreeview**: Custom Treeview with styling
294
+ - Size bars, color coding, icon display
295
+ - Node mapping for tree operations
296
+
297
+ ### `ptdu.ui`
298
+ - **MainWindow**: Main application window
299
+ - Keyboard shortcut handling
300
+ - Integration with all components
301
+
302
+ ### `ptdu.fonts`
303
+ - **FontManager**: OS-aware font detection
304
+ - Dynamic font size adjustment
305
+ - Cross-platform font selection
306
+
307
+ ### `ptdu.utils`
308
+ - **SizeCalculator**: Human-readable size formatting
309
+ - Percentage calculations
310
+
311
+ ## Performance
312
+
313
+ PTDU is optimized for large directories:
314
+
315
+ - **Virtual Scrolling**: Renders only visible items (100k+ items supported)
316
+ - **Memory Monitoring**: Configurable thresholds with warnings
317
+ - **Depth Limiting**: `--max-depth` for limiting recursion
318
+ - **Caching**: Persistent SQLite cache reduces re-scan time
319
+
320
+ Typical performance:
321
+ - SSD: 50k-100k files/second
322
+ - HDD: 5k-10k files/second
323
+
324
+ ## Error Handling
325
+
326
+ Comprehensive error handling includes:
327
+
328
+ - Permission denied dialogs with retry/skip/abort options
329
+ - Long path warnings (>4000 characters)
330
+ - Scan error handling with continue options
331
+ - Delete error handling with retry
332
+ - Cache error handling (non-critical, continues without cache)
333
+
334
+ ## Documentation
335
+
336
+ - **User Guide**: `docs/user_guide.md` - Complete user documentation
337
+ - **Developer Docs**: `docs/developer.md` - Architecture and API documentation
338
+
339
+ ## License
340
+
341
+ MIT License
@@ -0,0 +1,17 @@
1
+ ptdu/__init__.py,sha256=aldEgsi3EE8D-GscpFk7-HwJ8O4sO1kvrF5fayKXNSk,945
2
+ ptdu/cache.py,sha256=_c9zBNFAH8Och-ZWg1HK2h4kgIaAnXK1w8cMTLyympg,11596
3
+ ptdu/errors.py,sha256=Yv-4rpM6BPnF-hAcpnrpdcu7gZyuw1RJR1d8E8rA30U,16676
4
+ ptdu/fonts.py,sha256=tSAm-4ps_CcbgfFr9atdb76i0fc0aN-0l-fhxc85Mr4,6975
5
+ ptdu/main.py,sha256=lhIBZaIKDIsIrqWwizfmTSxCDn5uMzs8j-h5bvstc2E,3104
6
+ ptdu/models.py,sha256=jUg2qw4SHOCbId_aq9e4o1SAWrOdKqMYPEkpM0oj3z4,3477
7
+ ptdu/performance.py,sha256=vxamlKuDlTjijV-7Uwv4lRQk5xlCGQdV2fYoLxGDN7Q,9208
8
+ ptdu/scanner.py,sha256=vZihN5wUzDNisV5p34ibjkDrZVoJaqjmbI22zv1QOSE,14835
9
+ ptdu/threads.py,sha256=oTzPsx4CaXRWnZ0KVP-AkZu4ZXm9cq8CK9bFGLaZXXQ,7039
10
+ ptdu/treeview.py,sha256=buOG8aW627CnjnkxcoURkrc4ostZovVyraJw5yoAy2A,12598
11
+ ptdu/ui.py,sha256=NrQdbD6mI-HPZhFhDzxIVJNnHUa8SoMW4T2JJ5p0q7I,42052
12
+ ptdu/utils.py,sha256=cdF-ayUwJvjHSlSMPxBV6A_DL9j6hdXZXHxNcn_bcA4,2096
13
+ ptdu-0.1.0.dist-info/METADATA,sha256=Jw5OeLqSoSXmF9y82ajwegfz8NbKI9rNvAgLgu1gVd8,9454
14
+ ptdu-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
15
+ ptdu-0.1.0.dist-info/entry_points.txt,sha256=o4TYqm432nS64rDR1OrrN4RGM_JjuDDvdUrmCtWjNAc,40
16
+ ptdu-0.1.0.dist-info/licenses/LICENSE,sha256=HIYkq8inF0pvCg6jWFbZJBIXjqahJmHyby8IConQm_Q,1070
17
+ ptdu-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ptdu = ptdu.main:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Cosme Zamudio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.