youpdated-scanning 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.
- youpdated_scanning/__init__.py +75 -0
- youpdated_scanning/base.py +70 -0
- youpdated_scanning/browsers.py +115 -0
- youpdated_scanning/cargo.py +76 -0
- youpdated_scanning/dotnet.py +60 -0
- youpdated_scanning/electron.py +126 -0
- youpdated_scanning/flatpak.py +53 -0
- youpdated_scanning/golang.py +141 -0
- youpdated_scanning/homebrew.py +78 -0
- youpdated_scanning/macapps.py +177 -0
- youpdated_scanning/npm.py +75 -0
- youpdated_scanning/pipx.py +87 -0
- youpdated_scanning/py.typed +0 -0
- youpdated_scanning/steam.py +245 -0
- youpdated_scanning/uv.py +68 -0
- youpdated_scanning/winget.py +318 -0
- youpdated_scanning/wingetnames.py +279 -0
- youpdated_scanning-0.1.0.dist-info/METADATA +61 -0
- youpdated_scanning-0.1.0.dist-info/RECORD +22 -0
- youpdated_scanning-0.1.0.dist-info/WHEEL +5 -0
- youpdated_scanning-0.1.0.dist-info/licenses/LICENSE +21 -0
- youpdated_scanning-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Find what's installed on this machine, for `youpdated scan`"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__version__ = "0.1.0"
|
|
6
|
+
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import TYPE_CHECKING, Iterable
|
|
9
|
+
|
|
10
|
+
from .base import Installed, ScanError, Scanner
|
|
11
|
+
from .browsers import BrowsersScanner
|
|
12
|
+
from .cargo import CargoScanner
|
|
13
|
+
from .dotnet import DotnetScanner
|
|
14
|
+
from .electron import ElectronScanner
|
|
15
|
+
from .flatpak import FlatpakScanner
|
|
16
|
+
from .golang import GoScanner
|
|
17
|
+
from .homebrew import HomebrewScanner
|
|
18
|
+
from .macapps import MacAppsScanner
|
|
19
|
+
from .npm import NpmScanner
|
|
20
|
+
from .pipx import PipxScanner
|
|
21
|
+
from .steam import SteamScanner
|
|
22
|
+
from .uv import UvScanner
|
|
23
|
+
from .winget import WingetScanner
|
|
24
|
+
|
|
25
|
+
if TYPE_CHECKING:
|
|
26
|
+
from youpdated.importers import Found
|
|
27
|
+
|
|
28
|
+
__all__ = ["Installed", "SCANNERS", "ScanError", "Scanner", "__version__", "scan"]
|
|
29
|
+
|
|
30
|
+
# In the order they run. Package managers come first: an app one installed is watched through it, and later scanners
|
|
31
|
+
# pass over what an earlier one found at the same place. Then the browsers, before an app's feed
|
|
32
|
+
SCANNERS: dict[str, Scanner] = {
|
|
33
|
+
scanner.name: scanner
|
|
34
|
+
for scanner in (
|
|
35
|
+
SteamScanner(), HomebrewScanner(), WingetScanner(), FlatpakScanner(),
|
|
36
|
+
PipxScanner(), UvScanner(), NpmScanner(), CargoScanner(), GoScanner(), DotnetScanner(),
|
|
37
|
+
BrowsersScanner(), MacAppsScanner(), ElectronScanner(),
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def scan(found: Found, only: Iterable[str] | None = None) -> list[Installed]:
|
|
43
|
+
"""Run the available scanners (or ``only``) into ``found``. Returns everything found, versions included"""
|
|
44
|
+
chosen = list(SCANNERS) if only is None else list(only)
|
|
45
|
+
unknown = [name for name in chosen if name not in SCANNERS]
|
|
46
|
+
if unknown:
|
|
47
|
+
raise ValueError(f"no scanner named {', '.join(unknown)}; expected one of {', '.join(SCANNERS)}")
|
|
48
|
+
# SCANNERS' order, whatever order --only gave
|
|
49
|
+
names = [name for name in SCANNERS if name in chosen]
|
|
50
|
+
|
|
51
|
+
installed: list[Installed] = []
|
|
52
|
+
claimed: set[Path] = set()
|
|
53
|
+
for name in names:
|
|
54
|
+
scanner = SCANNERS[name]
|
|
55
|
+
if not scanner.available():
|
|
56
|
+
continue
|
|
57
|
+
try:
|
|
58
|
+
if only is not None and getattr(scanner, "asks_first", False):
|
|
59
|
+
finds = list(scanner.scan(guarded_too=True))
|
|
60
|
+
else:
|
|
61
|
+
finds = list(scanner.scan())
|
|
62
|
+
for note in getattr(scanner, "notes", ()):
|
|
63
|
+
found.warn(f"{name}: {note}")
|
|
64
|
+
except ScanError as exc:
|
|
65
|
+
found.warn(f"{name}: {exc}")
|
|
66
|
+
continue
|
|
67
|
+
except Exception as exc:
|
|
68
|
+
found.warn(f"{name} failed: {type(exc).__name__}: {exc}")
|
|
69
|
+
continue
|
|
70
|
+
finds = [item for item in finds if item.where is None or item.where not in claimed]
|
|
71
|
+
claimed.update(item.where for item in finds if item.where is not None)
|
|
72
|
+
for item in finds:
|
|
73
|
+
found.add(item.source, item.entry)
|
|
74
|
+
installed.append(item)
|
|
75
|
+
return installed
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""What a scanner is and what it finds"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import ClassVar, Iterable, Mapping, Protocol
|
|
11
|
+
|
|
12
|
+
from youpdated.errors import YoupdatedError
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ScanError(YoupdatedError):
|
|
16
|
+
"""A scanner that could run but failed"""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True)
|
|
20
|
+
class Installed:
|
|
21
|
+
"""An installed source on this machine, as a Youpdated config entry"""
|
|
22
|
+
|
|
23
|
+
source: str
|
|
24
|
+
entry: str
|
|
25
|
+
name: str | None = None
|
|
26
|
+
version: str | None = None
|
|
27
|
+
where: Path | None = None
|
|
28
|
+
aliases: tuple[str, ...] = ()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Scanner(Protocol):
|
|
32
|
+
name: ClassVar[str]
|
|
33
|
+
summary: ClassVar[str]
|
|
34
|
+
# Youpdated sources this scanner's finds go under
|
|
35
|
+
sources: ClassVar[tuple[str, ...]]
|
|
36
|
+
# Programs a scanner runs that would go online on their own are given environment variables turning that off: see each scanner's ENV
|
|
37
|
+
|
|
38
|
+
def available(self) -> bool:
|
|
39
|
+
"""If there's anything to scan here: right OS, program on PATH, directory present. No subprocesses"""
|
|
40
|
+
...
|
|
41
|
+
|
|
42
|
+
def scan(self) -> Iterable[Installed]:
|
|
43
|
+
"""What's installed. Reads local files and runs local programs only"""
|
|
44
|
+
...
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def neutral_directory() -> Path:
|
|
48
|
+
"""Where programs are run from: the root of the home folder's drive"""
|
|
49
|
+
return Path(Path.home().anchor or os.sep)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def run(program: str, *args: str, timeout: float, env: Mapping[str, str] | None = None) -> str:
|
|
53
|
+
"""``program args`` output, found on PATH and run from ``neutral_directory()`` with ``env`` added to the environment"""
|
|
54
|
+
command = " ".join((program, *args))
|
|
55
|
+
path = shutil.which(program)
|
|
56
|
+
if path is None:
|
|
57
|
+
raise ScanError(f"{program} is not on PATH")
|
|
58
|
+
try:
|
|
59
|
+
done = subprocess.run(
|
|
60
|
+
[path, *args], capture_output=True, text=True, encoding="utf-8", errors="replace",
|
|
61
|
+
timeout=timeout, env={**os.environ, **(env or {})}, cwd=neutral_directory(),
|
|
62
|
+
)
|
|
63
|
+
except subprocess.TimeoutExpired:
|
|
64
|
+
raise ScanError(f"`{command}` took longer than {timeout:g} seconds") from None
|
|
65
|
+
except OSError as exc:
|
|
66
|
+
raise ScanError(f"cannot run `{command}`: {exc.strerror or exc}") from None
|
|
67
|
+
if done.returncode != 0:
|
|
68
|
+
lines = (done.stderr or done.stdout or "").strip().splitlines()
|
|
69
|
+
raise ScanError(f"`{command}` exited with {done.returncode}" + (f": {lines[-1].strip()}" if lines else ""))
|
|
70
|
+
return done.stdout
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Chrome, Brave, Firefox, Edge, for the browser source
|
|
2
|
+
|
|
3
|
+
None use Sparkle, so the apps scanner doesn't find them. They update themselves.
|
|
4
|
+
|
|
5
|
+
- macOS: by bundle id, in ``/Applications`` and ``~/Applications`` as the apps scanner reads them
|
|
6
|
+
- Linux: by the ``.desktop`` file their packages install, in ``$XDG_DATA_HOME`` and ``$XDG_DATA_DIRS``
|
|
7
|
+
(Flatpak's are Flathub app ids, which the flatpak scanner finds)
|
|
8
|
+
- Windows: winget identifies them, so this doesn't run
|
|
9
|
+
|
|
10
|
+
Only the stable channel is found
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import re
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import ClassVar, Iterable, Sequence
|
|
20
|
+
|
|
21
|
+
from .base import Installed
|
|
22
|
+
from .macapps import _text, app_dirs, bundles, read_plist
|
|
23
|
+
|
|
24
|
+
BUNDLE_IDS = {
|
|
25
|
+
"com.google.Chrome": "chrome",
|
|
26
|
+
"com.brave.Browser": "brave",
|
|
27
|
+
"org.mozilla.firefox": "firefox",
|
|
28
|
+
"com.microsoft.edgemac": "edge",
|
|
29
|
+
}
|
|
30
|
+
DESKTOP_FILES = {
|
|
31
|
+
"google-chrome.desktop": "chrome",
|
|
32
|
+
"brave-browser.desktop": "brave",
|
|
33
|
+
"firefox.desktop": "firefox",
|
|
34
|
+
# Ubuntu's Firefox snap
|
|
35
|
+
"firefox_firefox.desktop": "firefox",
|
|
36
|
+
"microsoft-edge.desktop": "edge",
|
|
37
|
+
}
|
|
38
|
+
NAMES = {"chrome": "Google Chrome", "brave": "Brave", "firefox": "Firefox", "edge": "Microsoft Edge"}
|
|
39
|
+
# Brave's bundle version puts its Chromium's major first: 158.1.100.59 is Brave 1.100.59
|
|
40
|
+
_BRAVE_RE = re.compile(r"^\d+\.(\d+\.\d+\.\d+)$")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def comparable(browser: str, version: str | None) -> str | None:
|
|
44
|
+
"""``version`` as the browser source numbers ``browser``'s releases, or None when it can't be"""
|
|
45
|
+
if version is None or browser != "brave":
|
|
46
|
+
return version
|
|
47
|
+
found = _BRAVE_RE.match(version)
|
|
48
|
+
return found.group(1) if found else None
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
_CHANNEL_RE = re.compile(r"""pref\(\s*["']app\.update\.channel["']\s*,\s*["']([^"']+)["']""")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def firefox_channel(app: Path) -> str | None:
|
|
55
|
+
"""The update channel a Firefox (``.app`` on macOS) was built for"""
|
|
56
|
+
for prefs in (
|
|
57
|
+
app / "Contents" / "Resources" / "defaults" / "pref" / "channel-prefs.js",
|
|
58
|
+
app / "defaults" / "pref" / "channel-prefs.js",
|
|
59
|
+
):
|
|
60
|
+
try:
|
|
61
|
+
match = _CHANNEL_RE.search(prefs.read_text(encoding="utf-8", errors="replace"))
|
|
62
|
+
except OSError:
|
|
63
|
+
continue
|
|
64
|
+
if match:
|
|
65
|
+
return match.group(1)
|
|
66
|
+
return None
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def desktop_dirs() -> list[Path]:
|
|
70
|
+
"""``applications`` in each XDG data folder"""
|
|
71
|
+
home = Path(os.environ.get("XDG_DATA_HOME") or Path.home() / ".local" / "share")
|
|
72
|
+
shared = (os.environ.get("XDG_DATA_DIRS") or os.pathsep.join(("/usr/local/share", "/usr/share"))).split(os.pathsep)
|
|
73
|
+
found = []
|
|
74
|
+
for directory in (home, *(Path(path) for path in shared if path)):
|
|
75
|
+
if (directory / "applications").is_dir() and directory / "applications" not in found:
|
|
76
|
+
found.append(directory / "applications")
|
|
77
|
+
return found
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class BrowsersScanner:
|
|
81
|
+
name: ClassVar[str] = "browsers"
|
|
82
|
+
summary: ClassVar[str] = "Chrome, Brave, Firefox, and Edge"
|
|
83
|
+
sources: ClassVar[tuple[str, ...]] = ("browser",)
|
|
84
|
+
|
|
85
|
+
def __init__(self, dirs: Sequence[Path] | None = None, platform: str | None = None) -> None:
|
|
86
|
+
self.dirs, self.platform = dirs, platform
|
|
87
|
+
|
|
88
|
+
def available(self) -> bool:
|
|
89
|
+
platform = self.platform or sys.platform
|
|
90
|
+
return platform == "darwin" or platform.startswith("linux")
|
|
91
|
+
|
|
92
|
+
def scan(self) -> Iterable[Installed]:
|
|
93
|
+
platform = self.platform or sys.platform
|
|
94
|
+
found = self.scan_mac() if platform == "darwin" else self.scan_linux()
|
|
95
|
+
seen: set[str] = set()
|
|
96
|
+
for item in found:
|
|
97
|
+
if item.entry not in seen:
|
|
98
|
+
seen.add(item.entry)
|
|
99
|
+
yield item
|
|
100
|
+
|
|
101
|
+
def scan_mac(self) -> Iterable[Installed]:
|
|
102
|
+
for directory in app_dirs() if self.dirs is None else self.dirs:
|
|
103
|
+
for app in bundles(directory):
|
|
104
|
+
info = read_plist(app / "Contents" / "Info.plist")
|
|
105
|
+
browser = BUNDLE_IDS.get(_text(info, "CFBundleIdentifier") or "") if info else None
|
|
106
|
+
if browser is None or (browser == "firefox" and firefox_channel(app) not in (None, "release")):
|
|
107
|
+
continue
|
|
108
|
+
version = _text(info, "CFBundleShortVersionString")
|
|
109
|
+
yield Installed("browser", browser, NAMES[browser], comparable(browser, version), app.resolve())
|
|
110
|
+
|
|
111
|
+
def scan_linux(self) -> Iterable[Installed]:
|
|
112
|
+
for directory in desktop_dirs() if self.dirs is None else self.dirs:
|
|
113
|
+
for file, browser in DESKTOP_FILES.items():
|
|
114
|
+
if (directory / file).is_file():
|
|
115
|
+
yield Installed("browser", browser, NAMES[browser])
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Rust programs installed with ``cargo install``
|
|
2
|
+
|
|
3
|
+
cargo records them in ``.crates2.json`` in its install root: ``$CARGO_INSTALL_ROOT``, else ``$CARGO_HOME``, else ``~/.cargo``.
|
|
4
|
+
|
|
5
|
+
The file is read instead of running ``cargo install --list``
|
|
6
|
+
|
|
7
|
+
An install root set with ``install.root`` in a cargo config file isn't followed.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import re
|
|
15
|
+
import tomllib
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import ClassVar, Iterable
|
|
18
|
+
|
|
19
|
+
from .base import Installed
|
|
20
|
+
|
|
21
|
+
CRATES_IO = ("registry+https://github.com/rust-lang/crates.io-index", "sparse+https://index.crates.io/")
|
|
22
|
+
_PACKAGE_ID_RE = re.compile(r"^(?P<name>\S+) (?P<version>\S+) \((?P<source>[^)]*)\)$")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def install_root() -> Path:
|
|
26
|
+
for variable in ("CARGO_INSTALL_ROOT", "CARGO_HOME"):
|
|
27
|
+
if os.environ.get(variable):
|
|
28
|
+
return Path(os.environ[variable]).expanduser()
|
|
29
|
+
return Path.home() / ".cargo"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def package_ids(root: Path) -> list[str]:
|
|
33
|
+
"""The package ids cargo installed into ``root``"""
|
|
34
|
+
try:
|
|
35
|
+
text = (root / ".crates2.json").read_text(encoding="utf-8")
|
|
36
|
+
except OSError:
|
|
37
|
+
text = None
|
|
38
|
+
if text is not None:
|
|
39
|
+
try:
|
|
40
|
+
installs = json.loads(text).get("installs") if text.strip() else {}
|
|
41
|
+
except (ValueError, AttributeError):
|
|
42
|
+
installs = None
|
|
43
|
+
if isinstance(installs, dict):
|
|
44
|
+
return list(installs)
|
|
45
|
+
try:
|
|
46
|
+
v1 = tomllib.loads((root / ".crates.toml").read_text(encoding="utf-8")).get("v1")
|
|
47
|
+
except (OSError, ValueError):
|
|
48
|
+
return []
|
|
49
|
+
return list(v1) if isinstance(v1, dict) else []
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def parse_package_id(package_id: str) -> tuple[str, str] | None:
|
|
53
|
+
"""(name, version) of a crates.io package id"""
|
|
54
|
+
match = _PACKAGE_ID_RE.match(package_id)
|
|
55
|
+
if match is None or match["source"] not in CRATES_IO:
|
|
56
|
+
return None
|
|
57
|
+
return match["name"], match["version"]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class CargoScanner:
|
|
61
|
+
name: ClassVar[str] = "cargo"
|
|
62
|
+
summary: ClassVar[str] = "Rust programs installed with cargo install"
|
|
63
|
+
sources: ClassVar[tuple[str, ...]] = ("crates",)
|
|
64
|
+
|
|
65
|
+
def __init__(self, root: Path | None = None) -> None:
|
|
66
|
+
self.root = root
|
|
67
|
+
|
|
68
|
+
def available(self) -> bool:
|
|
69
|
+
root = self.root or install_root()
|
|
70
|
+
return (root / ".crates2.json").is_file() or (root / ".crates.toml").is_file()
|
|
71
|
+
|
|
72
|
+
def scan(self) -> Iterable[Installed]:
|
|
73
|
+
for package_id in package_ids(self.root or install_root()):
|
|
74
|
+
found = parse_package_id(package_id)
|
|
75
|
+
if found is not None:
|
|
76
|
+
yield Installed("crates", found[0], found[0], found[1])
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
""".NET tools installed with ``dotnet tool install -g``
|
|
2
|
+
|
|
3
|
+
``dotnet tool list -g --format json`` gives each tool's NuGet package id and version
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import shutil
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import ClassVar, Iterable
|
|
13
|
+
|
|
14
|
+
from .base import Installed, ScanError, run
|
|
15
|
+
|
|
16
|
+
ENV = {
|
|
17
|
+
"DOTNET_CLI_TELEMETRY_OPTOUT": "1",
|
|
18
|
+
"DOTNET_NOLOGO": "1",
|
|
19
|
+
"DOTNET_SKIP_FIRST_TIME_EXPERIENCE": "1",
|
|
20
|
+
"DOTNET_GENERATE_ASPNET_CERTIFICATE": "false",
|
|
21
|
+
"DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_DISABLE": "1",
|
|
22
|
+
"DOTNET_CLI_UI_LANGUAGE": "en",
|
|
23
|
+
}
|
|
24
|
+
TIMEOUT = 60
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def tools_dir() -> Path:
|
|
28
|
+
"""Where global tools go: ``.dotnet/tools`` in ``$DOTNET_CLI_HOME``, else the home folder"""
|
|
29
|
+
return Path(os.environ.get("DOTNET_CLI_HOME") or Path.home()) / ".dotnet" / "tools"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def parse_list(text: str) -> list[tuple[str, str | None]]:
|
|
33
|
+
"""(package id, version) from ``dotnet tool list --format json``"""
|
|
34
|
+
try:
|
|
35
|
+
doc = json.loads(text)
|
|
36
|
+
except ValueError as exc:
|
|
37
|
+
raise ScanError(f"`dotnet tool list -g --format json` gave something other than JSON: {exc}") from None
|
|
38
|
+
tools = doc.get("data") if isinstance(doc, dict) else None
|
|
39
|
+
found = []
|
|
40
|
+
for tool in tools if isinstance(tools, list) else ():
|
|
41
|
+
package, version = (tool.get("packageId"), tool.get("version")) if isinstance(tool, dict) else (None, None)
|
|
42
|
+
if isinstance(package, str) and package:
|
|
43
|
+
found.append((package, version if isinstance(version, str) and version else None))
|
|
44
|
+
return found
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class DotnetScanner:
|
|
48
|
+
name: ClassVar[str] = "dotnet"
|
|
49
|
+
summary: ClassVar[str] = ".NET tools installed globally"
|
|
50
|
+
sources: ClassVar[tuple[str, ...]] = ("nuget",)
|
|
51
|
+
|
|
52
|
+
def available(self) -> bool:
|
|
53
|
+
return shutil.which("dotnet") is not None and tools_dir().is_dir()
|
|
54
|
+
|
|
55
|
+
def dotnet(self, *args: str) -> str:
|
|
56
|
+
return run("dotnet", *args, timeout=TIMEOUT, env=ENV)
|
|
57
|
+
|
|
58
|
+
def scan(self) -> Iterable[Installed]:
|
|
59
|
+
for package, version in parse_list(self.dotnet("tool", "list", "-g", "--format", "json")):
|
|
60
|
+
yield Installed("nuget", package, package, version)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""Electron apps updated from GitHub releases
|
|
2
|
+
|
|
3
|
+
Apps built with electron-builder have ``app-update.yml``, what its updater (electron-updater) reads:
|
|
4
|
+
- macOS: ``Contents/Resources/app-update.yml`` in each app the apps scanner reads, not Setapp's (see macapps)
|
|
5
|
+
- Windows: ``resources\\app-update.yml`` in each folder of ``%LOCALAPPDATA%\\Programs`` (a per-user install) and the
|
|
6
|
+
Program Files folders
|
|
7
|
+
- Linux: ``resources/app-update.yml`` in each folder of ``/opt``, where its .deb and .rpm packages install
|
|
8
|
+
|
|
9
|
+
``provider: github`` names the repo (``owner``, ``repo``, and ``host`` for GitHub Enterprise), and its releases are the
|
|
10
|
+
app's. ``private: true`` needs a token so it's skipped. Other providers (generic, GitLab by project number, S3) aren't a source Youpdated has.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import re
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any, ClassVar, Iterable, Iterator, Sequence
|
|
20
|
+
|
|
21
|
+
import yaml
|
|
22
|
+
|
|
23
|
+
from .base import Installed
|
|
24
|
+
from .macapps import _text, app_dirs, bundles, read_plist
|
|
25
|
+
|
|
26
|
+
GITHUB = "github.com"
|
|
27
|
+
_SEGMENT_RE = re.compile(r"^[A-Za-z0-9._-]+$")
|
|
28
|
+
_HOST_RE = re.compile(r"^[A-Za-z0-9.-]+(?::\d+)?$")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def read_update_config(path: Path) -> dict[str, Any] | None:
|
|
32
|
+
try:
|
|
33
|
+
loaded = yaml.safe_load(path.read_text(encoding="utf-8"))
|
|
34
|
+
except (OSError, ValueError, yaml.YAMLError):
|
|
35
|
+
return None
|
|
36
|
+
return loaded if isinstance(loaded, dict) else None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def github_repo(config: dict[str, Any]) -> str | None:
|
|
40
|
+
"""``host/owner/repo`` of a public ``provider: github`` config"""
|
|
41
|
+
if config.get("provider") != "github" or config.get("private") is True:
|
|
42
|
+
return None
|
|
43
|
+
owner, repo = config.get("owner"), config.get("repo")
|
|
44
|
+
host = config.get("host") or GITHUB
|
|
45
|
+
if not all(isinstance(value, str) and _SEGMENT_RE.match(value) for value in (owner, repo)):
|
|
46
|
+
return None
|
|
47
|
+
if not isinstance(host, str) or not _HOST_RE.match(host):
|
|
48
|
+
return None
|
|
49
|
+
host = host.lower()
|
|
50
|
+
# the API's host, for github.com's
|
|
51
|
+
if host == f"api.{GITHUB}":
|
|
52
|
+
host = GITHUB
|
|
53
|
+
return f"{host}/{owner}/{repo}"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def program_dirs() -> list[Path]:
|
|
57
|
+
"""Folders apps install into, on this OS"""
|
|
58
|
+
if sys.platform == "win32":
|
|
59
|
+
candidates = [
|
|
60
|
+
Path(os.environ["LOCALAPPDATA"]) / "Programs" if os.environ.get("LOCALAPPDATA") else None,
|
|
61
|
+
*(Path(os.environ[name]) if os.environ.get(name) else None for name in ("PROGRAMFILES", "PROGRAMFILES(X86)")),
|
|
62
|
+
]
|
|
63
|
+
else:
|
|
64
|
+
candidates = [Path("/opt")]
|
|
65
|
+
found: list[Path] = []
|
|
66
|
+
for path in candidates:
|
|
67
|
+
if path is not None and path.is_dir() and path not in found:
|
|
68
|
+
found.append(path)
|
|
69
|
+
return found
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _children(directory: Path) -> list[Path]:
|
|
73
|
+
try:
|
|
74
|
+
return sorted(child for child in directory.iterdir() if child.is_dir())
|
|
75
|
+
except OSError:
|
|
76
|
+
return []
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class ElectronScanner:
|
|
80
|
+
name: ClassVar[str] = "electron"
|
|
81
|
+
summary: ClassVar[str] = "Electron apps updated from GitHub releases"
|
|
82
|
+
sources: ClassVar[tuple[str, ...]] = ("git",)
|
|
83
|
+
|
|
84
|
+
def __init__(self, dirs: Sequence[Path] | None = None, platform: str | None = None) -> None:
|
|
85
|
+
self.dirs, self.platform = dirs, platform
|
|
86
|
+
|
|
87
|
+
def available(self) -> bool:
|
|
88
|
+
if self.dirs is not None:
|
|
89
|
+
return bool(self.dirs)
|
|
90
|
+
return bool(app_dirs() if (self.platform or sys.platform) == "darwin" else program_dirs())
|
|
91
|
+
|
|
92
|
+
def scan(self) -> Iterable[Installed]:
|
|
93
|
+
seen: set[str] = set()
|
|
94
|
+
for item in self._finds():
|
|
95
|
+
if item.entry.lower() not in seen:
|
|
96
|
+
seen.add(item.entry.lower())
|
|
97
|
+
yield item
|
|
98
|
+
|
|
99
|
+
def _finds(self) -> Iterator[Installed]:
|
|
100
|
+
mac = (self.platform or sys.platform) == "darwin"
|
|
101
|
+
for directory in self.dirs if self.dirs is not None else (app_dirs() if mac else program_dirs()):
|
|
102
|
+
if mac:
|
|
103
|
+
for app in bundles(directory):
|
|
104
|
+
found = self.read_mac(app)
|
|
105
|
+
if found:
|
|
106
|
+
yield found
|
|
107
|
+
else:
|
|
108
|
+
for folder in _children(directory):
|
|
109
|
+
found = self.read_folder(folder)
|
|
110
|
+
if found:
|
|
111
|
+
yield found
|
|
112
|
+
|
|
113
|
+
def read_mac(self, app: Path) -> Installed | None:
|
|
114
|
+
config = read_update_config(app / "Contents" / "Resources" / "app-update.yml")
|
|
115
|
+
repo = github_repo(config) if config else None
|
|
116
|
+
if repo is None:
|
|
117
|
+
return None
|
|
118
|
+
info = read_plist(app / "Contents" / "Info.plist") or {}
|
|
119
|
+
name = _text(info, "CFBundleDisplayName", "CFBundleName") or app.stem
|
|
120
|
+
version = _text(info, "CFBundleShortVersionString", "CFBundleVersion")
|
|
121
|
+
return Installed("git", repo, name, version, app.resolve())
|
|
122
|
+
|
|
123
|
+
def read_folder(self, folder: Path) -> Installed | None:
|
|
124
|
+
config = read_update_config(folder / "resources" / "app-update.yml")
|
|
125
|
+
repo = github_repo(config) if config else None
|
|
126
|
+
return Installed("git", repo, folder.name, None, folder.resolve()) if repo else None
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Flatpak apps installed from Flathub
|
|
2
|
+
|
|
3
|
+
``flatpak list --app --columns=application,version,origin,name`` reads the local installations (system and user) and makes no requests.
|
|
4
|
+
|
|
5
|
+
Only ``origin`` == ``flathub`` is watchable. Other remotes aren't on Flathub's API.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import shutil
|
|
11
|
+
import sys
|
|
12
|
+
from typing import ClassVar, Iterable
|
|
13
|
+
|
|
14
|
+
from .base import Installed, run
|
|
15
|
+
|
|
16
|
+
ENV = {"FLATPAK_FANCY_OUTPUT": "0"}
|
|
17
|
+
TIMEOUT = 60
|
|
18
|
+
REMOTE = "flathub"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def parse_list(text: str) -> list[tuple[str, str | None, str, str | None]]:
|
|
22
|
+
"""(app id, version, origin, name) rows"""
|
|
23
|
+
rows = []
|
|
24
|
+
seen = set()
|
|
25
|
+
for line in text.splitlines():
|
|
26
|
+
cells = line.rstrip("\r").split("\t")
|
|
27
|
+
if len(cells) < 3 or not cells[0].strip():
|
|
28
|
+
continue
|
|
29
|
+
app, version, origin = (cell.strip() for cell in cells[:3])
|
|
30
|
+
name = cells[3].strip() if len(cells) > 3 else ""
|
|
31
|
+
if (app, origin) in seen:
|
|
32
|
+
continue
|
|
33
|
+
seen.add((app, origin))
|
|
34
|
+
rows.append((app, version or None, origin, name or None))
|
|
35
|
+
return rows
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class FlatpakScanner:
|
|
39
|
+
name: ClassVar[str] = "flatpak"
|
|
40
|
+
summary: ClassVar[str] = "Flatpak apps from Flathub"
|
|
41
|
+
sources: ClassVar[tuple[str, ...]] = ("flathub",)
|
|
42
|
+
|
|
43
|
+
def available(self) -> bool:
|
|
44
|
+
return sys.platform.startswith("linux") and shutil.which("flatpak") is not None
|
|
45
|
+
|
|
46
|
+
def flatpak(self, *args: str) -> str:
|
|
47
|
+
return run("flatpak", *args, timeout=TIMEOUT, env=ENV)
|
|
48
|
+
|
|
49
|
+
def scan(self) -> Iterable[Installed]:
|
|
50
|
+
listed = self.flatpak("list", "--app", "--columns=application,version,origin,name")
|
|
51
|
+
for app, version, origin, name in parse_list(listed):
|
|
52
|
+
if origin == REMOTE:
|
|
53
|
+
yield Installed("flathub", app, name or app, version)
|