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,68 @@
|
|
|
1
|
+
"""Browser HTTP/disk caches (Firefox, Chrome, Chromium).
|
|
2
|
+
|
|
3
|
+
Only *cache* directories are touched — never profiles, cookies, history, or
|
|
4
|
+
saved passwords.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Iterable, List, Tuple
|
|
11
|
+
|
|
12
|
+
from cleanix.cleaners.base import Cleaner
|
|
13
|
+
from cleanix.core.models import CleanableItem
|
|
14
|
+
from cleanix.core.platform import XDG_PLATFORMS
|
|
15
|
+
from cleanix.core.utils import home, iter_children, path_size
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class BrowserCacheCleaner(Cleaner):
|
|
19
|
+
id = "browsers"
|
|
20
|
+
name = "Browser caches"
|
|
21
|
+
description = "Firefox/Chrome/Chromium on-disk HTTP caches"
|
|
22
|
+
requires_root = False
|
|
23
|
+
platforms = XDG_PLATFORMS
|
|
24
|
+
|
|
25
|
+
def _firefox_caches(self) -> Iterable[Tuple[Path, str]]:
|
|
26
|
+
# Firefox stores caches under ~/.cache/mozilla/firefox/<profile>/
|
|
27
|
+
base = home() / ".cache" / "mozilla" / "firefox"
|
|
28
|
+
for profile in iter_children(base):
|
|
29
|
+
cache = profile / "cache2"
|
|
30
|
+
if cache.exists():
|
|
31
|
+
yield cache, f"Firefox cache: {profile.name}"
|
|
32
|
+
|
|
33
|
+
def _chromium_caches(self) -> Iterable[Tuple[Path, str]]:
|
|
34
|
+
roots = {
|
|
35
|
+
"chrome": home() / ".config" / "google-chrome",
|
|
36
|
+
"chromium": home() / ".config" / "chromium",
|
|
37
|
+
}
|
|
38
|
+
for name, root in roots.items():
|
|
39
|
+
if not root.exists():
|
|
40
|
+
continue
|
|
41
|
+
for profile in iter_children(root):
|
|
42
|
+
if not profile.is_dir():
|
|
43
|
+
continue
|
|
44
|
+
for cache_name in ("Cache", "Code Cache", "GPUCache"):
|
|
45
|
+
cache = profile / cache_name
|
|
46
|
+
if cache.exists():
|
|
47
|
+
yield cache, f"{name} {cache_name}: {profile.name}"
|
|
48
|
+
|
|
49
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
50
|
+
wanted = {b.lower() for b in self.config.browsers}
|
|
51
|
+
sources: List[Tuple[Path, str]] = []
|
|
52
|
+
if "firefox" in wanted:
|
|
53
|
+
sources.extend(self._firefox_caches())
|
|
54
|
+
if "chrome" in wanted:
|
|
55
|
+
sources.extend(
|
|
56
|
+
s for s in self._chromium_caches() if s[1].startswith("chrome ")
|
|
57
|
+
)
|
|
58
|
+
if "chromium" in wanted:
|
|
59
|
+
sources.extend(
|
|
60
|
+
s for s in self._chromium_caches() if s[1].startswith("chromium ")
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
for path, label in sources:
|
|
64
|
+
if path_size(path) <= 0:
|
|
65
|
+
continue
|
|
66
|
+
item = self.path_item(path, label)
|
|
67
|
+
if item:
|
|
68
|
+
yield item
|
cleanix/cleaners/bsd.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""BSD package/ports leftovers (FreeBSD, and pkgin-based systems).
|
|
2
|
+
|
|
3
|
+
FreeBSD's ``pkg`` keeps a download cache and can autoremove orphaned
|
|
4
|
+
dependencies; the ports tree accumulates distfiles and build ``work`` dirs.
|
|
5
|
+
NetBSD/illumos ``pkgin`` keeps a similar cache.
|
|
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 BSD, FREEBSD, NETBSD
|
|
16
|
+
from cleanix.core.utils import path_size, run_command, which
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class FreeBsdPkgCleaner(Cleaner):
|
|
20
|
+
id = "pkg"
|
|
21
|
+
scope = SCOPE_SYSTEM
|
|
22
|
+
name = "FreeBSD pkg cache & orphans"
|
|
23
|
+
description = "Cached packages and orphaned dependencies (pkg)"
|
|
24
|
+
requires_root = True
|
|
25
|
+
platforms = tuple(BSD)
|
|
26
|
+
|
|
27
|
+
def available(self):
|
|
28
|
+
if not which("pkg"):
|
|
29
|
+
return "pkg not found"
|
|
30
|
+
return None
|
|
31
|
+
|
|
32
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
33
|
+
cache = Path("/var/cache/pkg")
|
|
34
|
+
size = path_size(cache) if cache.exists() else 0
|
|
35
|
+
if size > 0:
|
|
36
|
+
yield self.command_item(
|
|
37
|
+
["pkg", "clean", "-ay"],
|
|
38
|
+
"Remove cached package files",
|
|
39
|
+
size=size,
|
|
40
|
+
)
|
|
41
|
+
# Orphaned automatic dependencies.
|
|
42
|
+
code, out, _err = run_command(["pkg", "autoremove", "-n"], timeout=60)
|
|
43
|
+
blob = f"{out}\n{_err}"
|
|
44
|
+
if code == 0 and ("to be removed" in blob.lower() or "Deinstalling" in blob):
|
|
45
|
+
yield self.command_item(
|
|
46
|
+
["pkg", "autoremove", "-y"],
|
|
47
|
+
"Autoremove orphaned dependencies",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class BsdDistfilesCleaner(Cleaner):
|
|
52
|
+
id = "bsd_distfiles"
|
|
53
|
+
scope = SCOPE_SYSTEM
|
|
54
|
+
name = "BSD ports distfiles & work dirs"
|
|
55
|
+
description = "Downloaded source tarballs and stale build work/ directories"
|
|
56
|
+
requires_root = True
|
|
57
|
+
platforms = (FREEBSD,)
|
|
58
|
+
|
|
59
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
60
|
+
distfiles = Path("/usr/ports/distfiles")
|
|
61
|
+
if distfiles.exists() and path_size(distfiles) > 0:
|
|
62
|
+
item = self.path_item(distfiles, "Ports distfiles cache")
|
|
63
|
+
# Delete the *contents*, not the distfiles dir itself.
|
|
64
|
+
if item:
|
|
65
|
+
for child in distfiles.iterdir():
|
|
66
|
+
ci = self.path_item(child, f"Distfile: {child.name}")
|
|
67
|
+
if ci:
|
|
68
|
+
yield ci
|
|
69
|
+
|
|
70
|
+
# Leftover build work/ directories under the ports tree.
|
|
71
|
+
ports = Path("/usr/ports")
|
|
72
|
+
if ports.exists():
|
|
73
|
+
code, out, _err = run_command(
|
|
74
|
+
["find", "/usr/ports", "-type", "d", "-name", "work",
|
|
75
|
+
"-maxdepth", "3"],
|
|
76
|
+
timeout=60,
|
|
77
|
+
)
|
|
78
|
+
if code == 0:
|
|
79
|
+
for line in out.splitlines():
|
|
80
|
+
line = line.strip()
|
|
81
|
+
if line:
|
|
82
|
+
item = self.path_item(line, f"Ports work dir: {line}")
|
|
83
|
+
if item:
|
|
84
|
+
yield item
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class PkginCleaner(Cleaner):
|
|
88
|
+
id = "pkgin"
|
|
89
|
+
scope = SCOPE_SYSTEM
|
|
90
|
+
name = "pkgin cache (NetBSD/pkgsrc)"
|
|
91
|
+
description = "Cached binary packages downloaded by pkgin"
|
|
92
|
+
requires_root = True
|
|
93
|
+
platforms = (NETBSD,)
|
|
94
|
+
|
|
95
|
+
def available(self):
|
|
96
|
+
if not which("pkgin"):
|
|
97
|
+
return "pkgin not found"
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
101
|
+
cache = Path("/var/db/pkgin/cache")
|
|
102
|
+
size = path_size(cache) if cache.exists() else 0
|
|
103
|
+
if size > 0:
|
|
104
|
+
yield self.command_item(
|
|
105
|
+
["pkgin", "-y", "clean"],
|
|
106
|
+
"Remove cached binary packages",
|
|
107
|
+
size=size,
|
|
108
|
+
)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""Container-engine leftovers (Docker / Podman).
|
|
2
|
+
|
|
3
|
+
Dangling images, stopped containers, unused networks and build cache pile up
|
|
4
|
+
fast. We estimate the reclaimable amount from ``system df`` and offer a
|
|
5
|
+
``system prune``. Volumes are only included when explicitly enabled, since they
|
|
6
|
+
can hold real data.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import re
|
|
13
|
+
from typing import Iterable, List, Optional
|
|
14
|
+
|
|
15
|
+
from cleanix.cleaners.base import Cleaner, SCOPE_SYSTEM
|
|
16
|
+
from cleanix.core.models import CleanableItem
|
|
17
|
+
from cleanix.core.utils import run_command, which
|
|
18
|
+
|
|
19
|
+
_SIZE_RE = re.compile(r"([\d.]+)\s*([KMGT]?B)", re.IGNORECASE)
|
|
20
|
+
_UNIT = {"B": 1, "KB": 1024, "MB": 1024**2, "GB": 1024**3, "TB": 1024**4}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _parse_size(text: str) -> int:
|
|
24
|
+
m = _SIZE_RE.search(text or "")
|
|
25
|
+
if not m:
|
|
26
|
+
return 0
|
|
27
|
+
value = float(m.group(1))
|
|
28
|
+
unit = m.group(2).upper()
|
|
29
|
+
return int(value * _UNIT.get(unit, 1))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class _ContainerCleaner(Cleaner):
|
|
33
|
+
binary = ""
|
|
34
|
+
requires_root = False
|
|
35
|
+
|
|
36
|
+
def available(self):
|
|
37
|
+
if not which(self.binary):
|
|
38
|
+
return f"{self.binary} not found"
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
def _reclaimable(self) -> int:
|
|
42
|
+
code, out, _err = run_command(
|
|
43
|
+
[self.binary, "system", "df", "--format", "{{json .}}"], timeout=30
|
|
44
|
+
)
|
|
45
|
+
if code != 0 or not out.strip():
|
|
46
|
+
return 0
|
|
47
|
+
total = 0
|
|
48
|
+
for line in out.splitlines():
|
|
49
|
+
line = line.strip()
|
|
50
|
+
if not line:
|
|
51
|
+
continue
|
|
52
|
+
try:
|
|
53
|
+
row = json.loads(line)
|
|
54
|
+
except json.JSONDecodeError:
|
|
55
|
+
continue
|
|
56
|
+
total += _parse_size(row.get("Reclaimable", ""))
|
|
57
|
+
return total
|
|
58
|
+
|
|
59
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
60
|
+
reclaimable = self._reclaimable()
|
|
61
|
+
cmd: List[str] = [self.binary, "system", "prune", "-f"]
|
|
62
|
+
desc = "Prune stopped containers, dangling images, networks, build cache"
|
|
63
|
+
if self.config.docker_prune_volumes:
|
|
64
|
+
cmd.append("--volumes")
|
|
65
|
+
desc += " (incl. unused volumes)"
|
|
66
|
+
yield self.command_item(cmd, desc, size=reclaimable)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class DockerCleaner(_ContainerCleaner):
|
|
70
|
+
id = "docker"
|
|
71
|
+
scope = SCOPE_SYSTEM
|
|
72
|
+
name = "Docker leftovers"
|
|
73
|
+
description = "Dangling images, stopped containers, build cache"
|
|
74
|
+
binary = "docker"
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class PodmanCleaner(_ContainerCleaner):
|
|
78
|
+
id = "podman"
|
|
79
|
+
scope = SCOPE_SYSTEM
|
|
80
|
+
name = "Podman leftovers"
|
|
81
|
+
description = "Dangling images, stopped containers, build cache"
|
|
82
|
+
binary = "podman"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""System coredumps under ``/var/lib/systemd/coredump``."""
|
|
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 CoredumpCleaner(Cleaner):
|
|
15
|
+
id = "coredumps"
|
|
16
|
+
scope = SCOPE_SYSTEM
|
|
17
|
+
name = "Coredumps"
|
|
18
|
+
description = "Crash coredumps kept by systemd-coredump"
|
|
19
|
+
requires_root = True
|
|
20
|
+
platforms = (LINUX,)
|
|
21
|
+
|
|
22
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
23
|
+
root = Path("/var/lib/systemd/coredump")
|
|
24
|
+
if not root.exists():
|
|
25
|
+
return
|
|
26
|
+
min_age = self.config.coredump_min_age_days
|
|
27
|
+
for child in iter_children(root):
|
|
28
|
+
if not older_than(child, min_age):
|
|
29
|
+
continue
|
|
30
|
+
item = self.path_item(child, f"Coredump: {child.name}")
|
|
31
|
+
if item:
|
|
32
|
+
yield item
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Rebuildable desktop search indexes and activity databases."""
|
|
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
|
|
9
|
+
from cleanix.core.models import CleanableItem
|
|
10
|
+
from cleanix.core.platform import XDG_PLATFORMS
|
|
11
|
+
from cleanix.core.utils import home, path_size
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SearchIndexCleaner(Cleaner):
|
|
15
|
+
id = "search_index"
|
|
16
|
+
name = "Desktop search indexes"
|
|
17
|
+
description = "Baloo/Tracker/Zeitgeist indexes (rebuilt automatically)"
|
|
18
|
+
requires_root = False
|
|
19
|
+
platforms = XDG_PLATFORMS
|
|
20
|
+
|
|
21
|
+
def _candidates(self) -> Iterable[Tuple[Path, str]]:
|
|
22
|
+
h = home()
|
|
23
|
+
data = h / ".local" / "share"
|
|
24
|
+
cache = h / ".cache"
|
|
25
|
+
yield data / "baloo", "KDE Baloo file index"
|
|
26
|
+
yield cache / "tracker3", "GNOME Tracker cache"
|
|
27
|
+
yield data / "tracker3", "GNOME Tracker index"
|
|
28
|
+
yield cache / "tracker", "GNOME Tracker cache (v2)"
|
|
29
|
+
yield data / "tracker", "GNOME Tracker index (v2)"
|
|
30
|
+
yield data / "zeitgeist", "Zeitgeist activity log"
|
|
31
|
+
yield data / "gvfs-metadata", "GVFS metadata"
|
|
32
|
+
yield cache / "krunner", "KRunner cache"
|
|
33
|
+
|
|
34
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
35
|
+
seen = set()
|
|
36
|
+
for path, label in self._candidates():
|
|
37
|
+
if path in seen or not path.exists() or path_size(path) <= 0:
|
|
38
|
+
continue
|
|
39
|
+
seen.add(path)
|
|
40
|
+
item = self.path_item(path, label)
|
|
41
|
+
if item:
|
|
42
|
+
yield item
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Developer / language-toolchain caches.
|
|
2
|
+
|
|
3
|
+
These are all safely regenerable download/build caches. We deliberately avoid
|
|
4
|
+
directories that double as *installed* artifacts (``~/.m2/repository`` for
|
|
5
|
+
offline builds, installed gems, Go module source), touching only pure caches.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Iterable, List, Tuple
|
|
12
|
+
|
|
13
|
+
from cleanix.cleaners.base import Cleaner
|
|
14
|
+
from cleanix.core.models import CleanableItem
|
|
15
|
+
from cleanix.core.utils import home, path_size
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class DevCacheCleaner(Cleaner):
|
|
19
|
+
id = "dev_caches"
|
|
20
|
+
name = "Developer caches"
|
|
21
|
+
description = "Regenerable caches for cargo, go, gradle, ccache, composer…"
|
|
22
|
+
requires_root = False
|
|
23
|
+
|
|
24
|
+
def _candidates(self) -> Iterable[Tuple[Path, str]]:
|
|
25
|
+
h = home()
|
|
26
|
+
cache = h / ".cache"
|
|
27
|
+
yield cache / "go-build", "Go build cache"
|
|
28
|
+
yield h / ".cargo" / "registry" / "cache", "Cargo registry cache"
|
|
29
|
+
yield h / ".cargo" / "registry" / "src", "Cargo registry sources"
|
|
30
|
+
yield h / ".gradle" / "caches", "Gradle cache"
|
|
31
|
+
yield cache / "ccache", "ccache"
|
|
32
|
+
yield h / ".ccache", "ccache"
|
|
33
|
+
yield cache / "composer", "Composer cache"
|
|
34
|
+
yield h / ".composer" / "cache", "Composer cache"
|
|
35
|
+
yield cache / "pypoetry" / "cache", "Poetry cache"
|
|
36
|
+
yield cache / "pre-commit", "pre-commit hook cache"
|
|
37
|
+
yield cache / "puppeteer", "Puppeteer browser cache"
|
|
38
|
+
yield cache / "ms-playwright", "Playwright browser cache"
|
|
39
|
+
yield h / ".dartServer", "Dart analysis cache"
|
|
40
|
+
yield h / ".gradle" / "daemon", "Gradle daemon logs"
|
|
41
|
+
yield cache / "uv", "uv (Python) cache"
|
|
42
|
+
yield cache / "Cypress", "Cypress binary cache"
|
|
43
|
+
yield cache / "electron", "Electron download cache"
|
|
44
|
+
yield cache / "node-gyp", "node-gyp headers cache"
|
|
45
|
+
# NOTE: model-download caches (huggingface, torch hub, gpt4all) are
|
|
46
|
+
# intentionally handled by dedicated AI cleaners so we never wholesale
|
|
47
|
+
# delete downloaded weights.
|
|
48
|
+
|
|
49
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
50
|
+
seen = set()
|
|
51
|
+
for path, label in self._candidates():
|
|
52
|
+
if path in seen or not path.exists() or path_size(path) <= 0:
|
|
53
|
+
continue
|
|
54
|
+
seen.add(path)
|
|
55
|
+
item = self.path_item(path, label)
|
|
56
|
+
if item:
|
|
57
|
+
yield item
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Package-manager cleaners for the less-common Linux distros.
|
|
2
|
+
|
|
3
|
+
openSUSE (zypper), Alpine (apk), Void (xbps), and Gentoo (portage). Each offers
|
|
4
|
+
cache cleanup and, where cheaply detectable, orphan removal.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Iterable
|
|
11
|
+
|
|
12
|
+
from cleanix.cleaners.base import Cleaner, SCOPE_SYSTEM
|
|
13
|
+
from cleanix.core.models import CleanableItem
|
|
14
|
+
from cleanix.core.platform import LINUX
|
|
15
|
+
from cleanix.core.utils import path_size, run_command, which
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ZypperCleaner(Cleaner):
|
|
19
|
+
id = "zypper"
|
|
20
|
+
scope = SCOPE_SYSTEM
|
|
21
|
+
name = "Zypper cache (openSUSE)"
|
|
22
|
+
description = "Cached RPMs and metadata under /var/cache/zypp"
|
|
23
|
+
requires_root = True
|
|
24
|
+
platforms = (LINUX,)
|
|
25
|
+
|
|
26
|
+
def available(self):
|
|
27
|
+
if not which("zypper"):
|
|
28
|
+
return "zypper not found (not an openSUSE system)"
|
|
29
|
+
return None
|
|
30
|
+
|
|
31
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
32
|
+
cache = Path("/var/cache/zypp")
|
|
33
|
+
size = path_size(cache) if cache.exists() else 0
|
|
34
|
+
if size > 0:
|
|
35
|
+
yield self.command_item(
|
|
36
|
+
["zypper", "clean", "--all"],
|
|
37
|
+
"Clean all zypper caches (packages + metadata)",
|
|
38
|
+
size=size,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ApkCleaner(Cleaner):
|
|
43
|
+
id = "apk"
|
|
44
|
+
scope = SCOPE_SYSTEM
|
|
45
|
+
name = "apk cache (Alpine)"
|
|
46
|
+
description = "Cached packages under /var/cache/apk"
|
|
47
|
+
requires_root = True
|
|
48
|
+
platforms = (LINUX,)
|
|
49
|
+
|
|
50
|
+
def available(self):
|
|
51
|
+
if not which("apk"):
|
|
52
|
+
return "apk not found (not an Alpine system)"
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
56
|
+
cache = Path("/var/cache/apk")
|
|
57
|
+
size = path_size(cache) if cache.exists() else 0
|
|
58
|
+
if size > 0:
|
|
59
|
+
yield self.command_item(
|
|
60
|
+
["apk", "cache", "clean", "-v"],
|
|
61
|
+
"Remove obsolete cached apk packages",
|
|
62
|
+
size=size,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class XbpsCleaner(Cleaner):
|
|
67
|
+
id = "xbps"
|
|
68
|
+
scope = SCOPE_SYSTEM
|
|
69
|
+
name = "XBPS cache & orphans (Void)"
|
|
70
|
+
description = "Cached packages and orphaned dependencies"
|
|
71
|
+
requires_root = True
|
|
72
|
+
platforms = (LINUX,)
|
|
73
|
+
|
|
74
|
+
def available(self):
|
|
75
|
+
if not which("xbps-remove"):
|
|
76
|
+
return "xbps not found (not a Void system)"
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
80
|
+
cache = Path("/var/cache/xbps")
|
|
81
|
+
size = path_size(cache) if cache.exists() else 0
|
|
82
|
+
if size > 0:
|
|
83
|
+
yield self.command_item(
|
|
84
|
+
["xbps-remove", "-Oy"],
|
|
85
|
+
"Clean obsolete packages from the XBPS cache",
|
|
86
|
+
size=size,
|
|
87
|
+
)
|
|
88
|
+
# Orphaned packages.
|
|
89
|
+
code, out, _err = run_command(["xbps-query", "-O"], timeout=45)
|
|
90
|
+
if code == 0 and out.strip():
|
|
91
|
+
yield self.command_item(
|
|
92
|
+
["xbps-remove", "-oy"],
|
|
93
|
+
"Remove orphaned packages",
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class PortageCleaner(Cleaner):
|
|
98
|
+
id = "portage"
|
|
99
|
+
scope = SCOPE_SYSTEM
|
|
100
|
+
name = "Portage distfiles (Gentoo)"
|
|
101
|
+
description = "Stale source tarballs and binary packages"
|
|
102
|
+
requires_root = True
|
|
103
|
+
platforms = (LINUX,)
|
|
104
|
+
|
|
105
|
+
def available(self):
|
|
106
|
+
if not which("emerge"):
|
|
107
|
+
return "emerge not found (not a Gentoo system)"
|
|
108
|
+
if not which("eclean") and not which("eclean-dist"):
|
|
109
|
+
return "eclean not found (install app-portage/gentoolkit)"
|
|
110
|
+
return None
|
|
111
|
+
|
|
112
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
113
|
+
distfiles = 0
|
|
114
|
+
for base in ("/var/cache/distfiles", "/usr/portage/distfiles"):
|
|
115
|
+
p = Path(base)
|
|
116
|
+
if p.exists():
|
|
117
|
+
distfiles += path_size(p)
|
|
118
|
+
|
|
119
|
+
dist_cmd = ["eclean-dist", "-d"] if which("eclean-dist") else ["eclean", "-d", "distfiles"]
|
|
120
|
+
yield self.command_item(
|
|
121
|
+
dist_cmd, "Clean obsolete source distfiles", size=distfiles
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
pkg_cmd = ["eclean-pkg", "-d"] if which("eclean-pkg") else ["eclean", "-d", "packages"]
|
|
125
|
+
yield self.command_item(
|
|
126
|
+
pkg_cmd, "Clean obsolete binary packages"
|
|
127
|
+
)
|
cleanix/cleaners/dnf.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""DNF/YUM (Fedora/RHEL) — cache and orphaned packages."""
|
|
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 path_size, run_command, which
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class DnfCleaner(Cleaner):
|
|
15
|
+
id = "dnf"
|
|
16
|
+
scope = SCOPE_SYSTEM
|
|
17
|
+
name = "DNF cache & orphans"
|
|
18
|
+
description = "Cached metadata/RPMs and packages left over as unneeded deps"
|
|
19
|
+
requires_root = True
|
|
20
|
+
platforms = (LINUX,)
|
|
21
|
+
|
|
22
|
+
def _binary(self) -> str:
|
|
23
|
+
if which("dnf5"):
|
|
24
|
+
return "dnf5"
|
|
25
|
+
if which("dnf"):
|
|
26
|
+
return "dnf"
|
|
27
|
+
return "yum" # older RHEL/CentOS fallback
|
|
28
|
+
|
|
29
|
+
def available(self):
|
|
30
|
+
if not (which("dnf") or which("dnf5") or which("yum")):
|
|
31
|
+
return "dnf/yum not found (not a Fedora/RHEL system)"
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
def find_items(self) -> Iterable[CleanableItem]:
|
|
35
|
+
binary = self._binary()
|
|
36
|
+
|
|
37
|
+
cache = Path("/var/cache/dnf")
|
|
38
|
+
size = path_size(cache) if cache.exists() else 0
|
|
39
|
+
if size > 0:
|
|
40
|
+
yield self.command_item(
|
|
41
|
+
[binary, "clean", "all"],
|
|
42
|
+
"Clean all DNF caches (metadata + packages)",
|
|
43
|
+
size=size,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# Orphaned packages (installed as deps, no longer required).
|
|
47
|
+
code, out, _err = run_command(
|
|
48
|
+
[binary, "repoquery", "--unneeded", "--quiet"], timeout=90
|
|
49
|
+
)
|
|
50
|
+
if code == 0 and out.strip():
|
|
51
|
+
pkgs = [ln.strip() for ln in out.splitlines() if ln.strip()]
|
|
52
|
+
if pkgs:
|
|
53
|
+
yield self.command_item(
|
|
54
|
+
[binary, "-y", "autoremove"],
|
|
55
|
+
f"Autoremove {len(pkgs)} orphaned package(s)",
|
|
56
|
+
)
|