filesweep-cli 3.0.0__tar.gz

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.
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Emmanuelaudu
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.
22
+
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.4
2
+ Name: filesweep-cli
3
+ Version: 3.0.0
4
+ Summary: Safe, reversible Windows command-line file organiser.
5
+ Author: Emmanuelaudu
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Joshemmy/sweep-cli
8
+ Project-URL: Repository, https://github.com/Joshemmy/sweep-cli
9
+ Project-URL: Issues, https://github.com/Joshemmy/sweep-cli/issues
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Environment :: Console
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Utilities
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Dynamic: license-file
22
+
23
+ # Sweep
24
+
25
+ A safe, reversible Windows command-line file organiser built purely with the Python 3.11+ standard library.
26
+
27
+ <!-- ![Sweep demo](https://raw.githubusercontent.com/Joshemmy/sweep-cli/main/assets/demo.gif) -->
28
+
29
+ Sweep tidies loose top-level files in your user folders without deleting or overwriting anything. Every run previews the exact move plan first (dry-run by default), records every intent in a write-ahead undo log before moving files, and reverses any run with a single command.
30
+
31
+ ## Key Principles
32
+
33
+ * **Dry-run by default:** CLI runs are strictly read-only unless `--apply` is passed explicitly.
34
+ * **Write-ahead undo log:** Each planned move is recorded atomically as `pending` in `%USERPROFILE%\.sweep\logs\<run_id>.json` before `shutil.move` runs, then updated to `committed`, `skipped`, or `failed` for reliable crash recovery.
35
+ * **Zero deletions or overwrites:** Sweep never deletes files or folders. Existing destination filenames trigger Windows-style numbering (`report (1).pdf`, `report (2).pdf`).
36
+ * **Zero third-party dependencies:** Runs using Python's built-in modules only.
37
+
38
+ ## Requirements
39
+
40
+ * Windows 10 or Windows 11
41
+ * Python 3.11 or newer (zero third-party runtime dependencies)
42
+
43
+ ## Installation
44
+
45
+ Install the `sweep` command globally from PyPI:
46
+
47
+ ```powershell
48
+ pip install filesweep-cli
49
+ ```
50
+
51
+ To upgrade an existing installation:
52
+
53
+ ```powershell
54
+ pip install --upgrade filesweep-cli
55
+ ```
56
+
57
+ From a local clone, you can also run `python sweep.py` directly or install in editable mode with `pip install -e .` (which loads `rules.json` from the repository directory).
58
+
59
+ ## Quick Start
60
+
61
+ Run `sweep` from any folder (or `python sweep.py` from the repository root):
62
+
63
+ ```powershell
64
+ # Launch the interactive menu (when run with no arguments in a terminal)
65
+ sweep
66
+
67
+ # Preview planned moves without modifying disk (dry-run)
68
+ sweep --target "%USERPROFILE%\Downloads"
69
+
70
+ # Apply planned moves across default targets (Downloads, Desktop, Documents)
71
+ sweep --apply
72
+
73
+ # Preview or apply with opt-in kebab-case filename and folder normalisation
74
+ sweep --kebab --target "%USERPROFILE%\Downloads"
75
+ sweep --kebab --apply
76
+
77
+ # Preview or apply in-place kebab-case renaming without moving into category folders
78
+ sweep --rename-only --target "%USERPROFILE%\Downloads" --target "%USERPROFILE%\Desktop"
79
+ sweep --rename-only --rename-folders --target "%USERPROFILE%\Projects" --apply
80
+
81
+ # Target specific folders (repeatable) and optionally override rules or log paths
82
+ sweep --target "%USERPROFILE%\Downloads" --target "%USERPROFILE%\Desktop" --rules rules.json --log-dir "%USERPROFILE%\.sweep\logs" --apply
83
+
84
+ # List recent runs, preview a rollback, undo the most recent run, or reverse a specific run ID
85
+ sweep undo --list
86
+ sweep undo --dry-run
87
+ sweep undo
88
+ sweep undo --run 20260101T120000Z_ab12cd34
89
+
90
+ # Show the installed Sweep version
91
+ sweep --version
92
+ ```
93
+
94
+ ### Interactive Mode
95
+
96
+ Running `sweep` (or `python sweep.py`) with no arguments in an interactive terminal runs an immediate read-only scan and displays a compact dashboard (target folders, scan summary, top extensions, any smart file groups spotted, and the active naming mode, which defaults to `Original names (kebab-case: OFF)`), followed by a 6-option menu:
97
+
98
+ 1. Guided sort (review groups, preview plan, then apply)
99
+ 2. Switch folder (`Downloads`, `Desktop`, `Documents`, all defaults, or a custom path)
100
+ 3. Toggle kebab-case naming (currently OFF/ON; opt-in, defaults to OFF)
101
+ 4. Undo a previous run (list the 10 most recent runs with status, relative time, action summary, and target folder, preview up to 5 items to restore, then confirm)
102
+ 5. Batch rename files or folders (kebab-case) (pick one or more folders, choose files only, subfolders only, or folders and files inside them, preview plan, then confirm)
103
+ 6. Exit
104
+
105
+ Redirected or piped output (`sweep > plan.txt`) automatically bypasses interactive mode and prints the read-only dry-run table.
106
+
107
+ ### CLI Options
108
+
109
+ | Command / Flag | Description | Default |
110
+ |---|---|---|
111
+ | `--version` | Show the Sweep version and exit | - |
112
+ | `--apply` | Execute planned moves or renames | Dry-run only |
113
+ | `--kebab` | Normalise destination filenames and auto-created category/cluster folders to lowercase kebab-case when sorting | Off (preserve original names and Title Case folders) |
114
+ | `--rename-only` | Rename eligible loose files in place to lowercase kebab-case without moving into category folders | Off (sort into folders) |
115
+ | `--rename-folders` | Opt-in: rename safe top-level subfolders (and eligible files inside them when combined with `--rename-only`) to lowercase kebab-case | Off (never rename folders) |
116
+ | `--target <path>` | Target folder to scan (repeatable) | `Downloads`, `Desktop`, `Documents` |
117
+ | `--rules <path>` | Path to `rules.json` | `rules.json` alongside `sweep.py` |
118
+ | `--log-dir <path>` | Directory for write-ahead undo logs | `%USERPROFILE%\.sweep\logs` |
119
+ | `undo` | Reverse the latest non-undone run | Latest active log |
120
+ | `undo --run <id>` | Reverse a specific logged run ID | Latest active log |
121
+ | `undo --list` | Display up to 10 recent logged runs with status, timestamp, action summary, and target folder | - |
122
+ | `undo --dry-run` | Preview items that would be restored for the selected run without modifying disk | - |
123
+
124
+ ## Smart Sorting
125
+
126
+ Sweep evaluates eligible loose files in four ordered stages:
127
+
128
+ 1. **Title rules (`title_rules`):** Keywords in `rules.json` are matched first against filename stems using word-boundary patterns, routing matching files into named buckets (such as `Receipts`, `Presentations`, `Transcripts`, or `Diagrams`) before other checks run.
129
+ 2. **Existing-folder matching:** Scans safe top-level subfolders in the target folder (ignoring hidden/dot folders, system folders, generic fallback categories from `rules.json`, project-marker folders, and short or vague names such as `new`, `work`, `misc`, `temp`, `files`, `folder`, `stuff`, `final`). A loose file matches an existing folder only when all meaningful tokens of that folder appear in the filename stem, picking the unique most-specific match (leaving ties unmatched) while preserving the existing folder's exact on-disk name.
130
+ 3. **Auto-discovered file groups (in Guided sort, option `1`):** Inspects remaining eligible `planned` filenames (never skipped files, title-rule matches, existing-folder matches, or file contents), strips noise words (stopwords, media tags, versions, months, short titles, and standalone numbers), and surfaces non-overlapping 1- or 2-token groups of 3 or more files within the same target folder. Approved groups apply to the current run and can optionally be saved to `rules.json`.
131
+ 4. **Extension rules (`rules`):** Remaining files are sorted in order into `Documents`, `Images`, `Video`, `Audio`, `Archives`, `Installers`, or `Other` (`*`).
132
+
133
+ ## Built-in Safety Guards
134
+
135
+ * **Top-level loose files by default:** Scans only the top level of target folders. Folder renaming is strictly opt-in (`--rename-folders` or interactive option `5`). When combined with `--rename-only` (or interactive scope `c`), Sweep also renames eligible files directly inside safe top-level subfolders (applying inner-file renames before parent-folder renames so WAL undo reverses them cleanly) without recursing deeper or following symbolic links.
136
+ * **Protected system paths:** Blocks `C:\Windows`, `Program Files`, `Program Files (x86)`, and `AppData` (subdirectories under `%TEMP%` are permitted only when explicitly targeted for sandboxing).
137
+ * **Excluded file types:** Always skips `.lnk`, `.url`, `.ini`, `.rdp`, `.key`, and `.pem` files.
138
+ * **Partial downloads:** Skips `.crdownload`, `.part`, `.tmp`, and `.opdownload` files.
139
+ * **Temporary Office files:** Skips lock/temp files whose names begin with `~$`.
140
+ * **24-hour safety buffer:** Skips files modified within the last 24 hours.
141
+ * **Locked files and folders:** Checks sharing access via `CreateFileW` and skips locked items (as well as folders or rename-mode files that raise `PermissionError` during rename) without crashing.
142
+ * **OneDrive cloud placeholders:** Checks `FILE_ATTRIBUTE_OFFLINE` and `FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS` via `GetFileAttributesW` before opening handles, avoiding unwanted cloud hydration.
143
+ * **Project-safe mode and folder guards:** Skips loose files in any target folder that directly contains `.git`, `pyproject.toml`, `package.json`, `.blend`, `.aep`, or `.prproj`. In `--rename-folders` mode, also skips hidden/dot folders (starting with `.`), cloud-sync root folders (`OneDrive`, `OneDrive - ...`, `Dropbox`, `Google Drive`, `iCloudDrive`), and subfolders containing `.git`, `package.json`, `pyproject.toml`, `requirements.txt`, `.venv`, or `venv`.
144
+ * **Safe folder names and collision numbering:** Rejects Windows reserved device names (`CON`, `PRN`, `AUX`, `NUL`, `COM1`-`COM9`, `LPT1`-`LPT9`), illegal NTFS characters, and leading or trailing dots/spaces. Keeps original names untouched if kebab-case normalisation yields an empty string or reserved name, and resolves collisions using Windows-style numbering (`(1)`, `(2)`).
145
+
146
+ ## Customising `rules.json`
147
+
148
+ Edit [rules.json](rules.json) to adjust sorting without changing Python code:
149
+
150
+ * `title_rules`: Ordered list of `{"bucket": "<FolderName>", "keywords": ["..."]}` entries evaluated first against filename stems (multi-word keywords match across spaces, hyphens, and underscores).
151
+ * `rules`: Ordered list of `{"category": "<FolderName>", "extensions": [".ext", ...]}` entries evaluated when no title rule matches, ending with `"*"` as a catch-all.
152
+
153
+ ## Running the Test Suite
154
+
155
+ All automated tests run inside isolated temporary directories and never touch your real user folders:
156
+
157
+ ```powershell
158
+ python -m unittest discover -s tests -v
159
+ ```
160
+
161
+ ## Project Layout
162
+
163
+ ```text
164
+ filesweep-cli/
165
+ ├── LICENSE
166
+ ├── README.md
167
+ ├── clustering.py
168
+ ├── pyproject.toml
169
+ ├── rules.json
170
+ ├── sweep.py
171
+ └── tests/
172
+ └── test_sweep.py
173
+ ```
@@ -0,0 +1,151 @@
1
+ # Sweep
2
+
3
+ A safe, reversible Windows command-line file organiser built purely with the Python 3.11+ standard library.
4
+
5
+ <!-- ![Sweep demo](https://raw.githubusercontent.com/Joshemmy/sweep-cli/main/assets/demo.gif) -->
6
+
7
+ Sweep tidies loose top-level files in your user folders without deleting or overwriting anything. Every run previews the exact move plan first (dry-run by default), records every intent in a write-ahead undo log before moving files, and reverses any run with a single command.
8
+
9
+ ## Key Principles
10
+
11
+ * **Dry-run by default:** CLI runs are strictly read-only unless `--apply` is passed explicitly.
12
+ * **Write-ahead undo log:** Each planned move is recorded atomically as `pending` in `%USERPROFILE%\.sweep\logs\<run_id>.json` before `shutil.move` runs, then updated to `committed`, `skipped`, or `failed` for reliable crash recovery.
13
+ * **Zero deletions or overwrites:** Sweep never deletes files or folders. Existing destination filenames trigger Windows-style numbering (`report (1).pdf`, `report (2).pdf`).
14
+ * **Zero third-party dependencies:** Runs using Python's built-in modules only.
15
+
16
+ ## Requirements
17
+
18
+ * Windows 10 or Windows 11
19
+ * Python 3.11 or newer (zero third-party runtime dependencies)
20
+
21
+ ## Installation
22
+
23
+ Install the `sweep` command globally from PyPI:
24
+
25
+ ```powershell
26
+ pip install filesweep-cli
27
+ ```
28
+
29
+ To upgrade an existing installation:
30
+
31
+ ```powershell
32
+ pip install --upgrade filesweep-cli
33
+ ```
34
+
35
+ From a local clone, you can also run `python sweep.py` directly or install in editable mode with `pip install -e .` (which loads `rules.json` from the repository directory).
36
+
37
+ ## Quick Start
38
+
39
+ Run `sweep` from any folder (or `python sweep.py` from the repository root):
40
+
41
+ ```powershell
42
+ # Launch the interactive menu (when run with no arguments in a terminal)
43
+ sweep
44
+
45
+ # Preview planned moves without modifying disk (dry-run)
46
+ sweep --target "%USERPROFILE%\Downloads"
47
+
48
+ # Apply planned moves across default targets (Downloads, Desktop, Documents)
49
+ sweep --apply
50
+
51
+ # Preview or apply with opt-in kebab-case filename and folder normalisation
52
+ sweep --kebab --target "%USERPROFILE%\Downloads"
53
+ sweep --kebab --apply
54
+
55
+ # Preview or apply in-place kebab-case renaming without moving into category folders
56
+ sweep --rename-only --target "%USERPROFILE%\Downloads" --target "%USERPROFILE%\Desktop"
57
+ sweep --rename-only --rename-folders --target "%USERPROFILE%\Projects" --apply
58
+
59
+ # Target specific folders (repeatable) and optionally override rules or log paths
60
+ sweep --target "%USERPROFILE%\Downloads" --target "%USERPROFILE%\Desktop" --rules rules.json --log-dir "%USERPROFILE%\.sweep\logs" --apply
61
+
62
+ # List recent runs, preview a rollback, undo the most recent run, or reverse a specific run ID
63
+ sweep undo --list
64
+ sweep undo --dry-run
65
+ sweep undo
66
+ sweep undo --run 20260101T120000Z_ab12cd34
67
+
68
+ # Show the installed Sweep version
69
+ sweep --version
70
+ ```
71
+
72
+ ### Interactive Mode
73
+
74
+ Running `sweep` (or `python sweep.py`) with no arguments in an interactive terminal runs an immediate read-only scan and displays a compact dashboard (target folders, scan summary, top extensions, any smart file groups spotted, and the active naming mode, which defaults to `Original names (kebab-case: OFF)`), followed by a 6-option menu:
75
+
76
+ 1. Guided sort (review groups, preview plan, then apply)
77
+ 2. Switch folder (`Downloads`, `Desktop`, `Documents`, all defaults, or a custom path)
78
+ 3. Toggle kebab-case naming (currently OFF/ON; opt-in, defaults to OFF)
79
+ 4. Undo a previous run (list the 10 most recent runs with status, relative time, action summary, and target folder, preview up to 5 items to restore, then confirm)
80
+ 5. Batch rename files or folders (kebab-case) (pick one or more folders, choose files only, subfolders only, or folders and files inside them, preview plan, then confirm)
81
+ 6. Exit
82
+
83
+ Redirected or piped output (`sweep > plan.txt`) automatically bypasses interactive mode and prints the read-only dry-run table.
84
+
85
+ ### CLI Options
86
+
87
+ | Command / Flag | Description | Default |
88
+ |---|---|---|
89
+ | `--version` | Show the Sweep version and exit | - |
90
+ | `--apply` | Execute planned moves or renames | Dry-run only |
91
+ | `--kebab` | Normalise destination filenames and auto-created category/cluster folders to lowercase kebab-case when sorting | Off (preserve original names and Title Case folders) |
92
+ | `--rename-only` | Rename eligible loose files in place to lowercase kebab-case without moving into category folders | Off (sort into folders) |
93
+ | `--rename-folders` | Opt-in: rename safe top-level subfolders (and eligible files inside them when combined with `--rename-only`) to lowercase kebab-case | Off (never rename folders) |
94
+ | `--target <path>` | Target folder to scan (repeatable) | `Downloads`, `Desktop`, `Documents` |
95
+ | `--rules <path>` | Path to `rules.json` | `rules.json` alongside `sweep.py` |
96
+ | `--log-dir <path>` | Directory for write-ahead undo logs | `%USERPROFILE%\.sweep\logs` |
97
+ | `undo` | Reverse the latest non-undone run | Latest active log |
98
+ | `undo --run <id>` | Reverse a specific logged run ID | Latest active log |
99
+ | `undo --list` | Display up to 10 recent logged runs with status, timestamp, action summary, and target folder | - |
100
+ | `undo --dry-run` | Preview items that would be restored for the selected run without modifying disk | - |
101
+
102
+ ## Smart Sorting
103
+
104
+ Sweep evaluates eligible loose files in four ordered stages:
105
+
106
+ 1. **Title rules (`title_rules`):** Keywords in `rules.json` are matched first against filename stems using word-boundary patterns, routing matching files into named buckets (such as `Receipts`, `Presentations`, `Transcripts`, or `Diagrams`) before other checks run.
107
+ 2. **Existing-folder matching:** Scans safe top-level subfolders in the target folder (ignoring hidden/dot folders, system folders, generic fallback categories from `rules.json`, project-marker folders, and short or vague names such as `new`, `work`, `misc`, `temp`, `files`, `folder`, `stuff`, `final`). A loose file matches an existing folder only when all meaningful tokens of that folder appear in the filename stem, picking the unique most-specific match (leaving ties unmatched) while preserving the existing folder's exact on-disk name.
108
+ 3. **Auto-discovered file groups (in Guided sort, option `1`):** Inspects remaining eligible `planned` filenames (never skipped files, title-rule matches, existing-folder matches, or file contents), strips noise words (stopwords, media tags, versions, months, short titles, and standalone numbers), and surfaces non-overlapping 1- or 2-token groups of 3 or more files within the same target folder. Approved groups apply to the current run and can optionally be saved to `rules.json`.
109
+ 4. **Extension rules (`rules`):** Remaining files are sorted in order into `Documents`, `Images`, `Video`, `Audio`, `Archives`, `Installers`, or `Other` (`*`).
110
+
111
+ ## Built-in Safety Guards
112
+
113
+ * **Top-level loose files by default:** Scans only the top level of target folders. Folder renaming is strictly opt-in (`--rename-folders` or interactive option `5`). When combined with `--rename-only` (or interactive scope `c`), Sweep also renames eligible files directly inside safe top-level subfolders (applying inner-file renames before parent-folder renames so WAL undo reverses them cleanly) without recursing deeper or following symbolic links.
114
+ * **Protected system paths:** Blocks `C:\Windows`, `Program Files`, `Program Files (x86)`, and `AppData` (subdirectories under `%TEMP%` are permitted only when explicitly targeted for sandboxing).
115
+ * **Excluded file types:** Always skips `.lnk`, `.url`, `.ini`, `.rdp`, `.key`, and `.pem` files.
116
+ * **Partial downloads:** Skips `.crdownload`, `.part`, `.tmp`, and `.opdownload` files.
117
+ * **Temporary Office files:** Skips lock/temp files whose names begin with `~$`.
118
+ * **24-hour safety buffer:** Skips files modified within the last 24 hours.
119
+ * **Locked files and folders:** Checks sharing access via `CreateFileW` and skips locked items (as well as folders or rename-mode files that raise `PermissionError` during rename) without crashing.
120
+ * **OneDrive cloud placeholders:** Checks `FILE_ATTRIBUTE_OFFLINE` and `FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS` via `GetFileAttributesW` before opening handles, avoiding unwanted cloud hydration.
121
+ * **Project-safe mode and folder guards:** Skips loose files in any target folder that directly contains `.git`, `pyproject.toml`, `package.json`, `.blend`, `.aep`, or `.prproj`. In `--rename-folders` mode, also skips hidden/dot folders (starting with `.`), cloud-sync root folders (`OneDrive`, `OneDrive - ...`, `Dropbox`, `Google Drive`, `iCloudDrive`), and subfolders containing `.git`, `package.json`, `pyproject.toml`, `requirements.txt`, `.venv`, or `venv`.
122
+ * **Safe folder names and collision numbering:** Rejects Windows reserved device names (`CON`, `PRN`, `AUX`, `NUL`, `COM1`-`COM9`, `LPT1`-`LPT9`), illegal NTFS characters, and leading or trailing dots/spaces. Keeps original names untouched if kebab-case normalisation yields an empty string or reserved name, and resolves collisions using Windows-style numbering (`(1)`, `(2)`).
123
+
124
+ ## Customising `rules.json`
125
+
126
+ Edit [rules.json](rules.json) to adjust sorting without changing Python code:
127
+
128
+ * `title_rules`: Ordered list of `{"bucket": "<FolderName>", "keywords": ["..."]}` entries evaluated first against filename stems (multi-word keywords match across spaces, hyphens, and underscores).
129
+ * `rules`: Ordered list of `{"category": "<FolderName>", "extensions": [".ext", ...]}` entries evaluated when no title rule matches, ending with `"*"` as a catch-all.
130
+
131
+ ## Running the Test Suite
132
+
133
+ All automated tests run inside isolated temporary directories and never touch your real user folders:
134
+
135
+ ```powershell
136
+ python -m unittest discover -s tests -v
137
+ ```
138
+
139
+ ## Project Layout
140
+
141
+ ```text
142
+ filesweep-cli/
143
+ ├── LICENSE
144
+ ├── README.md
145
+ ├── clustering.py
146
+ ├── pyproject.toml
147
+ ├── rules.json
148
+ ├── sweep.py
149
+ └── tests/
150
+ └── test_sweep.py
151
+ ```