backpocket 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.
- backpocket/__init__.py +3 -0
- backpocket/cli.py +48 -0
- backpocket/commands/__init__.py +1 -0
- backpocket/commands/cleanup.py +109 -0
- backpocket-0.1.0.dist-info/METADATA +43 -0
- backpocket-0.1.0.dist-info/RECORD +9 -0
- backpocket-0.1.0.dist-info/WHEEL +4 -0
- backpocket-0.1.0.dist-info/entry_points.txt +2 -0
- backpocket-0.1.0.dist-info/licenses/LICENSE +21 -0
backpocket/__init__.py
ADDED
backpocket/cli.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""
|
|
2
|
+
backpocket CLI entrypoint.
|
|
3
|
+
Dispatches subcommands to modular command handlers in backpocket.commands.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from backpocket import __version__
|
|
10
|
+
from backpocket.commands import cleanup
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
14
|
+
parser = argparse.ArgumentParser(
|
|
15
|
+
prog="backpocket",
|
|
16
|
+
description="Essential developer utilities and automation kept in your backpocket.",
|
|
17
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
parser.add_argument(
|
|
21
|
+
"-v", "--version",
|
|
22
|
+
action="version",
|
|
23
|
+
version=f"%(prog)s {__version__}",
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
subparsers = parser.add_subparsers(
|
|
27
|
+
dest="command",
|
|
28
|
+
title="available commands",
|
|
29
|
+
metavar="<command>",
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# Register active commands
|
|
33
|
+
cleanup.register_subparser(subparsers)
|
|
34
|
+
|
|
35
|
+
return parser
|
|
36
|
+
|
|
37
|
+
def main(argv: list[str] | None = None) -> int:
|
|
38
|
+
parser = build_parser()
|
|
39
|
+
args = parser.parse_args(argv)
|
|
40
|
+
|
|
41
|
+
if not hasattr(args, "func"):
|
|
42
|
+
parser.print_help()
|
|
43
|
+
return 0
|
|
44
|
+
|
|
45
|
+
return args.func(args)
|
|
46
|
+
|
|
47
|
+
if __name__ == "__main__":
|
|
48
|
+
sys.exit(main())
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""CLI command modules for backpocket."""
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Cleanup command module.
|
|
3
|
+
Purges developer caches (pip, uv, poetry, npm, pnpm) and empties trash.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import platform
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
|
|
11
|
+
CLEANUP_TARGETS = [
|
|
12
|
+
{
|
|
13
|
+
"name": "Recycle Bin / Trash",
|
|
14
|
+
"check": lambda: platform.system() == "Windows",
|
|
15
|
+
"cmd": ["powershell", "-NoProfile", "-Command", "Clear-RecycleBin -Force -ErrorAction SilentlyContinue"],
|
|
16
|
+
"desc": "Windows Recycle Bin",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "PIP Cache",
|
|
20
|
+
"check": lambda: shutil.which("pip") is not None or shutil.which("python") is not None,
|
|
21
|
+
"cmd": ["pip", "cache", "purge"],
|
|
22
|
+
"desc": "Python PIP package download cache",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "UV Cache",
|
|
26
|
+
"check": lambda: shutil.which("uv") is not None,
|
|
27
|
+
"cmd": ["uv", "cache", "clean"],
|
|
28
|
+
"desc": "Astral UV wheel and source cache",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "Poetry Cache",
|
|
32
|
+
"check": lambda: shutil.which("poetry") is not None,
|
|
33
|
+
"cmd": ["poetry", "cache", "clear", "pypi", "--all", "-n"],
|
|
34
|
+
"desc": "Poetry dependency resolution cache",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": "NPM Cache",
|
|
38
|
+
"check": lambda: shutil.which("npm") is not None,
|
|
39
|
+
"cmd": ["npm", "cache", "clean", "--force"],
|
|
40
|
+
"desc": "Node NPM tarball and metadata cache",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"name": "PNPM Store",
|
|
44
|
+
"check": lambda: shutil.which("pnpm") is not None,
|
|
45
|
+
"cmd": ["pnpm", "store", "prune"],
|
|
46
|
+
"desc": "PNPM unreferenced store packages",
|
|
47
|
+
},
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
def run_cleanup(args: argparse.Namespace) -> int:
|
|
51
|
+
dry_run = getattr(args, "dry_run", False)
|
|
52
|
+
|
|
53
|
+
print("=" * 60)
|
|
54
|
+
print(" backpocket: Developer Disk & Cache Cleanup")
|
|
55
|
+
if dry_run:
|
|
56
|
+
print(" [MODE: DRY RUN - no files will be deleted]")
|
|
57
|
+
print("=" * 60)
|
|
58
|
+
|
|
59
|
+
total = len(CLEANUP_TARGETS)
|
|
60
|
+
executed = 0
|
|
61
|
+
skipped = 0
|
|
62
|
+
|
|
63
|
+
for idx, target in enumerate(CLEANUP_TARGETS, start=1):
|
|
64
|
+
name = target["name"]
|
|
65
|
+
cmd = target["cmd"]
|
|
66
|
+
available = target["check"]()
|
|
67
|
+
|
|
68
|
+
print(f"\n[{idx}/{total}] Checking {name}...")
|
|
69
|
+
|
|
70
|
+
if not available:
|
|
71
|
+
print(" [-] Tool not found on PATH. Skipped.")
|
|
72
|
+
skipped += 1
|
|
73
|
+
continue
|
|
74
|
+
|
|
75
|
+
if dry_run:
|
|
76
|
+
print(f" [*] Would execute: {' '.join(cmd)}")
|
|
77
|
+
executed += 1
|
|
78
|
+
continue
|
|
79
|
+
|
|
80
|
+
print(f" [*] Executing: {' '.join(cmd)}")
|
|
81
|
+
try:
|
|
82
|
+
res = subprocess.run(cmd, capture_output=True, text=True, check=False)
|
|
83
|
+
if res.returncode == 0:
|
|
84
|
+
print(" [+] Success.")
|
|
85
|
+
else:
|
|
86
|
+
err_msg = res.stderr.strip() or res.stdout.strip() or f"exit code {res.returncode}"
|
|
87
|
+
print(f" [!] Note: {err_msg}")
|
|
88
|
+
executed += 1
|
|
89
|
+
except (subprocess.SubprocessError, OSError) as e:
|
|
90
|
+
print(f" [!] Error running {name}: {e}")
|
|
91
|
+
|
|
92
|
+
print("\n" + "=" * 60)
|
|
93
|
+
print(f" Cleanup complete. {executed} executed, {skipped} skipped.")
|
|
94
|
+
print("=" * 60 + "\n")
|
|
95
|
+
return 0
|
|
96
|
+
|
|
97
|
+
def register_subparser(subparsers: argparse._SubParsersAction):
|
|
98
|
+
parser = subparsers.add_parser(
|
|
99
|
+
"cleanup",
|
|
100
|
+
aliases=["clean"],
|
|
101
|
+
help="Purge package manager caches (pip, uv, npm, poetry) and trash.",
|
|
102
|
+
description="Purge developer package caches and empty trash to reclaim disk space.",
|
|
103
|
+
)
|
|
104
|
+
parser.add_argument(
|
|
105
|
+
"--dry-run",
|
|
106
|
+
action="store_true",
|
|
107
|
+
help="Inspect cleanup targets without deleting files.",
|
|
108
|
+
)
|
|
109
|
+
parser.set_defaults(func=run_cleanup)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: backpocket
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Just some utilities kept in my backpocket
|
|
5
|
+
Author: sayyed
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: automation,cleanup,cli,developer-tools,utilities
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
<div align="center">
|
|
21
|
+
|
|
22
|
+
<img src="assets/backpocket.png" alt="backpocket logo" width="180" />
|
|
23
|
+
|
|
24
|
+
# backpocket
|
|
25
|
+
|
|
26
|
+
> Some scripts that I'd like to keep in my backpocket
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
The big idea behind this repository is to just house some scripts or instructions that could be useful for me in the sense of
|
|
33
|
+
- project development
|
|
34
|
+
- redundant chores
|
|
35
|
+
|
|
36
|
+
or other usecases that I haven't currently thought of.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
### Script index
|
|
41
|
+
|
|
42
|
+
1. **[Disk Cleanup](scripts/disk_cleanup.bat)**
|
|
43
|
+
> This script enables me to just clear out the developer caches after a major project or sometimes every so often, helps me clean back some space on my drives.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
backpocket/__init__.py,sha256=ow6C6FBtLvVhRuhgACeCtvrT35qcvpczcJ9bZEwzaBg,112
|
|
2
|
+
backpocket/cli.py,sha256=lnIbRlr7c_anc6eiKaBQWJuWCcXr-BIDmOAaW3L0dLk,1116
|
|
3
|
+
backpocket/commands/__init__.py,sha256=epSAvrkohD1PwkD3mXsTIt1-l-o3LtAdCWoCBrTAcfs,42
|
|
4
|
+
backpocket/commands/cleanup.py,sha256=MvyDjWi02SWpj2O0KC3DpF7All6QgdTqNGd69JOc7PQ,3505
|
|
5
|
+
backpocket-0.1.0.dist-info/METADATA,sha256=dnMYe6yaoI1K6wzrQSR2jG1zyX82B-fsvqbn0v4VKP8,1298
|
|
6
|
+
backpocket-0.1.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
7
|
+
backpocket-0.1.0.dist-info/entry_points.txt,sha256=xhlyiBS4GY-4mtT9GtROQHIVufXZK_Pwa6HZhu-mkhU,51
|
|
8
|
+
backpocket-0.1.0.dist-info/licenses/LICENSE,sha256=RaxhHnfQ3bt18ALnmZ-fFI15Y-dSjJKTR6iqD6L8RO4,1068
|
|
9
|
+
backpocket-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Asif Sayyed
|
|
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.
|