cleanix-cli 1.0.1__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.
Files changed (64) hide show
  1. cleanix/__init__.py +4 -0
  2. cleanix/__main__.py +6 -0
  3. cleanix/cleaners/__init__.py +269 -0
  4. cleanix/cleaners/ai_cli.py +193 -0
  5. cleanix/cleaners/ai_tools.py +224 -0
  6. cleanix/cleaners/app_cruft.py +201 -0
  7. cleanix/cleaners/apple_litter.py +41 -0
  8. cleanix/cleaners/apps.py +89 -0
  9. cleanix/cleaners/apt.py +70 -0
  10. cleanix/cleaners/base.py +173 -0
  11. cleanix/cleaners/broken_symlinks.py +51 -0
  12. cleanix/cleaners/browsers.py +68 -0
  13. cleanix/cleaners/bsd.py +108 -0
  14. cleanix/cleaners/containers.py +82 -0
  15. cleanix/cleaners/coredumps.py +32 -0
  16. cleanix/cleaners/desktop_extras.py +42 -0
  17. cleanix/cleaners/dev_caches.py +57 -0
  18. cleanix/cleaners/distro_pkg.py +127 -0
  19. cleanix/cleaners/dnf.py +56 -0
  20. cleanix/cleaners/editor_litter.py +115 -0
  21. cleanix/cleaners/font_cache.py +29 -0
  22. cleanix/cleaners/ide.py +87 -0
  23. cleanix/cleaners/kernels.py +115 -0
  24. cleanix/cleaners/lang_caches.py +70 -0
  25. cleanix/cleaners/linux_extras.py +77 -0
  26. cleanix/cleaners/localizations.py +70 -0
  27. cleanix/cleaners/logs.py +80 -0
  28. cleanix/cleaners/macos.py +166 -0
  29. cleanix/cleaners/macos_extra.py +125 -0
  30. cleanix/cleaners/memory.py +110 -0
  31. cleanix/cleaners/more_pkg.py +168 -0
  32. cleanix/cleaners/npm_cache.py +36 -0
  33. cleanix/cleaners/packaging_extras.py +140 -0
  34. cleanix/cleaners/pacman.py +63 -0
  35. cleanix/cleaners/pip_cache.py +27 -0
  36. cleanix/cleaners/snapshots.py +126 -0
  37. cleanix/cleaners/sys_extras.py +109 -0
  38. cleanix/cleaners/temp_files.py +48 -0
  39. cleanix/cleaners/thumbnails.py +31 -0
  40. cleanix/cleaners/trash.py +47 -0
  41. cleanix/cleaners/user_cache.py +69 -0
  42. cleanix/cleaners/virtualization.py +76 -0
  43. cleanix/cli.py +810 -0
  44. cleanix/completion.py +131 -0
  45. cleanix/config.py +225 -0
  46. cleanix/core/__init__.py +1 -0
  47. cleanix/core/context.py +147 -0
  48. cleanix/core/engine.py +155 -0
  49. cleanix/core/history.py +55 -0
  50. cleanix/core/models.py +141 -0
  51. cleanix/core/platform.py +117 -0
  52. cleanix/core/quarantine.py +147 -0
  53. cleanix/core/registry.py +58 -0
  54. cleanix/core/report.py +130 -0
  55. cleanix/core/safety.py +166 -0
  56. cleanix/core/utils.py +244 -0
  57. cleanix/reset.py +328 -0
  58. cleanix/scheduler/__init__.py +1 -0
  59. cleanix/scheduler/systemd.py +160 -0
  60. cleanix_cli-1.0.1.dist-info/METADATA +436 -0
  61. cleanix_cli-1.0.1.dist-info/RECORD +64 -0
  62. cleanix_cli-1.0.1.dist-info/WHEEL +5 -0
  63. cleanix_cli-1.0.1.dist-info/entry_points.txt +2 -0
  64. cleanix_cli-1.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,140 @@
