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.
- cleanix/__init__.py +4 -0
- cleanix/__main__.py +6 -0
- cleanix/cleaners/__init__.py +269 -0
- cleanix/cleaners/ai_cli.py +193 -0
- cleanix/cleaners/ai_tools.py +224 -0
- cleanix/cleaners/app_cruft.py +201 -0
- cleanix/cleaners/apple_litter.py +41 -0
- cleanix/cleaners/apps.py +89 -0
- cleanix/cleaners/apt.py +70 -0
- cleanix/cleaners/base.py +173 -0
- cleanix/cleaners/broken_symlinks.py +51 -0
- cleanix/cleaners/browsers.py +68 -0
- cleanix/cleaners/bsd.py +108 -0
- cleanix/cleaners/containers.py +82 -0
- cleanix/cleaners/coredumps.py +32 -0
- cleanix/cleaners/desktop_extras.py +42 -0
- cleanix/cleaners/dev_caches.py +57 -0
- cleanix/cleaners/distro_pkg.py +127 -0
- cleanix/cleaners/dnf.py +56 -0
- cleanix/cleaners/editor_litter.py +115 -0
- cleanix/cleaners/font_cache.py +29 -0
- cleanix/cleaners/ide.py +87 -0
- cleanix/cleaners/kernels.py +115 -0
- cleanix/cleaners/lang_caches.py +70 -0
- cleanix/cleaners/linux_extras.py +77 -0
- cleanix/cleaners/localizations.py +70 -0
- cleanix/cleaners/logs.py +80 -0
- cleanix/cleaners/macos.py +166 -0
- cleanix/cleaners/macos_extra.py +125 -0
- cleanix/cleaners/memory.py +110 -0
- cleanix/cleaners/more_pkg.py +168 -0
- cleanix/cleaners/npm_cache.py +36 -0
- cleanix/cleaners/packaging_extras.py +140 -0
- cleanix/cleaners/pacman.py +63 -0
- cleanix/cleaners/pip_cache.py +27 -0
- cleanix/cleaners/snapshots.py +126 -0
- cleanix/cleaners/sys_extras.py +109 -0
- cleanix/cleaners/temp_files.py +48 -0
- cleanix/cleaners/thumbnails.py +31 -0
- cleanix/cleaners/trash.py +47 -0
- cleanix/cleaners/user_cache.py +69 -0
- cleanix/cleaners/virtualization.py +76 -0
- cleanix/cli.py +810 -0
- cleanix/completion.py +131 -0
- cleanix/config.py +225 -0
- cleanix/core/__init__.py +1 -0
- cleanix/core/context.py +147 -0
- cleanix/core/engine.py +155 -0
- cleanix/core/history.py +55 -0
- cleanix/core/models.py +141 -0
- cleanix/core/platform.py +117 -0
- cleanix/core/quarantine.py +147 -0
- cleanix/core/registry.py +58 -0
- cleanix/core/report.py +130 -0
- cleanix/core/safety.py +166 -0
- cleanix/core/utils.py +244 -0
- cleanix/reset.py +328 -0
- cleanix/scheduler/__init__.py +1 -0
- cleanix/scheduler/systemd.py +160 -0
- cleanix_cli-1.0.1.dist-info/METADATA +436 -0
- cleanix_cli-1.0.1.dist-info/RECORD +64 -0
- cleanix_cli-1.0.1.dist-info/WHEEL +5 -0
- cleanix_cli-1.0.1.dist-info/entry_points.txt +2 -0
- cleanix_cli-1.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"""macOS-specific cleaners.
|
|
2
|
+
|
|
3
|
+
Covers the ~/Library cache/log layout, the macOS Trash, Homebrew/MacPorts,
|
|
4
|
+
Xcode's notoriously large developer caches, and diagnostic/crash reports.
|
|
5
|
+
All are gated to ``platforms = (MACOS,)``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Iterable, List, Tuple
|
|
13
|
+
|
|
14
|
+
from cleanix.cleaners.base import Cleaner, SCOPE_SYSTEM
|
|
15
|
+
from cleanix.core.models import CleanableItem
|
|
16
|
+
from cleanix.core.platform import MACOS
|
|
17
|
+
from cleanix.core.utils import current_uid
|
|
18
|
+
from cleanix.core.utils import home, iter_children, modified_within, path_size, run_command, which
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MacUserCacheCleaner(Cleaner):
|
|
22
|
+
id = "macos_caches"
|
|
23
|
+
name = "macOS user caches"
|
|
24
|
+
description = "Application caches under ~/Library/Caches"
|
|
25
|
+
requires_root = False
|
|
26
|
+
platforms = (MACOS,)
|
|
27
|
+
|
|
28
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
29
|
+
base = home() / "Library" / "Caches"
|
|
30
|
+
if not base.is_dir():
|
|
31
|
+
return
|
|
32
|
+
guard = self.config.cache_min_age_minutes
|
|
33
|
+
for child in iter_children(base):
|
|
34
|
+
if modified_within(child, guard):
|
|
35
|
+
continue
|
|
36
|
+
item = self.path_item(child, f"Cache: {child.name}")
|
|
37
|
+
if item:
|
|
38
|
+
yield item
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class MacTrashCleaner(Cleaner):
|
|
42
|
+
id = "macos_trash"
|
|
43
|
+
name = "macOS Trash"
|
|
44
|
+
description = "Files in ~/.Trash and per-volume .Trashes"
|
|
45
|
+
requires_root = False
|
|
46
|
+
platforms = (MACOS,)
|
|
47
|
+
|
|
48
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
49
|
+
trashes: List[Path] = [home() / ".Trash"]
|
|
50
|
+
uid = current_uid() or 0
|
|
51
|
+
volumes = Path("/Volumes")
|
|
52
|
+
if volumes.is_dir():
|
|
53
|
+
for vol in iter_children(volumes):
|
|
54
|
+
trashes.append(vol / ".Trashes" / str(uid))
|
|
55
|
+
for trash in trashes:
|
|
56
|
+
for child in iter_children(trash):
|
|
57
|
+
item = self.path_item(child, f"Trash: {child.name}")
|
|
58
|
+
if item:
|
|
59
|
+
yield item
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class MacDiagnosticsCleaner(Cleaner):
|
|
63
|
+
id = "macos_diagnostics"
|
|
64
|
+
name = "macOS logs & crash reports"
|
|
65
|
+
description = "Diagnostic reports and logs under ~/Library/Logs"
|
|
66
|
+
requires_root = False
|
|
67
|
+
platforms = (MACOS,)
|
|
68
|
+
|
|
69
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
70
|
+
targets = [
|
|
71
|
+
home() / "Library" / "Logs" / "DiagnosticReports",
|
|
72
|
+
home() / "Library" / "Logs",
|
|
73
|
+
home() / "Library" / "Application Support" / "CrashReporter",
|
|
74
|
+
]
|
|
75
|
+
seen = set()
|
|
76
|
+
for base in targets:
|
|
77
|
+
if not base.is_dir():
|
|
78
|
+
continue
|
|
79
|
+
for child in iter_children(base):
|
|
80
|
+
if str(child) in seen:
|
|
81
|
+
continue
|
|
82
|
+
seen.add(str(child))
|
|
83
|
+
item = self.path_item(child, f"Log/report: {child.name}")
|
|
84
|
+
if item:
|
|
85
|
+
yield item
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class HomebrewCleaner(Cleaner):
|
|
89
|
+
id = "homebrew"
|
|
90
|
+
name = "Homebrew cleanup"
|
|
91
|
+
description = "Old formula versions and download cache"
|
|
92
|
+
requires_root = False
|
|
93
|
+
platforms = (MACOS,)
|
|
94
|
+
|
|
95
|
+
def available(self):
|
|
96
|
+
if not which("brew"):
|
|
97
|
+
return "brew not found"
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
101
|
+
size = 0
|
|
102
|
+
code, out, _err = run_command(["brew", "--cache"], timeout=20)
|
|
103
|
+
if code == 0 and out.strip():
|
|
104
|
+
cache = Path(out.strip())
|
|
105
|
+
if cache.exists():
|
|
106
|
+
size = path_size(cache)
|
|
107
|
+
yield self.command_item(
|
|
108
|
+
["brew", "cleanup", "--prune=all", "-s"],
|
|
109
|
+
"Remove old versions and scrub the Homebrew download cache",
|
|
110
|
+
size=size,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class MacPortsCleaner(Cleaner):
|
|
115
|
+
id = "macports"
|
|
116
|
+
scope = SCOPE_SYSTEM
|
|
117
|
+
name = "MacPorts cleanup"
|
|
118
|
+
description = "Inactive ports and build leftovers"
|
|
119
|
+
requires_root = True
|
|
120
|
+
platforms = (MACOS,)
|
|
121
|
+
|
|
122
|
+
def available(self):
|
|
123
|
+
if not which("port"):
|
|
124
|
+
return "port not found"
|
|
125
|
+
return None
|
|
126
|
+
|
|
127
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
128
|
+
yield self.command_item(
|
|
129
|
+
["port", "-q", "clean", "--all", "installed"],
|
|
130
|
+
"Clean build/distfile leftovers for installed ports",
|
|
131
|
+
)
|
|
132
|
+
yield self.command_item(
|
|
133
|
+
["port", "-q", "uninstall", "inactive"],
|
|
134
|
+
"Uninstall inactive (superseded) port versions",
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class XcodeCleaner(Cleaner):
|
|
139
|
+
id = "xcode"
|
|
140
|
+
name = "Xcode developer caches"
|
|
141
|
+
description = "DerivedData, Archives, device support, simulator caches"
|
|
142
|
+
requires_root = False
|
|
143
|
+
platforms = (MACOS,)
|
|
144
|
+
|
|
145
|
+
def _paths(self) -> Iterable[Tuple[Path, str]]:
|
|
146
|
+
dev = home() / "Library" / "Developer"
|
|
147
|
+
yield dev / "Xcode" / "DerivedData", "Xcode DerivedData"
|
|
148
|
+
yield dev / "Xcode" / "Archives", "Xcode Archives"
|
|
149
|
+
yield dev / "Xcode" / "iOS DeviceSupport", "iOS DeviceSupport"
|
|
150
|
+
yield dev / "Xcode" / "watchOS DeviceSupport", "watchOS DeviceSupport"
|
|
151
|
+
yield dev / "Xcode" / "tvOS DeviceSupport", "tvOS DeviceSupport"
|
|
152
|
+
yield dev / "CoreSimulator" / "Caches", "CoreSimulator caches"
|
|
153
|
+
yield home() / "Library" / "Caches" / "com.apple.dt.Xcode", "Xcode cache"
|
|
154
|
+
|
|
155
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
156
|
+
for path, label in self._paths():
|
|
157
|
+
if path.exists() and path_size(path) > 0:
|
|
158
|
+
item = self.path_item(path, label)
|
|
159
|
+
if item:
|
|
160
|
+
yield item
|
|
161
|
+
# Unavailable simulators (deleted OS runtimes) can waste many GB.
|
|
162
|
+
if which("xcrun"):
|
|
163
|
+
yield self.command_item(
|
|
164
|
+
["xcrun", "simctl", "delete", "unavailable"],
|
|
165
|
+
"Delete unavailable/obsolete iOS simulators",
|
|
166
|
+
)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""Additional macOS leftovers beyond the core macOS cleaners."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Iterable, Tuple
|
|
7
|
+
|
|
8
|
+
from cleanix.cleaners.base import Cleaner, SCOPE_SYSTEM
|
|
9
|
+
from cleanix.core.models import CleanableItem
|
|
10
|
+
from cleanix.core.platform import MACOS
|
|
11
|
+
from cleanix.core.utils import home, iter_children, path_size
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class MacExtraCachesCleaner(Cleaner):
|
|
15
|
+
id = "macos_extra"
|
|
16
|
+
name = "macOS extra caches"
|
|
17
|
+
description = "Saved app state, CocoaPods/Carthage caches, QuickLook"
|
|
18
|
+
requires_root = False
|
|
19
|
+
platforms = (MACOS,)
|
|
20
|
+
|
|
21
|
+
def _candidates(self) -> Iterable[Tuple[Path, str]]:
|
|
22
|
+
h = home()
|
|
23
|
+
lib = h / "Library"
|
|
24
|
+
yield lib / "Saved Application State", "Saved application state"
|
|
25
|
+
yield lib / "Caches" / "CocoaPods", "CocoaPods cache"
|
|
26
|
+
yield lib / "Caches" / "org.carthage.CarthageKit", "Carthage cache"
|
|
27
|
+
yield lib / "Caches" / "com.apple.QuickLook.thumbnailcache", "QuickLook thumbnails"
|
|
28
|
+
yield lib / "Caches" / "Homebrew", "Homebrew cache"
|
|
29
|
+
yield lib / "Developer" / "CoreSimulator" / "Devices", "CoreSimulator devices"
|
|
30
|
+
yield lib / "Containers" / "com.apple.mail" / "Data" / "Library" / "Mail Downloads", "Mail downloads"
|
|
31
|
+
|
|
32
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
33
|
+
seen = set()
|
|
34
|
+
for path, label in self._candidates():
|
|
35
|
+
if path in seen or not path.exists() or path_size(path) <= 0:
|
|
36
|
+
continue
|
|
37
|
+
seen.add(path)
|
|
38
|
+
item = self.path_item(path, label)
|
|
39
|
+
if item:
|
|
40
|
+
yield item
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class MacContainerCacheCleaner(Cleaner):
|
|
44
|
+
id = "macos_containers"
|
|
45
|
+
name = "macOS sandboxed app caches"
|
|
46
|
+
description = "Caches inside ~/Library/Containers and Group Containers"
|
|
47
|
+
requires_root = False
|
|
48
|
+
platforms = (MACOS,)
|
|
49
|
+
|
|
50
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
51
|
+
lib = home() / "Library"
|
|
52
|
+
from cleanix.core.utils import modified_within
|
|
53
|
+
guard = self.config.cache_min_age_minutes
|
|
54
|
+
for base in ("Containers", "Group Containers"):
|
|
55
|
+
root = lib / base
|
|
56
|
+
if not root.is_dir():
|
|
57
|
+
continue
|
|
58
|
+
for container in iter_children(root):
|
|
59
|
+
cache = container / "Data" / "Library" / "Caches"
|
|
60
|
+
if not cache.is_dir():
|
|
61
|
+
cache = container / "Library" / "Caches"
|
|
62
|
+
if cache.is_dir():
|
|
63
|
+
for child in iter_children(cache):
|
|
64
|
+
if modified_within(child, guard):
|
|
65
|
+
continue
|
|
66
|
+
item = self.path_item(
|
|
67
|
+
child, f"{container.name}: {child.name}"
|
|
68
|
+
)
|
|
69
|
+
if item:
|
|
70
|
+
yield item
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class MacSystemCacheCleaner(Cleaner):
|
|
74
|
+
id = "macos_system_cache"
|
|
75
|
+
name = "macOS system caches"
|
|
76
|
+
description = "Regenerable caches under /Library/Caches"
|
|
77
|
+
requires_root = True
|
|
78
|
+
platforms = (MACOS,)
|
|
79
|
+
scope = SCOPE_SYSTEM
|
|
80
|
+
|
|
81
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
82
|
+
root = Path("/Library/Caches")
|
|
83
|
+
if not root.is_dir():
|
|
84
|
+
return
|
|
85
|
+
for child in iter_children(root):
|
|
86
|
+
item = self.path_item(child, f"/Library/Caches: {child.name}")
|
|
87
|
+
if item:
|
|
88
|
+
yield item
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class MacFontCacheCleaner(Cleaner):
|
|
92
|
+
id = "macos_font_cache"
|
|
93
|
+
name = "macOS font caches"
|
|
94
|
+
description = "Rebuildable font registration caches (atsutil)"
|
|
95
|
+
requires_root = False
|
|
96
|
+
platforms = (MACOS,)
|
|
97
|
+
|
|
98
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
99
|
+
from cleanix.core.utils import which
|
|
100
|
+
|
|
101
|
+
if which("atsutil"):
|
|
102
|
+
yield self.command_item(
|
|
103
|
+
["atsutil", "databases", "-removeUser"],
|
|
104
|
+
"Clear per-user font databases",
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class MacSleepImageReporter(Cleaner):
|
|
109
|
+
id = "macos_sleepimage"
|
|
110
|
+
name = "macOS sleep image"
|
|
111
|
+
description = "Hibernation image (report only — recreated by the OS)"
|
|
112
|
+
requires_root = True
|
|
113
|
+
platforms = (MACOS,)
|
|
114
|
+
scope = SCOPE_SYSTEM
|
|
115
|
+
|
|
116
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
117
|
+
for base in ("/private/var/vm/sleepimage", "/var/vm/sleepimage"):
|
|
118
|
+
p = Path(base)
|
|
119
|
+
if p.exists():
|
|
120
|
+
item = self.report_item(
|
|
121
|
+
p, "macOS sleep/hibernation image",
|
|
122
|
+
hint="managed by pmset; remove only if you understand hibernation impact",
|
|
123
|
+
)
|
|
124
|
+
if item:
|
|
125
|
+
yield item
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""Safe memory reclamation (RAM caches + swap).
|
|
2
|
+
|
|
3
|
+
These operations NEVER kill or trim running applications — they only ask the
|
|
4
|
+
kernel to release *clean, reclaimable* memory:
|
|
5
|
+
|
|
6
|
+
- **drop_caches** frees the page/dentry/inode cache. The kernel simply re-reads
|
|
7
|
+
from disk later; no process loses data (we ``sync`` first to flush dirty pages).
|
|
8
|
+
- **swap reclaim** (``swapoff -a && swapon -a``) pulls swapped pages back into
|
|
9
|
+
RAM, emptying swap — but only when there is clearly enough free RAM to hold
|
|
10
|
+
them, so it can never trigger an out-of-memory kill.
|
|
11
|
+
|
|
12
|
+
They are opt-in (``default_enabled = False``): run explicitly with
|
|
13
|
+
``cleanix clean --only memory,swap``. All are read-only until you execute.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Dict, Iterable
|
|
20
|
+
|
|
21
|
+
from cleanix.cleaners.base import SCOPE_SYSTEM, Cleaner
|
|
22
|
+
from cleanix.core.models import CleanableItem
|
|
23
|
+
from cleanix.core.platform import LINUX, MACOS
|
|
24
|
+
from cleanix.core.utils import which
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _meminfo() -> Dict[str, int]:
|
|
28
|
+
"""Parse /proc/meminfo into a dict of bytes (values are in kB there)."""
|
|
29
|
+
info: Dict[str, int] = {}
|
|
30
|
+
try:
|
|
31
|
+
for line in Path("/proc/meminfo").read_text().splitlines():
|
|
32
|
+
key, _, rest = line.partition(":")
|
|
33
|
+
parts = rest.split()
|
|
34
|
+
if parts and parts[0].isdigit():
|
|
35
|
+
info[key.strip()] = int(parts[0]) * 1024
|
|
36
|
+
except OSError:
|
|
37
|
+
pass
|
|
38
|
+
return info
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class DropCachesCleaner(Cleaner):
|
|
42
|
+
id = "memory"
|
|
43
|
+
name = "RAM cache (drop_caches)"
|
|
44
|
+
description = "Free reclaimable page/dentry/inode cache (safe; no app impact)"
|
|
45
|
+
requires_root = True
|
|
46
|
+
platforms = (LINUX,)
|
|
47
|
+
scope = SCOPE_SYSTEM
|
|
48
|
+
default_enabled = False
|
|
49
|
+
|
|
50
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
51
|
+
info = _meminfo()
|
|
52
|
+
reclaimable = info.get("Cached", 0) + info.get("Buffers", 0) + info.get(
|
|
53
|
+
"SReclaimable", 0
|
|
54
|
+
)
|
|
55
|
+
if reclaimable <= 0:
|
|
56
|
+
return
|
|
57
|
+
# `sync` flushes dirty pages so nothing is lost; then drop clean caches.
|
|
58
|
+
yield self.command_item(
|
|
59
|
+
["sh", "-c", "sync && echo 3 > /proc/sys/vm/drop_caches"],
|
|
60
|
+
"Drop reclaimable RAM caches (page/dentry/inode)",
|
|
61
|
+
size=reclaimable,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class SwapReclaimCleaner(Cleaner):
|
|
66
|
+
id = "swap"
|
|
67
|
+
name = "Swap reclaim"
|
|
68
|
+
description = "Move swapped pages back to RAM to empty swap (OOM-guarded)"
|
|
69
|
+
requires_root = True
|
|
70
|
+
platforms = (LINUX,)
|
|
71
|
+
scope = SCOPE_SYSTEM
|
|
72
|
+
default_enabled = False
|
|
73
|
+
|
|
74
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
75
|
+
info = _meminfo()
|
|
76
|
+
swap_total = info.get("SwapTotal", 0)
|
|
77
|
+
swap_free = info.get("SwapFree", 0)
|
|
78
|
+
swap_used = swap_total - swap_free
|
|
79
|
+
available = info.get("MemAvailable", 0)
|
|
80
|
+
|
|
81
|
+
if swap_used <= 0:
|
|
82
|
+
return
|
|
83
|
+
# Only offer if free RAM comfortably exceeds swap in use (20% headroom),
|
|
84
|
+
# otherwise swapoff could fail or force an OOM — never risk that.
|
|
85
|
+
if available < swap_used * 1.2:
|
|
86
|
+
return
|
|
87
|
+
yield self.command_item(
|
|
88
|
+
["sh", "-c", "swapoff -a && swapon -a"],
|
|
89
|
+
f"Reclaim swap (~{swap_used // (1024 * 1024)} MiB) back into free RAM",
|
|
90
|
+
size=swap_used,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class MacMemoryPurgeCleaner(Cleaner):
|
|
95
|
+
id = "memory_macos"
|
|
96
|
+
name = "macOS memory purge"
|
|
97
|
+
description = "Free inactive memory with Apple's supported `purge` tool"
|
|
98
|
+
requires_root = True
|
|
99
|
+
platforms = (MACOS,)
|
|
100
|
+
scope = SCOPE_SYSTEM
|
|
101
|
+
default_enabled = False
|
|
102
|
+
|
|
103
|
+
def available(self):
|
|
104
|
+
return None if which("purge") else "purge not found"
|
|
105
|
+
|
|
106
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
107
|
+
yield self.command_item(
|
|
108
|
+
["purge"],
|
|
109
|
+
"Purge inactive memory (disk cache) — Apple-supported, safe",
|
|
110
|
+
)
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""Cleanup steps for the remaining package managers.
|
|
2
|
+
|
|
3
|
+
Rounds out coverage across the ecosystem: Conda/Mamba, Guix, Solus eopkg,
|
|
4
|
+
Clear Linux swupd, OCaml opam, SDKMAN!, RubyGems, and cpanm — each invoking its
|
|
5
|
+
native cleanup, or clearing its download/cache dirs where there is no command.
|
|
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
|
|
16
|
+
from cleanix.core.utils import home, path_size, which
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class CondaCleaner(Cleaner):
|
|
20
|
+
id = "conda"
|
|
21
|
+
name = "Conda/Mamba caches"
|
|
22
|
+
description = "Unused packages, tarballs and index cache (conda clean -a)"
|
|
23
|
+
requires_root = False
|
|
24
|
+
|
|
25
|
+
def _pkg_dirs(self):
|
|
26
|
+
h = home()
|
|
27
|
+
for base in ("miniconda3", "anaconda3", "miniforge3", "mambaforge", ".conda"):
|
|
28
|
+
yield h / base / "pkgs"
|
|
29
|
+
|
|
30
|
+
def available(self):
|
|
31
|
+
if which("conda") or which("mamba") or which("micromamba"):
|
|
32
|
+
return None
|
|
33
|
+
if any(p.exists() for p in self._pkg_dirs()):
|
|
34
|
+
return None
|
|
35
|
+
return "conda/mamba not found"
|
|
36
|
+
|
|
37
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
38
|
+
size = sum(path_size(p) for p in self._pkg_dirs() if p.exists())
|
|
39
|
+
binary = "mamba" if which("mamba") else "conda"
|
|
40
|
+
if which(binary) or which("micromamba"):
|
|
41
|
+
tool = binary if which(binary) else "micromamba"
|
|
42
|
+
yield self.command_item(
|
|
43
|
+
[tool, "clean", "-a", "-y"],
|
|
44
|
+
"Remove unused conda packages, tarballs and index cache",
|
|
45
|
+
size=size,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class GuixCleaner(Cleaner):
|
|
50
|
+
id = "guix"
|
|
51
|
+
name = "Guix garbage collection"
|
|
52
|
+
description = "Unreferenced store items and old generations (guix gc)"
|
|
53
|
+
requires_root = False
|
|
54
|
+
platforms = (LINUX,)
|
|
55
|
+
|
|
56
|
+
def available(self):
|
|
57
|
+
return None if which("guix") else "guix not found"
|
|
58
|
+
|
|
59
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
60
|
+
yield self.command_item(
|
|
61
|
+
["guix", "gc", "-C"],
|
|
62
|
+
"Collect Guix garbage (unreferenced store items)",
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class EopkgCleaner(Cleaner):
|
|
67
|
+
id = "eopkg"
|
|
68
|
+
name = "Solus eopkg (cache & orphans)"
|
|
69
|
+
description = "Cached packages and orphaned dependencies"
|
|
70
|
+
requires_root = True
|
|
71
|
+
platforms = (LINUX,)
|
|
72
|
+
scope = SCOPE_SYSTEM
|
|
73
|
+
|
|
74
|
+
def available(self):
|
|
75
|
+
return None if which("eopkg") else "eopkg not found (not a Solus system)"
|
|
76
|
+
|
|
77
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
78
|
+
cache = Path("/var/cache/eopkg/packages")
|
|
79
|
+
size = path_size(cache) if cache.exists() else 0
|
|
80
|
+
yield self.command_item(
|
|
81
|
+
["eopkg", "delete-cache"], "Clear the eopkg package cache", size=size
|
|
82
|
+
)
|
|
83
|
+
yield self.command_item(
|
|
84
|
+
["eopkg", "remove-orphans", "-y"], "Remove orphaned dependencies"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class SwupdCleaner(Cleaner):
|
|
89
|
+
id = "swupd"
|
|
90
|
+
name = "Clear Linux swupd cache"
|
|
91
|
+
description = "Cached update bundles (swupd clean)"
|
|
92
|
+
requires_root = True
|
|
93
|
+
platforms = (LINUX,)
|
|
94
|
+
scope = SCOPE_SYSTEM
|
|
95
|
+
|
|
96
|
+
def available(self):
|
|
97
|
+
return None if which("swupd") else "swupd not found (not a Clear Linux system)"
|
|
98
|
+
|
|
99
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
100
|
+
cache = Path("/var/lib/swupd")
|
|
101
|
+
size = path_size(cache) if cache.exists() else 0
|
|
102
|
+
yield self.command_item(
|
|
103
|
+
["swupd", "clean", "--all"], "Clean the swupd cache", size=size
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class OpamCleaner(Cleaner):
|
|
108
|
+
id = "opam"
|
|
109
|
+
name = "OPAM cache (OCaml)"
|
|
110
|
+
description = "Cached downloads and build logs (opam clean)"
|
|
111
|
+
requires_root = False
|
|
112
|
+
|
|
113
|
+
def available(self):
|
|
114
|
+
return None if which("opam") else "opam not found"
|
|
115
|
+
|
|
116
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
117
|
+
size = path_size(home() / ".opam" / "download-cache")
|
|
118
|
+
yield self.command_item(
|
|
119
|
+
["opam", "clean", "-y"],
|
|
120
|
+
"Clear opam download cache and build logs",
|
|
121
|
+
size=size,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class SdkmanCleaner(Cleaner):
|
|
126
|
+
id = "sdkman"
|
|
127
|
+
name = "SDKMAN! archives"
|
|
128
|
+
description = "Downloaded SDK archives and temp files"
|
|
129
|
+
requires_root = False
|
|
130
|
+
|
|
131
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
132
|
+
base = home() / ".sdkman"
|
|
133
|
+
for sub in ("archives", "tmp"):
|
|
134
|
+
target = base / sub
|
|
135
|
+
if target.is_dir() and path_size(target) > 0:
|
|
136
|
+
item = self.path_item(target, f"SDKMAN! {sub}")
|
|
137
|
+
if item:
|
|
138
|
+
yield item
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class GemCleanupCleaner(Cleaner):
|
|
142
|
+
id = "gem"
|
|
143
|
+
name = "RubyGems old versions"
|
|
144
|
+
description = "Remove superseded installed gem versions (gem cleanup)"
|
|
145
|
+
requires_root = False
|
|
146
|
+
|
|
147
|
+
def available(self):
|
|
148
|
+
return None if which("gem") else "gem not found"
|
|
149
|
+
|
|
150
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
151
|
+
yield self.command_item(
|
|
152
|
+
["gem", "cleanup"],
|
|
153
|
+
"Remove old versions of installed gems",
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class CpanmCleaner(Cleaner):
|
|
158
|
+
id = "cpanm"
|
|
159
|
+
name = "cpanm build leftovers"
|
|
160
|
+
description = "Perl cpanminus work/build directories"
|
|
161
|
+
requires_root = False
|
|
162
|
+
|
|
163
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
164
|
+
work = home() / ".cpanm" / "work"
|
|
165
|
+
if work.is_dir() and path_size(work) > 0:
|
|
166
|
+
item = self.path_item(work, "cpanm work directory")
|
|
167
|
+
if item:
|
|
168
|
+
yield item
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""npm / yarn caches under the user home."""
|
|
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 NpmCacheCleaner(Cleaner):
|
|
16
|
+
id = "npm_cache"
|
|
17
|
+
name = "npm/yarn cache"
|
|
18
|
+
description = "JavaScript package manager caches"
|
|
19
|
+
requires_root = False
|
|
20
|
+
|
|
21
|
+
def _candidates(self):
|
|
22
|
+
h = home()
|
|
23
|
+
cache = str(cache_dir())
|
|
24
|
+
yield h / ".npm" / "_cacache", "npm cache"
|
|
25
|
+
yield Path(cache) / "yarn", "yarn cache"
|
|
26
|
+
yield h / ".cache" / "yarn", "yarn cache"
|
|
27
|
+
|
|
28
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
29
|
+
seen = set()
|
|
30
|
+
for path, label in self._candidates():
|
|
31
|
+
if path in seen or not path.exists() or path_size(path) <= 0:
|
|
32
|
+
continue
|
|
33
|
+
seen.add(path)
|
|
34
|
+
item = self.path_item(path, label)
|
|
35
|
+
if item:
|
|
36
|
+
yield item
|