forked from Shinonome/caelestia-cli
shell: filter log
This commit is contained in:
@@ -28,6 +28,7 @@ set -l not_seen "$seen shell && not $seen $commands"
|
|||||||
complete -c caelestia -n $not_seen -s 'd' -l 'daemon' -d 'Start the shell detached'
|
complete -c caelestia -n $not_seen -s 'd' -l 'daemon' -d 'Start the shell detached'
|
||||||
complete -c caelestia -n $not_seen -s 's' -l 'show' -d 'Print all IPC commands'
|
complete -c caelestia -n $not_seen -s 's' -l 'show' -d 'Print all IPC commands'
|
||||||
complete -c caelestia -n $not_seen -s 'l' -l 'log' -d 'Print the shell log'
|
complete -c caelestia -n $not_seen -s 'l' -l 'log' -d 'Print the shell log'
|
||||||
|
complete -c caelestia -n $not_seen -l 'log-rules' -d 'Log rules to apply'
|
||||||
complete -c caelestia -n $not_seen -a 'mpris' -d 'Mpris control'
|
complete -c caelestia -n $not_seen -a 'mpris' -d 'Mpris control'
|
||||||
complete -c caelestia -n $not_seen -a 'drawers' -d 'Toggle drawers'
|
complete -c caelestia -n $not_seen -a 'drawers' -d 'Toggle drawers'
|
||||||
complete -c caelestia -n $not_seen -a 'wallpaper' -d 'Wallpaper control (for internal use)'
|
complete -c caelestia -n $not_seen -a 'wallpaper' -d 'Wallpaper control (for internal use)'
|
||||||
|
|||||||
@@ -20,13 +20,12 @@ def parse_args() -> (argparse.ArgumentParser, argparse.Namespace):
|
|||||||
shell_parser.add_argument("message", nargs="*", help="a message to send to the shell")
|
shell_parser.add_argument("message", nargs="*", help="a message to send to the shell")
|
||||||
shell_parser.add_argument("-d", "--daemon", action="store_true", help="start the shell detached")
|
shell_parser.add_argument("-d", "--daemon", action="store_true", help="start the shell detached")
|
||||||
shell_parser.add_argument("-s", "--show", action="store_true", help="print all shell IPC commands")
|
shell_parser.add_argument("-s", "--show", action="store_true", help="print all shell IPC commands")
|
||||||
|
shell_parser.add_argument("-l", "--log", action="store_true", help="print the shell log")
|
||||||
shell_parser.add_argument(
|
shell_parser.add_argument(
|
||||||
"-l",
|
"--log-rules",
|
||||||
"--log",
|
default="quickshell.dbus.properties.warning=false;quickshell.dbus.dbusmenu.warning=false;quickshell.service.notifications.warning=false;quickshell.service.sni.host.warning=false",
|
||||||
nargs="?",
|
|
||||||
const="quickshell.dbus.properties.warning=false;quickshell.dbus.dbusmenu.warning=false;quickshell.service.notifications.warning=false;quickshell.service.sni.host.warning=false",
|
|
||||||
metavar="RULES",
|
metavar="RULES",
|
||||||
help="print the shell log",
|
help="log rules to apply",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create parser for toggle opts
|
# Create parser for toggle opts
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
|
|
||||||
|
from caelestia.utils.paths import c_cache_dir
|
||||||
|
|
||||||
|
|
||||||
class Command:
|
class Command:
|
||||||
args: Namespace
|
args: Namespace
|
||||||
@@ -20,22 +22,33 @@ class Command:
|
|||||||
self.message(*self.args.message)
|
self.message(*self.args.message)
|
||||||
else:
|
else:
|
||||||
# Start the shell
|
# Start the shell
|
||||||
args = ["qs", "-n", "-c", "caelestia"]
|
args = ["qs", "-n", "-c", "caelestia", "--log-rules", self.args.log_rules]
|
||||||
if self.args.daemon:
|
if self.args.daemon:
|
||||||
args.append("-d")
|
args.append("-d")
|
||||||
subprocess.run(args)
|
subprocess.run(args)
|
||||||
|
else:
|
||||||
|
shell = subprocess.Popen(args, stdout=subprocess.PIPE, universal_newlines=True)
|
||||||
|
for line in shell.stdout:
|
||||||
|
if self.filter_log(line):
|
||||||
|
print(line, end="")
|
||||||
|
|
||||||
def shell(self, *args: list[str]) -> str:
|
def shell(self, *args: list[str]) -> str:
|
||||||
return subprocess.check_output(["qs", "-c", "caelestia", *args], text=True)
|
return subprocess.check_output(["qs", "-c", "caelestia", *args], text=True)
|
||||||
|
|
||||||
|
def filter_log(self, line: str) -> bool:
|
||||||
|
return (
|
||||||
|
"QProcess: Destroyed while process" not in line
|
||||||
|
and f"Cannot open: file://{c_cache_dir}/imagecache/" not in line
|
||||||
|
)
|
||||||
|
|
||||||
def print_ipc(self) -> None:
|
def print_ipc(self) -> None:
|
||||||
print(self.shell("ipc", "show"), end="")
|
print(self.shell("ipc", "show"), end="")
|
||||||
|
|
||||||
def print_log(self) -> None:
|
def print_log(self) -> None:
|
||||||
log = self.shell("log")
|
log = self.shell("log", "-r", self.args.log_rules)
|
||||||
# FIXME: remove when logging rules are added/warning is removed
|
# FIXME: remove when logging rules are added/warning is removed
|
||||||
for line in log.splitlines():
|
for line in log.splitlines():
|
||||||
if "QProcess: Destroyed while process" not in line:
|
if self.filter_log(line):
|
||||||
print(line)
|
print(line)
|
||||||
|
|
||||||
def message(self, *args: list[str]) -> None:
|
def message(self, *args: list[str]) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user