1
+ """Sandbox/universal package leftovers: Flatpak, Snap, Nix, AppImage.
2
+
3
+ These package formats each accumulate their own kind of cruft — unused runtimes,
4
+ superseded revisions, old generations — that the base package manager never
5
+ touches.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+ from pathlib import Path
12
+ from typing import Iterable
13
+
14
+ from cleanix.cleaners.base import Cleaner, SCOPE_SYSTEM
15
+ from cleanix.core.models import CleanableItem
16
+ from cleanix.core.platform import LINUX, MACOS
17
+ from cleanix.core.utils import home, path_size, run_command, which
18
+
19
+
20
+ class FlatpakCleaner(Cleaner):
21
+ id = "flatpak"
22
+ scope = SCOPE_SYSTEM
23
+ name = "Flatpak unused runtimes"
24
+ description = "Runtimes/extensions no longer needed by any app"
25
+ requires_root = False
26
+ platforms = (LINUX,)
27
+
28
+ def available(self):
29
+ if not which("flatpak"):
30
+ return "flatpak not found"
31
+ return None
32
+
33
+ def find_items(self) -> Iterable[CleanableItem]:
34
+ code, out, _err = run_command(
35
+ ["flatpak", "uninstall", "--unused", "--assumeno"], timeout=60
36
+ )
37
+ # The --assumeno dry run lists what *would* be removed.
38
+ blob = f"{out}\n{_err}"
39
+ refs = [
40
+ ln.strip()
41
+ for ln in blob.splitlines()
42
+ if "/" in ln and ln.strip() and not ln.lower().startswith("proceed")
43
+ ]
44
+ # Fall back to offering the prune even if we couldn't parse counts.
45
+ yield self.command_item(
46
+ ["flatpak", "uninstall", "--unused", "-y"],
47
+ f"Remove {len(refs)} unused Flatpak runtime(s)"
48
+ if refs
49
+ else "Remove unused Flatpak runtimes",
50
+ )
51
+
52
+
53
+ class SnapCleaner(Cleaner):
54
+ id = "snap"
55
+ scope = SCOPE_SYSTEM
56
+ name = "Snap old revisions"
57
+ description = "Disabled superseded snap revisions still on disk"
58
+ requires_root = True
59
+ platforms = (LINUX,)
60
+
61
+ def available(self):
62
+ if not which("snap"):
63
+ return "snap not found"
64
+ return None
65
+
66
+ def find_items(self) -> Iterable[CleanableItem]:
67
+ code, out, _err = run_command(["snap", "list", "--all"], timeout=30)
68
+ if code != 0 or not out.strip():
69
+ return
70
+ for line in out.splitlines()[1:]:
71
+ parts = line.split()
72
+ if len(parts) >= 6 and "disabled" in parts[5]:
73
+ name, rev = parts[0], parts[2]
74
+ yield self.command_item(
75
+ ["snap", "remove", name, "--revision", rev],
76
+ f"Remove disabled snap revision: {name} (rev {rev})",
77
+ )
78
+
79
+
80
+ class NixGcCleaner(Cleaner):
81
+ id = "nix_gc"
82
+ scope = SCOPE_SYSTEM
83
+ name = "Nix garbage collection"
84
+ description = "Old profile generations and unreferenced Nix store paths"
85
+ requires_root = False # user store; multi-user setups may need root
86
+ platforms = (LINUX, MACOS)
87
+
88
+ def available(self):
89
+ if not which("nix-collect-garbage") and not which("nix-store"):
90
+ return "nix not found"
91
+ return None
92
+
93
+ def find_items(self) -> Iterable[CleanableItem]:
94
+ # Estimate reclaimable space from dead store paths.
95
+ size = 0
96
+ code, out, _err = run_command(
97
+ ["nix-store", "--gc", "--print-dead"], timeout=120
98
+ )
99
+ if code == 0 and out.strip():
100
+ for p in out.splitlines():
101
+ p = p.strip()
102
+ if p:
103
+ size += path_size(p)
104
+ yield self.command_item(
105
+ ["nix-collect-garbage", "-d"],
106
+ "Delete old generations and collect Nix garbage",
107
+ size=size,
108
+ )
109
+
110
+
111
+ class AppImageCruftCleaner(Cleaner):
112
+ id = "appimage"
113
+ name = "AppImage integration cruft"
114
+ description = "Orphaned .desktop/icon entries from removed AppImages"
115
+ requires_root = False
116
+ platforms = (LINUX,)
117
+
118
+ def find_items(self) -> Iterable[CleanableItem]:
119
+ # appimaged writes launcher entries here; leftovers point nowhere.
120
+ apps = home() / ".local" / "share" / "applications"
121
+ if not apps.is_dir():
122
+ return
123
+ import os
124
+
125
+ for entry in apps.glob("appimagekit_*.desktop"):
126
+ try:
127
+ text = entry.read_text(errors="ignore")
128
+ except OSError:
129
+ continue
130
+ exec_line = next(
131
+ (l for l in text.splitlines() if l.startswith("Exec=")), ""
132
+ )
133
+ m = re.search(r"Exec=\"?([^\s\"]+)", exec_line)
134
+ target = m.group(1) if m else ""
135
+ if target and not os.path.exists(os.path.expanduser(target)):
136
+ item = self.path_item(
137
+ entry, f"Orphaned AppImage launcher: {entry.name}"
138
+ )
139
+ if item:
140
+ yield item
@@ -0,0 +1,63 @@
1
+ """Pacman (Arch) — package cache, orphans, AUR helper build caches."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import Iterable
7
+
8
+ from cleanix.cleaners.base import Cleaner, SCOPE_SYSTEM
9
+ from cleanix.core.models import CleanableItem
10
+ from cleanix.core.platform import LINUX
11
+ from cleanix.core.utils import home, path_size, run_command, which
12
+
13
+
14
+ class PacmanCleaner(Cleaner):
15
+ id = "pacman"
16
+ scope = SCOPE_SYSTEM
17
+ name = "Pacman cache & orphans"
18
+ description = "Cached tarballs, orphaned packages, and AUR build caches"
19
+ requires_root = True
20
+ platforms = (LINUX,)
21
+
22
+ def available(self):
23
+ if not which("pacman"):
24
+ return "pacman not found (not an Arch-based system)"
25
+ return None
26
+
27
+ def find_items(self) -> Iterable[CleanableItem]:
28
+ # 1) Package cache.
29
+ cache = Path("/var/cache/pacman/pkg")
30
+ size = path_size(cache) if cache.exists() else 0
31
+ if size > 0:
32
+ if which("paccache"):
33
+ yield self.command_item(
34
+ ["paccache", "-r"],
35
+ "Trim cached packages, keeping the 3 latest versions",
36
+ size=size,
37
+ )
38
+ else:
39
+ yield self.command_item(
40
+ ["pacman", "-Sc", "--noconfirm"],
41
+ "Remove cached packages for uninstalled software",
42
+ size=size,
43
+ )
44
+
45
+ # 2) Orphans — installed as deps, now required by nothing.
46
+ code, out, _err = run_command(["pacman", "-Qtdq"], timeout=60)
47
+ if code == 0 and out.strip():
48
+ orphans = [ln.strip() for ln in out.splitlines() if ln.strip()]
49
+ yield self.command_item(
50
+ ["pacman", "-Rns", "--noconfirm", *orphans],
51
+ f"Remove {len(orphans)} orphaned package(s)",
52
+ )
53
+
54
+ # 3) AUR helper build caches (user-owned).
55
+ for rel, label in (
56
+ (".cache/yay", "yay build cache"),
57
+ (".cache/paru", "paru build cache"),
58
+ ):
59
+ item = self.path_item(
60
+ home() / rel, label, requires_root=False
61
+ )
62
+ if item:
63
+ yield item
@@ -0,0 +1,27 @@
1
+ """pip's download/wheel cache (``~/.cache/pip``)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+ from typing import Iterable
8
+
9
+ from cleanix.cleaners.base import Cleaner
10
+ from cleanix.core.models import CleanableItem
11
+ from cleanix.core.utils import cache_dir
12
+ from cleanix.core.utils import home, path_size
13
+
14
+
15
+ class PipCacheCleaner(Cleaner):
16
+ id = "pip_cache"
17
+ name = "pip cache"
18
+ description = "Cached wheels and downloads under ~/.cache/pip"
19
+ requires_root = False
20
+
21
+ def find_items(self) -> Iterable[CleanableItem]:
22
+ cache = str(cache_dir())
23
+ pip_dir = Path(cache) / "pip"
24
+ if pip_dir.exists() and path_size(pip_dir) > 0:
25
+ item = self.path_item(pip_dir, "pip download/wheel cache")
26
+ if item:
27
+ yield item
@@ -0,0 +1,126 @@
1
+ """Backups & snapshots.
2
+
3
+ These hold real recovery data, so cleanix **reports** them (with sizes and the
4
+ correct removal command) but never deletes them. The exception is backup-tool
5
+ *caches*, which are safe to clear.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from pathlib import Path
11
+ from typing import Iterable
12
+
13
+ from cleanix.cleaners.base import Cleaner, SCOPE_SYSTEM
14
+ from cleanix.core.models import CleanableItem
15
+ from cleanix.core.platform import LINUX, MACOS
16
+ from cleanix.core.utils import home, iter_children, path_size, run_command, which
17
+
18
+
19
+ class BackupCacheCleaner(Cleaner):
20
+ id = "backup_caches"
21
+ name = "Backup-tool caches"
22
+ description = "borg/restic/rclone caches (safe — not the repositories)"
23
+ requires_root = False
24
+
25
+ def find_items(self) -> Iterable[CleanableItem]:
26
+ h = home()
27
+ for path, label in (
28
+ (h / ".cache" / "borg", "Borg cache"),
29
+ (h / ".cache" / "restic", "restic cache"),
30
+ (h / ".cache" / "rclone", "rclone cache"),
31
+ (h / ".cache" / "deja-dup", "Déjà Dup cache"),
32
+ ):
33
+ if path.exists() and path_size(path) > 0:
34
+ item = self.path_item(path, label)
35
+ if item:
36
+ yield item
37
+
38
+
39
+ class SnapshotReporter(Cleaner):
40
+ id = "snapshots"
41
+ name = "Filesystem snapshots"
42
+ description = "Timeshift/Snapper/btrfs snapshots (report only)"
43
+ requires_root = True
44
+ platforms = (LINUX,)
45
+ scope = SCOPE_SYSTEM
46
+
47
+ def find_items(self) -> Iterable[CleanableItem]:
48
+ # Timeshift.
49
+ for base in ("/timeshift/snapshots", "/run/timeshift/backup/timeshift-btrfs/snapshots"):
50
+ root = Path(base)
51
+ if root.is_dir():
52
+ for snap in iter_children(root):
53
+ item = self.report_item(
54
+ snap, f"Timeshift snapshot: {snap.name}",
55
+ hint="remove with: timeshift --delete --snapshot '<name>'",
56
+ )
57
+ if item:
58
+ yield item
59
+
60
+ # Snapper configs.
61
+ if which("snapper"):
62
+ code, out, _ = run_command(["snapper", "list-configs"], timeout=20)
63
+ if code == 0:
64
+ for line in out.splitlines()[2:]:
65
+ cfg = line.split("|")[0].strip()
66
+ if cfg:
67
+ snap_dir = Path("/.snapshots") if cfg == "root" else None
68
+ # Report the config; sizes are hard to attribute per-snap.
69
+ yield CleanableItem(
70
+ cleaner_id=self.id,
71
+ description=f"Snapper snapshots (config '{cfg}')",
72
+ size=path_size(snap_dir) if snap_dir else 0,
73
+ path=str(snap_dir) if snap_dir else "/.snapshots",
74
+ report_only=True,
75
+ requires_root=True,
76
+ hint=f"list/remove with: snapper -c {cfg} list / delete <N>",
77
+ )
78
+
79
+
80
+ class TimeMachineReporter(Cleaner):
81
+ id = "time_machine"
82
+ name = "Time Machine local snapshots"
83
+ description = "APFS local Time Machine snapshots (report only)"
84
+ requires_root = False
85
+ platforms = (MACOS,)
86
+ scope = SCOPE_SYSTEM
87
+
88
+ def available(self):
89
+ if not which("tmutil"):
90
+ return "tmutil not found"
91
+ return None
92
+
93
+ def find_items(self) -> Iterable[CleanableItem]:
94
+ code, out, _ = run_command(["tmutil", "listlocalsnapshots", "/"], timeout=20)
95
+ if code != 0:
96
+ return
97
+ snaps = [ln.strip() for ln in out.splitlines() if "com.apple" in ln]
98
+ if snaps:
99
+ yield CleanableItem(
100
+ cleaner_id=self.id,
101
+ description=f"{len(snaps)} Time Machine local snapshot(s)",
102
+ size=0,
103
+ path="/",
104
+ report_only=True,
105
+ hint="thin with: tmutil thinlocalsnapshots / or deletelocalsnapshots <date>",
106
+ )
107
+
108
+
109
+ class DeviceBackupReporter(Cleaner):
110
+ id = "device_backups"
111
+ name = "Mobile device backups"
112
+ description = "iOS/Android device backups (report only — irreplaceable)"
113
+ requires_root = False
114
+ platforms = (MACOS,)
115
+
116
+ def find_items(self) -> Iterable[CleanableItem]:
117
+ base = home() / "Library" / "Application Support" / "MobileSync" / "Backup"
118
+ if not base.is_dir():
119
+ return
120
+ for backup in iter_children(base):
121
+ item = self.report_item(
122
+ backup, f"iOS device backup: {backup.name}",
123
+ hint="remove in Finder → Manage Backups, or delete this folder if intentional",
124
+ )
125
+ if item:
126
+ yield item
@@ -0,0 +1,109 @@
1
+ """Additional system-wide leftovers: /var/cache, /var/backups, crash spools."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import Iterable
7
+
8
+ from cleanix.cleaners.base import Cleaner, SCOPE_SYSTEM
9
+ from cleanix.core.models import CleanableItem
10
+ from cleanix.core.platform import LINUX
11
+ from cleanix.core.utils import iter_children, older_than
12
+
13
+
14
+ class SystemCacheCleaner(Cleaner):
15
+ id = "system_cache"
16
+ name = "System caches (/var/cache)"
17
+ description = "Regenerable PackageKit/man/fontconfig/cups caches"
18
+ requires_root = True
19
+ platforms = (LINUX,)
20
+ scope = SCOPE_SYSTEM
21
+
22
+ # Regenerable /var/cache subdirs. Package-manager caches (dnf/apt/pacman…)
23
+ # are owned by their dedicated cleaners and intentionally excluded here.
24
+ _SAFE = (
25
+ "PackageKit",
26
+ "man",
27
+ "fontconfig",
28
+ "cups",
29
+ "fwupd",
30
+ "app-info",
31
+ "abrt-di",
32
+ )
33
+
34
+ def find_items(self) -> Iterable[CleanableItem]:
35
+ root = Path("/var/cache")
36
+ if not root.is_dir():
37
+ return
38
+ for name in self._SAFE:
39
+ target = root / name
40
+ if target.is_dir():
41
+ for child in iter_children(target):
42
+ item = self.path_item(child, f"/var/cache/{name}: {child.name}")
43
+ if item:
44
+ yield item
45
+
46
+
47
+ class VarBackupsCleaner(Cleaner):
48
+ id = "var_backups"
49
+ name = "Debian /var/backups"
50
+ description = "Rotated dpkg/apt status backups"
51
+ requires_root = True
52
+ platforms = (LINUX,)
53
+ scope = SCOPE_SYSTEM
54
+
55
+ def find_items(self) -> Iterable[CleanableItem]:
56
+ root = Path("/var/backups")
57
+ if not root.is_dir():
58
+ return
59
+ # These are regenerated automatically; keep only very recent ones.
60
+ for child in iter_children(root):
61
+ if child.is_file() and (
62
+ child.suffix == ".gz" or child.name[-1:].isdigit()
63
+ ):
64
+ if older_than(child, 7):
65
+ item = self.path_item(child, f"Backup: {child.name}")
66
+ if item:
67
+ yield item
68
+
69
+
70
+ class CrashSpoolCleaner(Cleaner):
71
+ id = "crash_spool"
72
+ name = "ABRT/apport crash spool"
73
+ description = "Queued crash reports under /var/spool/abrt and /var/tmp/abrt"
74
+ requires_root = True
75
+ platforms = (LINUX,)
76
+ scope = SCOPE_SYSTEM
77
+
78
+ def find_items(self) -> Iterable[CleanableItem]:
79
+ for base in ("/var/spool/abrt", "/var/tmp/abrt", "/var/spool/apport"):
80
+ root = Path(base)
81
+ if not root.is_dir():
82
+ continue
83
+ for child in iter_children(root):
84
+ if not older_than(child, 0.02): # ~30 min, may be mid-write
85
+ continue
86
+ item = self.path_item(child, f"Crash spool: {child.name}")
87
+ if item:
88
+ yield item
89
+
90
+
91
+ class OfflineUpdateCleaner(Cleaner):
92
+ id = "offline_updates"
93
+ name = "Downloaded offline updates"
94
+ description = "Packages staged for offline system upgrades"
95
+ requires_root = True
96
+ platforms = (LINUX,)
97
+ scope = SCOPE_SYSTEM
98
+
99
+ def find_items(self) -> Iterable[CleanableItem]:
100
+ for base in (
101
+ "/var/lib/dnf/system-upgrade",
102
+ "/var/cache/PackageKit/downloads",
103
+ "/var/lib/PackageKit/prepared-update",
104
+ ):
105
+ root = Path(base)
106
+ if root.exists():
107
+ item = self.path_item(root, f"Offline update payload: {base}")
108
+ if item:
109
+ yield item
@@ -0,0 +1,48 @@
1
+ """Stale files in ``/tmp`` and ``/var/tmp``.
2
+
3
+ Only files older than ``config.temp_min_age_days`` are offered, so files in
4
+ active use are left alone. We never offer the tmp directories themselves.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import os
10
+ from pathlib import Path
11
+ from typing import Iterable
12
+
13
+ from cleanix.cleaners.base import Cleaner, SCOPE_SYSTEM
14
+ from cleanix.core.models import CleanableItem
15
+ from cleanix.core.utils import iter_children, older_than
16
+
17
+
18
+ class TempFilesCleaner(Cleaner):
19
+ id = "temp"
20
+ scope = SCOPE_SYSTEM
21
+ name = "Temp files (/tmp, /var/tmp)"
22
+ description = "Stale temporary files older than the configured age"
23
+ requires_root = False # per-file; root items are flagged individually
24
+
25
+ def find_items(self) -> Iterable[CleanableItem]:
26
+ min_age = self.config.temp_min_age_days
27
+ uid = os.getuid() if hasattr(os, "getuid") else None
28
+
29
+ for base in ("/tmp", "/var/tmp"):
30
+ root = Path(base)
31
+ if not root.exists():
32
+ continue
33
+ for child in iter_children(root):
34
+ if not older_than(child, min_age):
35
+ continue
36
+ # Only offer files we own unless running as root.
37
+ try:
38
+ owned_by_us = uid is not None and child.lstat().st_uid == uid
39
+ except OSError:
40
+ continue
41
+ needs_root = not owned_by_us
42
+ item = self.path_item(
43
+ child,
44
+ f"Temp: {child}",
45
+ requires_root=needs_root,
46
+ )
47
+ if item:
48
+ yield item
@@ -0,0 +1,31 @@
1
+ """Thumbnail cache (``~/.cache/thumbnails``)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+ from typing import Iterable
8
+
9
+ from cleanix.cleaners.base import Cleaner
10
+ from cleanix.core.models import CleanableItem
11
+ from cleanix.core.platform import XDG_PLATFORMS
12
+ from cleanix.core.utils import cache_dir
13
+ from cleanix.core.utils import home, iter_children
14
+
15
+
16
+ class ThumbnailCleaner(Cleaner):
17
+ id = "thumbnails"
18
+ name = "Thumbnails"
19
+ description = "Cached image/video thumbnails (regenerated on demand)"
20
+ requires_root = False
21
+ platforms = XDG_PLATFORMS
22
+
23
+ def find_items(self) -> Iterable[CleanableItem]:
24
+ cache = str(cache_dir())
25
+ thumb_root = Path(cache) / "thumbnails"
26
+ if not thumb_root.exists():
27
+ return
28
+ for sub in iter_children(thumb_root): # normal, large, fail, ...
29
+ item = self.path_item(sub, f"Thumbnails: {sub.name}")
30
+ if item:
31
+ yield item
@@ -0,0 +1,47 @@
1
+ """Freedesktop trash (``~/.local/share/Trash``) and per-mount trashes."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+ from typing import Iterable
8
+
9
+ from cleanix.cleaners.base import Cleaner
10
+ from cleanix.core.models import CleanableItem
11
+ from cleanix.core.platform import XDG_PLATFORMS
12
+ from cleanix.core.utils import data_dir, current_uid
13
+ from cleanix.core.utils import home, iter_children
14
+
15
+
16
+ class TrashCleaner(Cleaner):
17
+ id = "trash"
18
+ name = "Trash"
19
+ description = "Files sitting in the desktop trash/recycle bin"
20
+ requires_root = False
21
+ platforms = XDG_PLATFORMS
22
+
23
+ def _trash_dirs(self) -> Iterable[Path]:
24
+ data = str(data_dir())
25
+ yield Path(data) / "Trash"
26
+ # Per-mount trash dirs, e.g. /media/usb/.Trash-1000
27
+ uid = current_uid() or 1000
28
+ for mount_root in ("/media", "/mnt", "/run/media"):
29
+ base = Path(mount_root)
30
+ if not base.exists():
31
+ continue
32
+ for child in iter_children(base):
33
+ cand = child / f".Trash-{uid}"
34
+ if cand.exists():
35
+ yield cand
36
+
37
+ def find_items(self) -> Iterable[CleanableItem]:
38
+ for trash in self._trash_dirs():
39
+ # Only clear the contents subdirs, never the Trash dir itself.
40
+ for sub in ("files", "info", "expunged"):
41
+ target = trash / sub
42
+ for child in iter_children(target):
43
+ item = self.path_item(
44
+ child, f"Trash: {child.name}"
45
+ )
46
+ if item:
47
+ yield item
@@ -0,0 +1,69 @@
1
+ """Application caches under ``~/.cache`` plus any configured extras.
2
+
3
+ We deliberately skip a small allow-list of subdirectories whose loss is
4
+ annoying (fontconfig, which is cheap but slow to rebuild) and anything the
5
+ other cleaners already own (thumbnails, pip, browsers).
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import os
11
+ from pathlib import Path
12
+ from typing import Iterable
13
+
14
+ from cleanix.cleaners.base import Cleaner
15
+ from cleanix.core.models import CleanableItem
16
+ from cleanix.core.platform import XDG_PLATFORMS
17
+ from cleanix.core.utils import cache_dir, expand
18
+ from cleanix.core.utils import home, iter_children, modified_within
19
+
20
+ # ~/.cache subdirectories owned by a dedicated cleaner (so we don't offer them
21
+ # twice) or deliberately preserved (downloaded AI models). This cleaner is the
22
+ # catch-all for *everything else* under ~/.cache.
23
+ _SKIP = {
24
+ # dedicated: thumbnails / fonts / pip / browsers
25
+ "thumbnails", "fontconfig", "pip",
26
+ "mozilla", "google-chrome", "chromium", "BraveSoftware", "vivaldi",
27
+ "microsoft-edge", "opera",
28
+ # dedicated: dev_caches
29
+ "go-build", "ccache", "composer", "pypoetry", "pre-commit", "puppeteer",
30
+ "ms-playwright", "uv", "Cypress", "electron", "node-gyp", "yarn",
31
+ # dedicated: AI compile caches
32
+ "torch_extensions", "vllm", "flashinfer", "tfhub_modules",
33
+ # dedicated: AI clients (surgical) + preserved model downloads
34
+ "huggingface", "lm-studio", "gpt4all", "torch", "chroma", "whisper",
35
+ # dedicated: GPU shader caches
36
+ "mesa_shader_cache", "mesa_shader_cache_db", "nvidia",
37
+ "radv_builtin_shaders64",
38
+ # dedicated: JetBrains
39
+ "JetBrains",
40
+ }
41
+
42
+
43
+ class UserCacheCleaner(Cleaner):
44
+ id = "user_cache"
45
+ name = "User cache (~/.cache)"
46
+ description = "Assorted application caches under ~/.cache"
47
+ requires_root = False
48
+ platforms = XDG_PLATFORMS
49
+
50
+ def find_items(self) -> Iterable[CleanableItem]:
51
+ cache = cache_dir()
52
+ guard = self.config.cache_min_age_minutes
53
+ if cache.exists():
54
+ for child in iter_children(cache):
55
+ if child.name in _SKIP:
56
+ continue
57
+ # Skip anything being actively written (in-use guard). This
58
+ # protects e.g. another program's growing scratch file.
59
+ if modified_within(child, guard):
60
+ continue
61
+ item = self.path_item(child, f"Cache: {child.name}")
62
+ if item:
63
+ yield item
64
+
65
+ for extra in self.config.extra_cache_dirs:
66
+ p = expand(extra)
67
+ item = self.path_item(p, f"Cache (extra): {p}")
68
+ if item:
69
+ yield item