pathflow-toolkit 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.
- path_file/__init__.py +223 -0
- path_file/__main__.py +6 -0
- path_file/_internal/__init__.py +87 -0
- path_file/_internal/_iterators.py +349 -0
- path_file/_internal/_log.py +153 -0
- path_file/_internal/_parsers.py +234 -0
- path_file/_internal/_safety.py +268 -0
- path_file/_version.py +1 -0
- path_file/actions.py +855 -0
- path_file/archive.py +447 -0
- path_file/chain.py +1028 -0
- path_file/cli.py +582 -0
- path_file/entries.py +459 -0
- path_file/exceptions.py +174 -0
- path_file/filters.py +654 -0
- path_file/hash.py +338 -0
- path_file/progress.py +321 -0
- path_file/py.typed +0 -0
- path_file/report.py +348 -0
- path_file/rules.py +481 -0
- path_file/search.py +472 -0
- path_file/sync.py +384 -0
- path_file/units.py +420 -0
- path_file/utils.py +509 -0
- path_file/watch.py +310 -0
- pathflow_toolkit-0.1.0.dist-info/METADATA +219 -0
- pathflow_toolkit-0.1.0.dist-info/RECORD +30 -0
- pathflow_toolkit-0.1.0.dist-info/WHEEL +4 -0
- pathflow_toolkit-0.1.0.dist-info/entry_points.txt +2 -0
- pathflow_toolkit-0.1.0.dist-info/licenses/LICENSE +21 -0
path_file/watch.py
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"""Folder monitoring with polling-based watcher."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import threading
|
|
6
|
+
import time
|
|
7
|
+
from collections.abc import Callable
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from types import TracebackType
|
|
12
|
+
|
|
13
|
+
from path_file._internal._iterators import scan_dir
|
|
14
|
+
from path_file._internal._log import get_logger, log_debug
|
|
15
|
+
from path_file.entries import Entry
|
|
16
|
+
|
|
17
|
+
logger = get_logger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# ──────────────────────────────────────────────────────────────────────────────
|
|
21
|
+
# WATCH EVENT
|
|
22
|
+
# ──────────────────────────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class WatchEvent:
|
|
27
|
+
"""File system event."""
|
|
28
|
+
|
|
29
|
+
type: str # "created", "modified", "deleted", "moved"
|
|
30
|
+
path: Path
|
|
31
|
+
old_path: Path | None = None
|
|
32
|
+
timestamp: datetime = field(default_factory=datetime.now)
|
|
33
|
+
entry: Entry | None = None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# ──────────────────────────────────────────────────────────────────────────────
|
|
37
|
+
# WATCHER
|
|
38
|
+
# ──────────────────────────────────────────────────────────────────────────────
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Watcher:
|
|
42
|
+
"""
|
|
43
|
+
Polling-based directory watcher.
|
|
44
|
+
|
|
45
|
+
Uses os.scandir to detect changes. No external dependencies.
|
|
46
|
+
|
|
47
|
+
Example:
|
|
48
|
+
watcher = pf.watch("~/Downloads")
|
|
49
|
+
watcher.filter("*.jpg").on_new(lambda e: print(f"New: {e}"))
|
|
50
|
+
watcher.run_forever()
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
def __init__(
|
|
54
|
+
self,
|
|
55
|
+
path: str | Path,
|
|
56
|
+
poll_interval: float = 1.0,
|
|
57
|
+
recursive: bool = False,
|
|
58
|
+
) -> None:
|
|
59
|
+
self.path = Path(path).resolve()
|
|
60
|
+
self.poll_interval = poll_interval
|
|
61
|
+
self.recursive = recursive
|
|
62
|
+
|
|
63
|
+
# Callbacks
|
|
64
|
+
self._on_new: Callable[[WatchEvent], None] | None = None
|
|
65
|
+
self._on_modified: Callable[[WatchEvent], None] | None = None
|
|
66
|
+
self._on_deleted: Callable[[WatchEvent], None] | None = None
|
|
67
|
+
self._on_moved: Callable[[WatchEvent], None] | None = None
|
|
68
|
+
|
|
69
|
+
# Filters
|
|
70
|
+
self._name_filter: Callable[[str], bool] | None = None
|
|
71
|
+
self._entry_filter: Callable[[Entry], bool] | None = None
|
|
72
|
+
|
|
73
|
+
# Debounce
|
|
74
|
+
self._debounce_seconds: float = 0
|
|
75
|
+
self._last_event: dict[Path, float] = {}
|
|
76
|
+
|
|
77
|
+
# State
|
|
78
|
+
self._snapshot: dict[Path, tuple[int, float]] = {} # path -> (size, mtime)
|
|
79
|
+
self._running = False
|
|
80
|
+
self._thread: threading.Thread | None = None
|
|
81
|
+
self._stop_event = threading.Event()
|
|
82
|
+
|
|
83
|
+
# Initialize snapshot
|
|
84
|
+
self._update_snapshot()
|
|
85
|
+
|
|
86
|
+
def _update_snapshot(self) -> None:
|
|
87
|
+
"""Update internal snapshot of directory state."""
|
|
88
|
+
self._snapshot = {}
|
|
89
|
+
try:
|
|
90
|
+
for entry in scan_dir(self.path):
|
|
91
|
+
self._snapshot[entry.path] = (entry.size, entry.modified.timestamp())
|
|
92
|
+
except (OSError, PermissionError):
|
|
93
|
+
pass
|
|
94
|
+
|
|
95
|
+
# ─── Filter Methods ──────────────────────────────────────────────────────
|
|
96
|
+
|
|
97
|
+
def filter(self, pattern: str) -> Watcher:
|
|
98
|
+
"""Filter events by glob pattern on name."""
|
|
99
|
+
import fnmatch
|
|
100
|
+
|
|
101
|
+
self._name_filter = lambda name: fnmatch.fnmatch(name, pattern)
|
|
102
|
+
return self
|
|
103
|
+
|
|
104
|
+
def filter_by(self, predicate: Callable[[Entry], bool]) -> Watcher:
|
|
105
|
+
"""Filter events by custom predicate on Entry."""
|
|
106
|
+
self._entry_filter = predicate
|
|
107
|
+
return self
|
|
108
|
+
|
|
109
|
+
def debounce(self, seconds: float) -> Watcher:
|
|
110
|
+
"""Debounce events - ignore rapid successive events for same path."""
|
|
111
|
+
self._debounce_seconds = seconds
|
|
112
|
+
return self
|
|
113
|
+
|
|
114
|
+
# ─── Callback Methods ────────────────────────────────────────────────────
|
|
115
|
+
|
|
116
|
+
def on_new(self, callback: Callable[[WatchEvent], None]) -> Watcher:
|
|
117
|
+
"""Callback for new files."""
|
|
118
|
+
self._on_new = callback
|
|
119
|
+
return self
|
|
120
|
+
|
|
121
|
+
def on_modified(self, callback: Callable[[WatchEvent], None]) -> Watcher:
|
|
122
|
+
"""Callback for modified files."""
|
|
123
|
+
self._on_modified = callback
|
|
124
|
+
return self
|
|
125
|
+
|
|
126
|
+
def on_deleted(self, callback: Callable[[WatchEvent], None]) -> Watcher:
|
|
127
|
+
"""Callback for deleted files."""
|
|
128
|
+
self._on_deleted = callback
|
|
129
|
+
return self
|
|
130
|
+
|
|
131
|
+
def on_moved(self, callback: Callable[[WatchEvent], None]) -> Watcher:
|
|
132
|
+
"""Callback for moved/renamed files."""
|
|
133
|
+
self._on_moved = callback
|
|
134
|
+
return self
|
|
135
|
+
|
|
136
|
+
# ─── Event Processing ────────────────────────────────────────────────────
|
|
137
|
+
|
|
138
|
+
def _scan(self) -> list[WatchEvent]:
|
|
139
|
+
"""Scan for changes and return list of events."""
|
|
140
|
+
events = []
|
|
141
|
+
current: dict[Path, tuple[int, float]] = {}
|
|
142
|
+
|
|
143
|
+
try:
|
|
144
|
+
for entry in scan_dir(self.path):
|
|
145
|
+
current[entry.path] = (entry.size, entry.modified.timestamp())
|
|
146
|
+
except (OSError, PermissionError):
|
|
147
|
+
pass
|
|
148
|
+
|
|
149
|
+
# Detect changes
|
|
150
|
+
all_paths = set(self._snapshot.keys()) | set(current.keys())
|
|
151
|
+
|
|
152
|
+
for path in all_paths:
|
|
153
|
+
old = self._snapshot.get(path)
|
|
154
|
+
new = current.get(path)
|
|
155
|
+
|
|
156
|
+
if old is None and new is not None:
|
|
157
|
+
# Created
|
|
158
|
+
events.append(WatchEvent("created", path, entry=Entry.from_path(path)))
|
|
159
|
+
elif old is not None and new is None:
|
|
160
|
+
# Deleted
|
|
161
|
+
events.append(WatchEvent("deleted", path))
|
|
162
|
+
elif old is not None and new is not None and (old[0] != new[0] or old[1] != new[1]):
|
|
163
|
+
# Check for modification
|
|
164
|
+
events.append(WatchEvent("modified", path, entry=Entry.from_path(path)))
|
|
165
|
+
|
|
166
|
+
# Apply filters (name glob / entry predicate)
|
|
167
|
+
events = [e for e in events if self._filter_event(e)]
|
|
168
|
+
|
|
169
|
+
# Detect moves (heuristic: similar size, one deleted, one created)
|
|
170
|
+
# This is a simplified detection
|
|
171
|
+
created = [e for e in events if e.type == "created"]
|
|
172
|
+
deleted = [e for e in events if e.type == "deleted"]
|
|
173
|
+
|
|
174
|
+
for c in created:
|
|
175
|
+
for d in deleted:
|
|
176
|
+
if c.entry and abs(c.entry.size - self._snapshot.get(d.path, (0,))[0]) < 1024:
|
|
177
|
+
# Likely a move
|
|
178
|
+
events.remove(c)
|
|
179
|
+
events.remove(d)
|
|
180
|
+
events.append(WatchEvent("moved", c.path, d.path, entry=c.entry))
|
|
181
|
+
break
|
|
182
|
+
|
|
183
|
+
# Update snapshot so the next scan compares against current state
|
|
184
|
+
self._snapshot = current
|
|
185
|
+
|
|
186
|
+
return events
|
|
187
|
+
|
|
188
|
+
def _filter_event(self, event: WatchEvent) -> bool:
|
|
189
|
+
"""Apply filters to event."""
|
|
190
|
+
if self._name_filter and not self._name_filter(event.path.name):
|
|
191
|
+
return False
|
|
192
|
+
return not (self._entry_filter and event.entry and not self._entry_filter(event.entry))
|
|
193
|
+
|
|
194
|
+
def _debounce_event(self, event: WatchEvent) -> bool:
|
|
195
|
+
"""Check if event should be debounced."""
|
|
196
|
+
if self._debounce_seconds <= 0:
|
|
197
|
+
return False
|
|
198
|
+
|
|
199
|
+
now = time.time()
|
|
200
|
+
key = event.path
|
|
201
|
+
|
|
202
|
+
if key in self._last_event and now - self._last_event[key] < self._debounce_seconds:
|
|
203
|
+
return True
|
|
204
|
+
|
|
205
|
+
self._last_event[key] = now
|
|
206
|
+
return False
|
|
207
|
+
|
|
208
|
+
def _dispatch(self, event: WatchEvent) -> None:
|
|
209
|
+
"""Dispatch event to appropriate callback."""
|
|
210
|
+
if self._debounce_event(event):
|
|
211
|
+
return
|
|
212
|
+
|
|
213
|
+
try:
|
|
214
|
+
if event.type == "created" and self._on_new:
|
|
215
|
+
self._on_new(event)
|
|
216
|
+
elif event.type == "modified" and self._on_modified:
|
|
217
|
+
self._on_modified(event)
|
|
218
|
+
elif event.type == "deleted" and self._on_deleted:
|
|
219
|
+
self._on_deleted(event)
|
|
220
|
+
elif event.type == "moved" and self._on_moved:
|
|
221
|
+
self._on_moved(event)
|
|
222
|
+
except Exception as e:
|
|
223
|
+
log_debug(f"Watcher callback error: {e}")
|
|
224
|
+
|
|
225
|
+
# ─── Control Methods ────────────────────────────────────────────────────
|
|
226
|
+
|
|
227
|
+
def _run_loop(self) -> None:
|
|
228
|
+
"""Main polling loop."""
|
|
229
|
+
while not self._stop_event.is_set():
|
|
230
|
+
try:
|
|
231
|
+
events = self._scan()
|
|
232
|
+
for event in events:
|
|
233
|
+
if self._filter_event(event):
|
|
234
|
+
self._dispatch(event)
|
|
235
|
+
|
|
236
|
+
# Update snapshot
|
|
237
|
+
self._snapshot = {}
|
|
238
|
+
try:
|
|
239
|
+
for entry in scan_dir(self.path):
|
|
240
|
+
self._snapshot[entry.path] = (entry.size, entry.modified.timestamp())
|
|
241
|
+
except (OSError, PermissionError):
|
|
242
|
+
pass
|
|
243
|
+
|
|
244
|
+
except Exception as e:
|
|
245
|
+
log_debug(f"Watcher scan error: {e}")
|
|
246
|
+
|
|
247
|
+
# Wait for next poll or stop
|
|
248
|
+
self._stop_event.wait(self.poll_interval)
|
|
249
|
+
|
|
250
|
+
def start(self) -> Watcher:
|
|
251
|
+
"""Start watching in background thread."""
|
|
252
|
+
if self._running:
|
|
253
|
+
return self
|
|
254
|
+
|
|
255
|
+
self._running = True
|
|
256
|
+
self._stop_event.clear()
|
|
257
|
+
self._thread = threading.Thread(target=self._run_loop, daemon=True)
|
|
258
|
+
self._thread.start()
|
|
259
|
+
return self
|
|
260
|
+
|
|
261
|
+
def stop(self) -> None:
|
|
262
|
+
"""Stop watching."""
|
|
263
|
+
self._running = False
|
|
264
|
+
self._stop_event.set()
|
|
265
|
+
if self._thread:
|
|
266
|
+
self._thread.join(timeout=2)
|
|
267
|
+
self._thread = None
|
|
268
|
+
|
|
269
|
+
def run_forever(self) -> None:
|
|
270
|
+
"""Run watcher in current thread (blocking)."""
|
|
271
|
+
self._running = True
|
|
272
|
+
self._stop_event.clear()
|
|
273
|
+
try:
|
|
274
|
+
self._run_loop()
|
|
275
|
+
except KeyboardInterrupt:
|
|
276
|
+
pass
|
|
277
|
+
finally:
|
|
278
|
+
self._running = False
|
|
279
|
+
|
|
280
|
+
def run_for(self, duration: float) -> None:
|
|
281
|
+
"""Run watcher for specified seconds."""
|
|
282
|
+
self.start()
|
|
283
|
+
time.sleep(duration)
|
|
284
|
+
self.stop()
|
|
285
|
+
|
|
286
|
+
def __enter__(self) -> Watcher:
|
|
287
|
+
self.start()
|
|
288
|
+
return self
|
|
289
|
+
|
|
290
|
+
def __exit__(
|
|
291
|
+
self,
|
|
292
|
+
exc_type: type[BaseException] | None,
|
|
293
|
+
exc_val: BaseException | None,
|
|
294
|
+
exc_tb: TracebackType | None,
|
|
295
|
+
) -> None:
|
|
296
|
+
self.stop()
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
# ──────────────────────────────────────────────────────────────────────────────
|
|
300
|
+
# CONVENIENCE FUNCTION
|
|
301
|
+
# ──────────────────────────────────────────────────────────────────────────────
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def watch(
|
|
305
|
+
path: str | Path,
|
|
306
|
+
poll_interval: float = 1.0,
|
|
307
|
+
recursive: bool = False,
|
|
308
|
+
) -> Watcher:
|
|
309
|
+
"""Create a new Watcher."""
|
|
310
|
+
return Watcher(path, poll_interval, recursive)
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pathflow-toolkit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The elegant file automation library for Python
|
|
5
|
+
Project-URL: Homepage, https://github.com/Largo-m/path_file
|
|
6
|
+
Project-URL: Documentation, https://github.com/Largo-m/path_file#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/Largo-m/path_file
|
|
8
|
+
Project-URL: Issues, https://github.com/Largo-m/path_file/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/Largo-m/path_file/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: Largo-m <Largo-m@users.noreply.github.com>
|
|
11
|
+
License: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: automation,chainable,files,filters,pathlib,shutil,sync
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: System :: Filesystems
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: black>=24.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
29
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest-xdist>=3.5; extra == 'dev'
|
|
32
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
34
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
35
|
+
Provides-Extra: trash
|
|
36
|
+
Requires-Dist: send2trash>=1.5; extra == 'trash'
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
|
|
39
|
+
# PathFile
|
|
40
|
+
|
|
41
|
+
> The elegant file automation library for Python.
|
|
42
|
+
|
|
43
|
+
[](https://pypi.org/project/path-file/)
|
|
44
|
+
[](https://pypi.org/project/path-file/)
|
|
45
|
+
[](LICENSE)
|
|
46
|
+
[](https://github.com/Largo-m/path-file/actions)
|
|
47
|
+
[](https://codecov.io/gh/Largo-m/path_file)
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Why PathFile?
|
|
52
|
+
|
|
53
|
+
Python's `pathlib` is great for single-file operations but painful for bulk operations, filtering, searching, and reporting. `shutil` has inconsistent APIs. Users end up writing 50-line scripts for tasks that should be 1 line.
|
|
54
|
+
|
|
55
|
+
**PathFile bridges this gap** with a chainable, declarative, dry-run-safe API.
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
# Before: 30 lines of pathlib + shutil + os.walk
|
|
59
|
+
# After: 1 line with path_file
|
|
60
|
+
import path_file as pf
|
|
61
|
+
|
|
62
|
+
pf.find("~/Downloads").files().with_extension(".jpg").larger_than("2MB").older_than(
|
|
63
|
+
"30 days"
|
|
64
|
+
).move_to("~/Pictures/OldLarge").execute()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Features
|
|
68
|
+
|
|
69
|
+
- 🔗 **Chainable API** - Fluent interface for complex operations
|
|
70
|
+
- 🛡️ **Dry-run by default** - Safety first for destructive operations
|
|
71
|
+
- 📦 **Zero dependencies** - Only Python standard library
|
|
72
|
+
- 🎯 **40+ filters** - Size, time, name, path, content, duplicates, permissions
|
|
73
|
+
- ⚡ **19 registered actions** - Copy, move, delete, trash, archive, extract, compress, hash, rename, touch, chmod, read/write, symlink, and more
|
|
74
|
+
- 📊 **Rich reporting** - Tables, JSON, CSV, summary statistics
|
|
75
|
+
- 🔄 **Parallel execution** - Multi-threaded with progress bars
|
|
76
|
+
- 📝 **Declarative rules** - TOML-based automation rules
|
|
77
|
+
- 👀 **Folder watching** - Polling-based file monitoring
|
|
78
|
+
- 🔁 **Directory sync** - Hash-based bidirectional synchronization
|
|
79
|
+
- 🖥️ **Full CLI** - 12 commands for terminal use
|
|
80
|
+
- 🏷️ **Full type hints** - Strict mypy compliance, IDE autocomplete
|
|
81
|
+
|
|
82
|
+
## Installation
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install path-file
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Requires **Python 3.10+**
|
|
89
|
+
|
|
90
|
+
## Quick Start
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import path_file as pf
|
|
94
|
+
|
|
95
|
+
# Find and report
|
|
96
|
+
report = pf.find("~/Documents").report()
|
|
97
|
+
print(report.to_table())
|
|
98
|
+
|
|
99
|
+
# Batch operations with safety (preview first)
|
|
100
|
+
result = pf.find("~/Downloads").files().older_than("30 days").delete(dry_run=True).execute()
|
|
101
|
+
print(result.summary())
|
|
102
|
+
|
|
103
|
+
# Actually delete (requires confirmation)
|
|
104
|
+
pf.find("~/Downloads") \
|
|
105
|
+
.files() \
|
|
106
|
+
.older_than("30 days") \
|
|
107
|
+
.delete(confirm=True) \
|
|
108
|
+
.execute()
|
|
109
|
+
|
|
110
|
+
# Organize photos by date
|
|
111
|
+
pf.find("~/Photos") \
|
|
112
|
+
.files() \
|
|
113
|
+
.with_extensions(".jpg", ".png", ".heic") \
|
|
114
|
+
.for_each(lambda e: e.path.rename(f"~/Photos/Organized/{e.modified:%Y/%m}/{e.name}"))
|
|
115
|
+
|
|
116
|
+
# Sync with verification
|
|
117
|
+
syncer = pf.sync("~/Documents", "/backup/Documents")
|
|
118
|
+
syncer.direction("source_to_dest").delete_extras(True).progress()
|
|
119
|
+
diff = syncer.compare()
|
|
120
|
+
syncer.execute()
|
|
121
|
+
|
|
122
|
+
# Declarative rules
|
|
123
|
+
rules = pf.Rules.from_file("cleanup.toml")
|
|
124
|
+
rules.apply(pf.find("~/Downloads").files())
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Documentation
|
|
128
|
+
|
|
129
|
+
- [Publishing / PyPI release checklist](PUBLISHING.md)
|
|
130
|
+
|
|
131
|
+
- [Quick Start](docs/quickstart.md)
|
|
132
|
+
- [API Reference](docs/api.md)
|
|
133
|
+
- [Recipes](docs/recipes.md)
|
|
134
|
+
- [Rules Engine](docs/rules.md)
|
|
135
|
+
- [CLI Reference](docs/cli.md)
|
|
136
|
+
|
|
137
|
+
## CLI Usage
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Find files
|
|
141
|
+
path-file find ~/Downloads --ext .jpg --larger 2MB
|
|
142
|
+
|
|
143
|
+
# Generate report
|
|
144
|
+
path-file report ~/Documents --json
|
|
145
|
+
|
|
146
|
+
# Copy with progress
|
|
147
|
+
path-file copy ~/Photos /backup/Photos --ext .jpg --parallel 4
|
|
148
|
+
|
|
149
|
+
# Safe delete (requires --confirm)
|
|
150
|
+
path-file delete ~/Temp --ext .tmp --confirm
|
|
151
|
+
|
|
152
|
+
# Sync directories
|
|
153
|
+
path-file sync ~/Documents /backup/Documents --delete-extras --dry-run
|
|
154
|
+
|
|
155
|
+
# Find duplicates
|
|
156
|
+
path-file duplicates ~/Photos
|
|
157
|
+
|
|
158
|
+
# Archive
|
|
159
|
+
path-file archive ~/Projects -o backup.zip
|
|
160
|
+
|
|
161
|
+
# Watch folder
|
|
162
|
+
path-file watch ~/Downloads --filter "*.pdf" --on-new "notify.sh {}"
|
|
163
|
+
|
|
164
|
+
# Apply rules
|
|
165
|
+
path-file rules ~/Downloads -f cleanup.toml --apply
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Comparison
|
|
169
|
+
|
|
170
|
+
| Feature | pathlib | shutil | path_file |
|
|
171
|
+
|---------|---------|--------|----------|
|
|
172
|
+
| Chainable API | ❌ | ❌ | ✅ |
|
|
173
|
+
| Bulk filtering | Manual | Limited | ✅ 40+ filters |
|
|
174
|
+
| Dry-run safety | Manual | ❌ | ✅ Default |
|
|
175
|
+
| Progress bars | ❌ | ❌ | ✅ Built-in |
|
|
176
|
+
| Parallel execution | Manual | ❌ | ✅ Built-in |
|
|
177
|
+
| Content search | Manual | ❌ | ✅ Text & regex |
|
|
178
|
+
| Duplicate detection | Manual | ❌ | ✅ By hash/name |
|
|
179
|
+
| Declarative rules | ❌ | ❌ | ✅ TOML |
|
|
180
|
+
| Folder watching | ❌ | ❌ | ✅ Polling |
|
|
181
|
+
| Directory sync | ❌ | Manual | ✅ Hash-based |
|
|
182
|
+
| CLI | ❌ | ❌ | ✅ 12 commands |
|
|
183
|
+
| Zero dependencies | ✅ | ✅ | ✅ |
|
|
184
|
+
| Type hints | ✅ | Partial | ✅ Strict |
|
|
185
|
+
|
|
186
|
+
## Examples
|
|
187
|
+
|
|
188
|
+
See [examples/](examples/) for 10 real-world scripts:
|
|
189
|
+
|
|
190
|
+
1. `01_clean_downloads.py` - Clean old downloads
|
|
191
|
+
2. `02_organize_photos.py` - Organize photos by date
|
|
192
|
+
3. `03_backup_documents.py` - Backup with hash verification
|
|
193
|
+
4. `04_find_duplicates.py` - Find and report duplicates
|
|
194
|
+
5. `05_watch_and_sort.py` - Auto-sort downloads
|
|
195
|
+
6. `06_sync_folders.py` - Bidirectional sync
|
|
196
|
+
7. `07_rules_declarative.py` - Rules-based cleanup
|
|
197
|
+
8. `08_compress_old_files.py` - Compress old files
|
|
198
|
+
9. `09_rename_batch.py` - Batch rename photos
|
|
199
|
+
10. `10_report_audit.py` - Generate audit reports
|
|
200
|
+
|
|
201
|
+
## Contributing
|
|
202
|
+
|
|
203
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
208
|
+
|
|
209
|
+
## Security
|
|
210
|
+
|
|
211
|
+
See [SECURITY.md](SECURITY.md) for security policy and vulnerability reporting.
|
|
212
|
+
|
|
213
|
+
## Changelog
|
|
214
|
+
|
|
215
|
+
See [CHANGELOG.md](CHANGELOG.md) for release history.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
Made with ❤️ by [Largo-m](https://github.com/Largo-m)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
path_file/__init__.py,sha256=qdlhbZZc0hvRp7TRxrim52-jrOEzP4sAYkz3_kHKM0g,6264
|
|
2
|
+
path_file/__main__.py,sha256=kLTIK-rI2bOie5kM8RCE9MGWuFaoafrkIB7E_kRuchY,134
|
|
3
|
+
path_file/_version.py,sha256=QTYqXqSTHFRkM9TEgpDFcHvwLbvqHDqvqfQ9EiXkcAM,23
|
|
4
|
+
path_file/actions.py,sha256=HlfdT7yHMcowsWSoLhc0gei4aYsvzXg-RlGfYvuHrSc,26723
|
|
5
|
+
path_file/archive.py,sha256=znRypc0bqM0qecgo4xrif0RU9r5qQbWqcm9QQ-ozm1E,15376
|
|
6
|
+
path_file/chain.py,sha256=jgfk8zy0H1j2JXzLM41FuwaaKRF2ZSe4ng3M-EQJE90,40003
|
|
7
|
+
path_file/cli.py,sha256=yrSF5k1PAzEFs5ANXf30coEy1Ujo5Sk7I7dRoxGbxJg,22882
|
|
8
|
+
path_file/entries.py,sha256=0ChoAgWP_9Mo2s-TaIHB5hoz1aPFbUbG_wKpWPqVanY,18317
|
|
9
|
+
path_file/exceptions.py,sha256=0ZlFcW_K6Gn7EKPK-2VwaUS98Uh6DwXuY2TkTIlG-XY,6467
|
|
10
|
+
path_file/filters.py,sha256=qXn9Czyqz5eAA_7z7fiMeXBw-5PjViKdWsqIgkHhJv0,21831
|
|
11
|
+
path_file/hash.py,sha256=fWJDtAcgwjAUBpsAb1CyASLCzWqTKDDIGLb2nSW-yFs,11492
|
|
12
|
+
path_file/progress.py,sha256=khVWvRRHHfwefO5GvHjJhMQ4Msorv0Iz55KoVjyIUOc,11904
|
|
13
|
+
path_file/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
path_file/report.py,sha256=wCu2ls-ul0cTtYcnFqxVuGnPYFzDSZUaq0x6KAsDZBU,14399
|
|
15
|
+
path_file/rules.py,sha256=lfGtL633d8aYjR5I2bzgybAu-XndAhkt9BPF3bUf8rc,18482
|
|
16
|
+
path_file/search.py,sha256=hOoKZXecv-XPBAo82lsSaU29HnCCfLLaJM9DvlgMvkY,12828
|
|
17
|
+
path_file/sync.py,sha256=uY-6ic9n5eYHRMMaVipRi_sy4QDToBZrC1C68h_SFk0,14682
|
|
18
|
+
path_file/units.py,sha256=Qx6R8-8lMAUNEf5-3XNYDjdslgL4GrcjHbzORxF2PIU,12101
|
|
19
|
+
path_file/utils.py,sha256=WrNX6zyflsrxcWmVdPaP6xJvceTTAIe40Xvd43DRJxw,17240
|
|
20
|
+
path_file/watch.py,sha256=tqUimFz6aU75LkrHFN7vxy7P4m2Lbjwrx4zIzKv244s,11576
|
|
21
|
+
path_file/_internal/__init__.py,sha256=RbX0pU5ZZMnf491ACfw59IeO6OuM_bxrKqPa2s-YNu0,1658
|
|
22
|
+
path_file/_internal/_iterators.py,sha256=PXduQM9i05Iw5-Z3HCstR0cf31s8pD4FsRvnCxlxOcY,13719
|
|
23
|
+
path_file/_internal/_log.py,sha256=I1-rwGPTapiGRYkXYfBAmTGOJleZ1nrsikTp0tFzfko,4741
|
|
24
|
+
path_file/_internal/_parsers.py,sha256=_vzyUWbQajdhWoIJJH3dk8d34nHkP5cdj3eLu51qbbw,9876
|
|
25
|
+
path_file/_internal/_safety.py,sha256=YE6TsP4jEx6XMZR-HtEgVXvFhwhy_r84GGrB8l-eC_U,8760
|
|
26
|
+
pathflow_toolkit-0.1.0.dist-info/METADATA,sha256=rlZHvzFPnD4J9oXrX9AnqHNZI92iuftS2pGdkUQ9M_8,7287
|
|
27
|
+
pathflow_toolkit-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
28
|
+
pathflow_toolkit-0.1.0.dist-info/entry_points.txt,sha256=4YiEriIn94y3L_jQ2nHhPgIOPAzePgulSAjWIYmMjCE,49
|
|
29
|
+
pathflow_toolkit-0.1.0.dist-info/licenses/LICENSE,sha256=BzmuG7iC75LpE5YpShs2G0chkWIXRa4KZueGbyc8v5E,1068
|
|
30
|
+
pathflow_toolkit-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Largo-m
|
|
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.
|