From 5a7f4b5dc1ee9ff454f0a055d413cba2f803923d Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Thu, 25 Jan 2024 17:47:36 -0800 Subject: delete some unused code --- tools/waybar-systemd-units/waybar-systemd.py | 75 ---------------------------- 1 file changed, 75 deletions(-) delete mode 100755 tools/waybar-systemd-units/waybar-systemd.py (limited to 'tools/waybar-systemd-units/waybar-systemd.py') diff --git a/tools/waybar-systemd-units/waybar-systemd.py b/tools/waybar-systemd-units/waybar-systemd.py deleted file mode 100755 index de5c2e0..0000000 --- a/tools/waybar-systemd-units/waybar-systemd.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python3 -import json -import subprocess -from typing import List - -import click - - -def _get_failed_units(cmd) -> List[str]: - res = subprocess.run(cmd, capture_output=True, check=True) - if res.returncode == 0: - units = json.loads(res.stdout) - return [unit.get("unit") for unit in units] - else: - click.echo(f"failed to run {cmd}", err=True) - return [] - - -@click.command() -@click.version_option(version="0.1.0") -def cli() -> int: - """ - Get a list of systemd units (system and users) that have - failed, and print the output in JSON, in a format compatible to - waybar. - """ - failed_system_units = _get_failed_units( - [ - "systemctl", - "list-units", - "-o", - "json", - "--state=failed", - ], - ) - - failed_user_units = _get_failed_units( - [ - "systemctl", - "--user", - "list-units", - "-o", - "json", - "--state=failed", - ], - ) - - failed_units = len(failed_user_units) + len(failed_system_units) - - # The output format documentation: - # https://github.com/Alexays/Waybar/wiki/Module:-Custom - output = {"text": failed_units, "class": "success"} - - if failed_units > 0: - output["class"] = "errors" - - tooltip = [] - - if len(failed_user_units) > 0: - tooltip.append("failed user units: {}".format(", ".join(failed_user_units))) - - if len(failed_system_units) > 0: - tooltip.append( - "failed system units: {}".format(", ".join(failed_system_units)) - ) - - output["tooltip"] = "\n".join(tooltip) - - click.echo(json.dumps(output)) - - return 0 - - -if __name__ == "__main__": - cli() -- cgit 1.4.1