wsldu 1.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.
- wsldu/__init__.py +2 -0
- wsldu/__main__.py +3 -0
- wsldu/cli.py +161 -0
- wsldu/core.py +1203 -0
- wsldu/i18n.py +61 -0
- wsldu/lang_fr.py +434 -0
- wsldu/plan.py +137 -0
- wsldu/skill/SKILL.md +63 -0
- wsldu/static/index.html +614 -0
- wsldu/tui.py +620 -0
- wsldu/update.py +139 -0
- wsldu/web.py +388 -0
- wsldu-1.1.0.dist-info/METADATA +300 -0
- wsldu-1.1.0.dist-info/RECORD +18 -0
- wsldu-1.1.0.dist-info/WHEEL +5 -0
- wsldu-1.1.0.dist-info/entry_points.txt +2 -0
- wsldu-1.1.0.dist-info/licenses/LICENSE +21 -0
- wsldu-1.1.0.dist-info/top_level.txt +1 -0
wsldu/__init__.py
ADDED
wsldu/__main__.py
ADDED
wsldu/cli.py
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"""Command line entry point."""
|
|
2
|
+
import argparse
|
|
3
|
+
import json
|
|
4
|
+
import locale
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from . import __version__, core, i18n
|
|
9
|
+
from .i18n import _
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def build_parser():
|
|
13
|
+
p = argparse.ArgumentParser(
|
|
14
|
+
prog="wsldu",
|
|
15
|
+
description=_("Find what fills your WSL disk, clean it up, and give the space back to Windows."),
|
|
16
|
+
epilog=_("Examples:\n"
|
|
17
|
+
" wsldu terminal UI on /\n"
|
|
18
|
+
" sudo wsldu ~ terminal UI on your home, seeing every file\n"
|
|
19
|
+
" wsldu --web same tool in your browser\n"
|
|
20
|
+
" wsldu --report text report (add --json for scripts)\n"
|
|
21
|
+
" wsldu --compact compact the virtual disks (asks for confirmation)\n"
|
|
22
|
+
" wsldu --compact --yes silent compaction\n"
|
|
23
|
+
" wsldu --install-task one UAC prompt now, no prompt ever after\n"
|
|
24
|
+
" wsldu --apply plan.json review what an AI agent proposes to delete\n"
|
|
25
|
+
" wsldu --update update to the latest release"),
|
|
26
|
+
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
27
|
+
p.add_argument("path", nargs="?", default="/", help=_("folder to analyse (default: /)"))
|
|
28
|
+
mode = p.add_mutually_exclusive_group()
|
|
29
|
+
mode.add_argument("--web", action="store_true", help=_("start the local web UI"))
|
|
30
|
+
mode.add_argument("--report", action="store_true", help=_("print a report and exit"))
|
|
31
|
+
mode.add_argument("--compact", action="store_true",
|
|
32
|
+
help=_("fstrim + compact the WSL / Docker Desktop virtual disks on Windows"))
|
|
33
|
+
mode.add_argument("--install-task", action="store_true",
|
|
34
|
+
help=_("install the Windows scheduled task used for prompt-free silent compaction"))
|
|
35
|
+
mode.add_argument("--uninstall-task", action="store_true", help=_("remove that scheduled task"))
|
|
36
|
+
mode.add_argument("--apply", metavar="PLAN", help=_("review a cleanup plan (e.g. written by an AI agent) item by item"))
|
|
37
|
+
mode.add_argument("--update", action="store_true", help=_("update wsldu to the latest GitHub release"))
|
|
38
|
+
mode.add_argument("--check-update", action="store_true", help=_("only check whether a new version exists"))
|
|
39
|
+
mode.add_argument("--install-skill", action="store_true",
|
|
40
|
+
help=_("install the AI agent skill (Claude Code: ~/.claude/skills/wsldu)"))
|
|
41
|
+
p.add_argument("-y", "--yes", action="store_true",
|
|
42
|
+
help=_("with --compact: silent mode, no confirmation and hidden window"))
|
|
43
|
+
p.add_argument("--disk", action="append", metavar="NAME",
|
|
44
|
+
help=_("with --compact: only this distro name or .vhdx path (repeatable)"))
|
|
45
|
+
p.add_argument("--json", action="store_true", help=_("with --report: JSON output"))
|
|
46
|
+
p.add_argument("--scan", metavar="PATH", help=_("with --report: also scan PATH (folders, big files, regenerable)"))
|
|
47
|
+
p.add_argument("--plan", metavar="PLAN", help=_("with --web: open a cleanup plan for review"))
|
|
48
|
+
p.add_argument("--host", default="127.0.0.1", help=_("with --web: address to bind (default: 127.0.0.1)"))
|
|
49
|
+
p.add_argument("--port", type=int, default=8765, help=_("with --web: port (default: 8765, 0 = random)"))
|
|
50
|
+
p.add_argument("--no-browser", action="store_true", help=_("with --web: do not open the browser"))
|
|
51
|
+
p.add_argument("--lang", choices=i18n.SUPPORTED, help=_("interface language (default: auto)"))
|
|
52
|
+
p.add_argument("-V", "--version", action="version", version=f"wsldu {__version__}")
|
|
53
|
+
return p
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _windows_or_exit():
|
|
57
|
+
if not core.is_wsl():
|
|
58
|
+
sys.exit("wsldu: " + _("this command only works inside WSL."))
|
|
59
|
+
info = core.windows_info()
|
|
60
|
+
if info.get("error"):
|
|
61
|
+
sys.exit("wsldu: " + info["error"])
|
|
62
|
+
return info
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def cmd_compact(args):
|
|
66
|
+
info = _windows_or_exit()
|
|
67
|
+
disks = [d for d in info["disks"] if not args.disk or d["name"] in args.disk or d["win"] in args.disk]
|
|
68
|
+
if not disks:
|
|
69
|
+
sys.exit("wsldu: " + _("No virtual disk found."))
|
|
70
|
+
print(_("Virtual disks:"))
|
|
71
|
+
for d in disks:
|
|
72
|
+
print(f" {core.human(d['size']):>10} {d['name']:<30} {d['win']}")
|
|
73
|
+
if not args.yes:
|
|
74
|
+
print("\n" + _("WSL (and this terminal) will be stopped during the compaction."))
|
|
75
|
+
print("\n$ fstrim -av", flush=True)
|
|
76
|
+
ok, msg = core.compact(info, paths=[d["win"] for d in disks] if args.disk else None, silent=args.yes)
|
|
77
|
+
print(("" if ok else "wsldu: ") + msg)
|
|
78
|
+
sys.exit(0 if ok else 1)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def install_skill():
|
|
82
|
+
import pkgutil
|
|
83
|
+
text = pkgutil.get_data("wsldu", "skill/SKILL.md")
|
|
84
|
+
dest = os.path.join(core.HOME, ".claude", "skills", "wsldu")
|
|
85
|
+
os.makedirs(dest, exist_ok=True)
|
|
86
|
+
with open(os.path.join(dest, "SKILL.md"), "wb") as f:
|
|
87
|
+
f.write(text)
|
|
88
|
+
print(_("Skill installed: {path}", path=os.path.join(dest, "SKILL.md")))
|
|
89
|
+
print(_("Other agents (Codex, Gemini, Cursor...): point them to that file or paste it in AGENTS.md."))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _update_notice():
|
|
93
|
+
from . import update
|
|
94
|
+
latest = update.notice()
|
|
95
|
+
if latest:
|
|
96
|
+
print(update.notice_text(latest), file=sys.stderr)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def main(argv=None):
|
|
100
|
+
try:
|
|
101
|
+
locale.setlocale(locale.LC_ALL, "")
|
|
102
|
+
except locale.Error:
|
|
103
|
+
pass
|
|
104
|
+
pre = argparse.ArgumentParser(add_help=False)
|
|
105
|
+
pre.add_argument("--lang")
|
|
106
|
+
known, _rest = pre.parse_known_args(argv)
|
|
107
|
+
i18n.detect(known.lang)
|
|
108
|
+
args = build_parser().parse_args(argv)
|
|
109
|
+
|
|
110
|
+
if args.update or args.check_update:
|
|
111
|
+
from . import update
|
|
112
|
+
ok, msg = update.self_update(check_only=args.check_update)
|
|
113
|
+
print(msg)
|
|
114
|
+
sys.exit(0 if ok else 1)
|
|
115
|
+
if args.install_skill:
|
|
116
|
+
return install_skill()
|
|
117
|
+
if args.apply:
|
|
118
|
+
from . import plan
|
|
119
|
+
try:
|
|
120
|
+
plan.apply_cli(args.apply)
|
|
121
|
+
except (OSError, ValueError) as ex:
|
|
122
|
+
sys.exit("wsldu: " + str(ex))
|
|
123
|
+
return
|
|
124
|
+
if args.report:
|
|
125
|
+
data = core.report_data(scan=os.path.abspath(os.path.expanduser(args.scan)) if args.scan else None)
|
|
126
|
+
if args.json:
|
|
127
|
+
print(json.dumps(data, indent=2, ensure_ascii=False, default=str))
|
|
128
|
+
else:
|
|
129
|
+
core.print_report(data)
|
|
130
|
+
_update_notice()
|
|
131
|
+
return
|
|
132
|
+
if args.compact:
|
|
133
|
+
return cmd_compact(args)
|
|
134
|
+
if args.install_task or args.uninstall_task:
|
|
135
|
+
info = _windows_or_exit()
|
|
136
|
+
ok, msg = (core.install_task if args.install_task else core.uninstall_task)(info)
|
|
137
|
+
print(msg)
|
|
138
|
+
sys.exit(0 if ok else 1)
|
|
139
|
+
|
|
140
|
+
root = os.path.abspath(os.path.expanduser(args.path))
|
|
141
|
+
if not os.path.isdir(root):
|
|
142
|
+
sys.exit("wsldu: " + _("{path} is not a folder", path=root))
|
|
143
|
+
if args.web:
|
|
144
|
+
from . import web
|
|
145
|
+
if args.plan:
|
|
146
|
+
from . import plan
|
|
147
|
+
try:
|
|
148
|
+
plan.load(args.plan)
|
|
149
|
+
except (OSError, ValueError) as ex:
|
|
150
|
+
sys.exit("wsldu: " + str(ex))
|
|
151
|
+
web.serve(root, host=args.host, port=args.port, browser=not args.no_browser,
|
|
152
|
+
plan=os.path.abspath(args.plan) if args.plan else None)
|
|
153
|
+
return
|
|
154
|
+
if not sys.stdout.isatty():
|
|
155
|
+
sys.exit("wsldu: " + _("the terminal UI needs a terminal; try --report or --web."))
|
|
156
|
+
from . import tui
|
|
157
|
+
tui.run(root)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
if __name__ == "__main__":
|
|
161
|
+
main()
|