From ec637f8423f50659debe9ae107a01470042c8e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Barcicki?= Date: Mon, 29 Dec 2025 12:27:56 +0100 Subject: [PATCH] [#85496] Prepare support for windows --- common.py | 3 +++ sargraph.py | 4 ++-- watch.py | 8 +++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/common.py b/common.py index 3a01b62..44d9be4 100644 --- a/common.py +++ b/common.py @@ -97,3 +97,6 @@ def is_version_ge(a, b): def is_darwin(): return platform.system() == 'Darwin' + +def is_windows(): + return platform.system() == 'Windows' \ No newline at end of file diff --git a/sargraph.py b/sargraph.py index f7ac1a8..1c79d21 100755 --- a/sargraph.py +++ b/sargraph.py @@ -50,7 +50,7 @@ def create_session(): fail(f"No device is mounted on {args.fspath}") params = (args.session, args.fsdev, args.iface, args.tmpfs, args.cache, args.udp, args.udp_cookie) - if is_darwin() or args.psutil: + if is_darwin() or args.psutil or is_windows(): watcher = watch.PsUtilWatcher(*params) else: watcher = watch.SarWatcher(*params) @@ -59,7 +59,7 @@ def create_session(): sys.exit(0) # Check if sar is available -if not is_darwin(): +if not (is_darwin() or is_windows()): p = run_or_fail("sar", "-V", stdout=subprocess.PIPE) if args.name != "data": diff --git a/watch.py b/watch.py index 0a628ae..e1a9726 100644 --- a/watch.py +++ b/watch.py @@ -102,8 +102,10 @@ def read_iface_stats(iface): return rx, tx def get_socket(session): - # TODO: when using on other platforms make sure this path exist; namely windows - path = f"/tmp/sargraph-{session}.sock" + if is_windows(): + path = fr"\\.\pipe\sargraph-{session}" + else: + path = f"/tmp/sargraph-{session}.sock" sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) return sock, path @@ -215,7 +217,7 @@ class Watcher(abc.ABC): used = (ram_data.total - ram_data.free) if used // 1024 > MAX_USED_RAM: MAX_USED_RAM = used // 1024 - if is_darwin(): + if isinstance(self, PsUtilWatcher): line = [ date + "-" + daytime, 100 * ram_data.free / ram_data.total,