thanos-cli 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.
thanos_cli/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ """Top-level package for thanos_cli."""
2
+
3
+ __author__ = """Soldatov Serhii"""
4
+ __email__ = "soldatov.own@gmail.com"
thanos_cli/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .cli import app
2
+
3
+ if __name__ == "__main__":
4
+ app()
thanos_cli/cli.py ADDED
@@ -0,0 +1,126 @@
1
+ """Console script for thanos_cli."""
2
+
3
+ import random
4
+ from typing import Annotated, Optional
5
+
6
+ import typer
7
+ from rich.console import Console
8
+
9
+ from .utils import get_files
10
+
11
+ app = typer.Typer(
12
+ name="thanos",
13
+ help="๐Ÿซฐ Thanos - Eliminate half of all files with a snap. Perfectly balanced, as all things should be.",
14
+ add_completion=False,
15
+ )
16
+ console = Console()
17
+
18
+
19
+ def snap(directory: str = ".", recursive: bool = False, dry_run: bool = False):
20
+ """
21
+ The Snap - Eliminates half of all files randomly.
22
+
23
+ Args:
24
+ directory: Target directory (default: current directory)
25
+ recursive: Include subdirectories
26
+ dry_run: Show what would be deleted without actually deleting
27
+ """
28
+ print("๐Ÿซฐ Initiating the Snap...")
29
+
30
+ files = get_files(directory, recursive)
31
+ total_files = len(files)
32
+
33
+ if total_files == 0:
34
+ print("No files found. The universe is empty.")
35
+ return
36
+
37
+ # Calculate how many files to eliminate
38
+ files_to_eliminate = total_files // 2
39
+
40
+ # Randomly select files for elimination
41
+ eliminated = random.sample(files, files_to_eliminate)
42
+
43
+ print("\n๐Ÿ“Š Balance Assessment:")
44
+ print(f" Total files: {total_files}")
45
+ print(f" Files to eliminate: {files_to_eliminate}")
46
+ print(f" Survivors: {total_files - files_to_eliminate}")
47
+
48
+ if dry_run:
49
+ print("\n๐Ÿ” DRY RUN - These files would be eliminated:")
50
+ for file in eliminated:
51
+ print(f" ๐Ÿ’€ {file}")
52
+ print("\nโš ๏ธ This was a dry run. No files were harmed.")
53
+ return
54
+
55
+ # Confirm before destruction
56
+ print("\nโš ๏ธ WARNING: This will permanently delete files!")
57
+ confirm = input("Type 'snap' to proceed: ")
58
+
59
+ if confirm.lower() != "snap":
60
+ print("Snap cancelled. The universe remains unchanged.")
61
+ return
62
+
63
+ # Execute the snap
64
+ print("\n๐Ÿ’ฅ Snapping...")
65
+ eliminated_count = 0
66
+
67
+ for file in eliminated:
68
+ try:
69
+ file.unlink()
70
+ eliminated_count += 1
71
+ print(f" ๐Ÿ’€ {file}")
72
+ except Exception as e:
73
+ print(f" โŒ Failed to eliminate {file}: {e}")
74
+
75
+ print("\nโœจ The snap is complete.")
76
+ print(f" {eliminated_count} files eliminated.")
77
+ print(" Perfectly balanced, as all things should be.")
78
+
79
+
80
+ @app.command()
81
+ def main(
82
+ directory: Annotated[
83
+ Optional[str],
84
+ typer.Argument(
85
+ help="Target directory to snap (default: current directory)",
86
+ show_default=False,
87
+ ),
88
+ ] = ".",
89
+ recursive: Annotated[
90
+ bool, typer.Option("--recursive", "-r", help="Include files in subdirectories recursively")
91
+ ] = False,
92
+ dry_run: Annotated[
93
+ bool, typer.Option("--dry-run", "-d", help="Preview what would be deleted without actually deleting")
94
+ ] = False,
95
+ ):
96
+ """
97
+ ๐Ÿซฐ Eliminate half of all files in a directory with a snap.
98
+
99
+ Thanos randomly selects and deletes exactly half of the files in the specified
100
+ directory. Use with caution - deleted files cannot be recovered!
101
+
102
+ Examples:
103
+
104
+ # Snap current directory (dry run first!)
105
+ $ thanos --dry-run
106
+
107
+ # Snap a specific directory
108
+ $ thanos /path/to/directory
109
+
110
+ # Include subdirectories recursively
111
+ $ thanos --recursive
112
+
113
+ # Snap a directory and its subdirectories
114
+ $ thanos /path/to/directory --recursive
115
+ """
116
+ try:
117
+ snap(directory, recursive, dry_run)
118
+ except Exception as e:
119
+ print(f"โŒ Error: {e}")
120
+ return 1
121
+
122
+ return 0
123
+
124
+
125
+ if __name__ == "__main__":
126
+ app()
thanos_cli/utils.py ADDED
@@ -0,0 +1,19 @@
1
+ from pathlib import Path
2
+
3
+
4
+ def get_files(directory: str, recursive: bool = False) -> list[Path]:
5
+ """Get all files in the directory."""
6
+ path = Path(directory)
7
+
8
+ if not path.exists():
9
+ raise FileNotFoundError(f"Directory '{directory}' does not exist")
10
+
11
+ if not path.is_dir():
12
+ raise NotADirectoryError(f"'{directory}' is not a directory")
13
+
14
+ if recursive:
15
+ files = [f for f in path.rglob("*") if f.is_file()]
16
+ else:
17
+ files = [f for f in path.iterdir() if f.is_file()]
18
+
19
+ return files
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.4
2
+ Name: thanos-cli
3
+ Version: 0.1.0
4
+ Summary: ๐Ÿซฐ Thanos - Eliminate half of all files with a snap. Perfectly balanced, as all things should be.
5
+ Project-URL: homepage, https://github.com/soldatov-ss/thanos
6
+ Project-URL: bugs, https://github.com/soldatov-ss/thanos/issues
7
+ Project-URL: changelog, https://github.com/soldatov-ss/thanos/blob/master/CHANGELOG.md
8
+ Project-URL: documentation, https://github.com/soldatov-ss/thanos/blob/master/docs/usage.md
9
+ Author-email: Soldatov Serhii <soldatov.own@gmail.com>
10
+ Maintainer-email: Soldatov Serhii <soldatov.own@gmail.com>
11
+ License: MIT
12
+ License-File: LICENSE
13
+ Keywords: cleanup,cli,files,thanos,utility
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: System Administrators
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
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: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: System :: Filesystems
26
+ Classifier: Topic :: Utilities
27
+ Classifier: Typing :: Typed
28
+ Requires-Python: >=3.9
29
+ Requires-Dist: typer
30
+ Provides-Extra: test
31
+ Requires-Dist: coverage; extra == 'test'
32
+ Requires-Dist: ipdb; extra == 'test'
33
+ Requires-Dist: pytest; extra == 'test'
34
+ Requires-Dist: ruff; extra == 'test'
35
+ Requires-Dist: ty; extra == 'test'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # ๐Ÿซฐ Thanos
39
+
40
+ > *"Perfectly balanced, as all things should be."*
41
+
42
+ A Python CLI tool that randomly eliminates half of the files in a directory with a snap. Inspired by Marvel's Thanos and his infamous snap.
43
+
44
+ [![Test Python application](https://github.com/soldatov-ss/thanos/actions/workflows/test.yml/badge.svg)](https://github.com/soldatov-ss/thanos/actions/workflows/test.yml)
45
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
46
+ [![Coverage Status](https://coveralls.io/repos/github/soldatov-ss/thanos/badge.svg?branch=master)](https://coveralls.io/github/soldatov-ss/thanos?branch=master)
47
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
48
+
49
+ ## โš ๏ธ Warning
50
+
51
+ **This tool permanently deletes files!** Use `--dry-run` first to preview what would be deleted. Deleted files cannot be recovered. Use at your own risk!
52
+
53
+ ## โœจ Features
54
+
55
+ - ๐ŸŽฒ **Random Selection**: Eliminates exactly half of all files randomly
56
+ - ๐Ÿ”’ **Safety First**: Requires confirmation before deletion
57
+ - ๐Ÿ‘๏ธ **Dry Run Mode**: Preview what would be deleted without actually deleting
58
+ - ๐Ÿ“ **Recursive Support**: Optionally include files in subdirectories
59
+ - ๐ŸŽจ **Beautiful CLI**: Colorful output with emojis and clear status messages
60
+ - ๐Ÿงช **Well Tested**: Comprehensive test suite with pytest
61
+
62
+ ## ๐Ÿ“ฆ Installation
63
+
64
+ ### Using uv (recommended)
65
+
66
+ ```bash
67
+ uv add thanos-cli
68
+ ```
69
+
70
+ ### Using pip
71
+
72
+ ```bash
73
+ pip install thanos-cli
74
+ ```
75
+
76
+
77
+ ## ๐Ÿš€ Quick Start
78
+
79
+ ```bash
80
+ # Always start with a dry run to see what would be deleted
81
+ thanos --dry-run
82
+
83
+ # Snap the current directory (requires confirmation)
84
+ thanos
85
+
86
+ # Snap a specific directory
87
+ thanos /path/to/directory
88
+
89
+ # Include subdirectories recursively
90
+ thanos --recursive
91
+
92
+ # Dry run on a specific directory with subdirectories
93
+ thanos /path/to/directory --recursive --dry-run
94
+ ```
95
+
96
+ ## ๐Ÿ“– Usage
97
+
98
+ ```bash
99
+ thanos [OPTIONS] [DIRECTORY]
100
+ ```
101
+
102
+ ### Arguments
103
+
104
+ - `DIRECTORY` - Target directory to snap (default: current directory)
105
+
106
+ ### Options
107
+
108
+ - `-r, --recursive` - Include files in subdirectories recursively
109
+ - `-d, --dry-run` - Preview what would be deleted without actually deleting
110
+ - `--help` - Show help message and exit
111
+
112
+ ### Examples
113
+
114
+ ```bash
115
+ # See what would happen in current directory
116
+ thanos --dry-run
117
+
118
+ # Snap current directory
119
+ thanos
120
+
121
+ # Snap specific directory
122
+ thanos /tmp/test-files
123
+
124
+ # Snap with subdirectories
125
+ thanos ~/old-projects --recursive
126
+ ```
127
+
128
+ For detailed usage instructions, see [USAGE.md](docs/usage.md).
129
+
130
+
131
+ ## ๐Ÿ“ License
132
+
133
+ This project is licensed under the MIT License - see the LICENSE file for details.
134
+
135
+ ## ๐Ÿค” FAQ
136
+
137
+ **Q: Can I recover deleted files?**
138
+ A: No, files are permanently deleted. Always use `--dry-run` first!
139
+
140
+ **Q: How are files selected?**
141
+ A: Files are selected completely randomly using Python's `random.sample()`.
142
+
143
+ **Q: Does it delete directories?**
144
+ A: No, only files are affected. Empty directories may remain.
145
+
146
+ **Q: What if I have an odd number of files?**
147
+ A: If you have 11 files, 5 will be deleted (11 // 2 = 5) and 6 will remain.
148
+
149
+ ## ๐Ÿ™ Acknowledgments
150
+
151
+ - Built with [Typer](https://typer.tiangolo.com/) for the beautiful CLI
152
+ - Tested with [pytest](https://pytest.org/)
153
+ - Inspired by the Marvel Cinematic Universe
154
+
155
+ ---
156
+
157
+ **Remember**: With great power comes great responsibility. Use Thanos wisely! ๐Ÿซฐ
@@ -0,0 +1,9 @@
1
+ thanos_cli/__init__.py,sha256=Xfb862S5SHdhq99Rr1q0QttMX7lzihzb0fwmlIlPjlk,113
2
+ thanos_cli/__main__.py,sha256=Qd-f8z2Q2vpiEP2x6PBFsJrpACWDVxFKQk820MhFmHo,59
3
+ thanos_cli/cli.py,sha256=kQlB0qgdihtmrKb5ng_XCXgA31B2W9fUIorqVQo7Xkw,3566
4
+ thanos_cli/utils.py,sha256=t6fk6T4RUTaQEsRtl1iwGk_E7T-TP_E3FvjMGq7r3bQ,531
5
+ thanos_cli-0.1.0.dist-info/METADATA,sha256=CWz-qZLdnRFvNg13NbyRtrSVOhEJ8oPajbOv03ucmyY,4958
6
+ thanos_cli-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ thanos_cli-0.1.0.dist-info/entry_points.txt,sha256=wjVOsPWiPvNmgcglWZHcq9_zOM5eZ1Szc7hX1lsyvW0,46
8
+ thanos_cli-0.1.0.dist-info/licenses/LICENSE,sha256=nQEsw9GKmnfxl9MVlhvyAKzqtopAWSeV5daOAMPQTvw,1073
9
+ thanos_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ thanos = thanos_cli.cli:app
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025, Soldatov Serhii
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.