Greater compatibility for *BSD

There are references to lsblk (from util-linux) and /proc that don't
exist on *BSD, so this expands on some macOS-specific code to
compensate for that
This commit is contained in:
Lydia Sobot 2026-04-07 19:06:42 +02:00
parent ede692925e
commit 84b05940cf
No known key found for this signature in database
3 changed files with 26 additions and 11 deletions

View file

@ -44,6 +44,14 @@ ANYWIN = WINDOWS or sys.platform in ["msys", "cygwin"]
MACOS = platform.system() == "Darwin" MACOS = platform.system() == "Darwin"
FREEBSD = platform.system() == "FreeBSD"
OPENBSD = platform.system() == "OpenBSD"
ANYBSD = FREEBSD or OPENBSD
UNIX = MACOS or ANYBSD
GRAAL = platform.python_implementation() == "GraalVM" GRAAL = platform.python_implementation() == "GraalVM"
EXE = bool(getattr(sys, "frozen", False)) EXE = bool(getattr(sys, "frozen", False))

View file

@ -7,7 +7,7 @@ import os
import re import re
import time import time
from .__init__ import ANYWIN, MACOS from .__init__ import ANYWIN, FREEBSD, MACOS, UNIX
from .authsrv import AXS, VFS, AuthSrv from .authsrv import AXS, VFS, AuthSrv
from .bos import bos from .bos import bos
from .util import chkcmd, json_hesc, min_ex, undot from .util import chkcmd, json_hesc, min_ex, undot
@ -88,7 +88,7 @@ class Fstab(object):
def _from_sp_mount(self) -> dict[str, str]: def _from_sp_mount(self) -> dict[str, str]:
sptn = r"^.*? on (.*) type ([^ ]+) \(.*" sptn = r"^.*? on (.*) type ([^ ]+) \(.*"
if MACOS: if MACOS or FREEBSD:
sptn = r"^.*? on (.*) \(([^ ]+), .*" sptn = r"^.*? on (.*) \(([^ ]+), .*"
ptn = re.compile(sptn) ptn = re.compile(sptn)
@ -118,7 +118,7 @@ class Fstab(object):
def build_tab(self) -> None: def build_tab(self) -> None:
self.log("inspecting mtab for changes") self.log("inspecting mtab for changes")
dtab = self._from_sp_mount() if MACOS else self._from_proc() dtab = self._from_sp_mount() if UNIX else self._from_proc()
# keep empirically-correct values if mounttab unchanged # keep empirically-correct values if mounttab unchanged
srctab = str(sorted(dtab.items())) srctab = str(sorted(dtab.items()))
@ -130,7 +130,7 @@ class Fstab(object):
try: try:
fuses = [mp for mp, fs in dtab.items() if fs == "fuseblk"] fuses = [mp for mp, fs in dtab.items() if fs == "fuseblk"]
if not fuses or MACOS: if not fuses or UNIX:
raise Exception() raise Exception()
try: try:
so, _ = chkcmd(["lsblk", "-nrfo", "FSTYPE,MOUNTPOINT"]) # centos6 so, _ = chkcmd(["lsblk", "-nrfo", "FSTYPE,MOUNTPOINT"]) # centos6

View file

@ -7,7 +7,7 @@ import socket
import sys import sys
import time import time
from .__init__ import ANYWIN, PY2, TYPE_CHECKING, unicode from .__init__ import ANYWIN, OPENBSD, PY2, TYPE_CHECKING, UNIX, unicode
from .cert import gencert from .cert import gencert
from .qrkode import QrCode, qr2png, qr2svg, qr2txt, qrgen from .qrkode import QrCode, qr2png, qr2svg, qr2txt, qrgen
from .util import ( from .util import (
@ -510,6 +510,13 @@ class TcpSrv(object):
return eps return eps
def _extdevs_nix(self) -> Generator[str, None, None]: def _extdevs_nix(self) -> Generator[str, None, None]:
if UNIX:
so, _ = chkcmd(["netstat", "-nrf", "inet"])
for ln in so.split("\n"):
if not ln.startswith("default"):
continue
yield ln.split()[7] if OPENBSD else ln.split()[3]
else:
with open("/proc/net/route", "rb") as f: with open("/proc/net/route", "rb") as f:
next(f) next(f)
for ln in f: for ln in f: