diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-06-19 15:47:44 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-06-19 15:47:44 +1000 |
| commit | 0714622d09e764c82c9b748ce8845fdbc11608fb (patch) | |
| tree | 026e084e36a12e60fdd8e5fb2ffca80f924f047f /src/caelestia/subcommands/shell.py | |
| parent | screenshot: use shell for region (diff) | |
| download | caelestia-cli-0714622d09e764c82c9b748ce8845fdbc11608fb.tar.gz caelestia-cli-0714622d09e764c82c9b748ce8845fdbc11608fb.tar.bz2 caelestia-cli-0714622d09e764c82c9b748ce8845fdbc11608fb.zip | |
shell: filter log
Diffstat (limited to 'src/caelestia/subcommands/shell.py')
| -rw-r--r-- | src/caelestia/subcommands/shell.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/caelestia/subcommands/shell.py b/src/caelestia/subcommands/shell.py index e8017fe..fc3321b 100644 --- a/src/caelestia/subcommands/shell.py +++ b/src/caelestia/subcommands/shell.py @@ -1,6 +1,8 @@ import subprocess from argparse import Namespace +from caelestia.utils.paths import c_cache_dir + class Command: args: Namespace @@ -20,22 +22,33 @@ class Command: self.message(*self.args.message) else: # Start the shell - args = ["qs", "-n", "-c", "caelestia"] + args = ["qs", "-n", "-c", "caelestia", "--log-rules", self.args.log_rules] if self.args.daemon: 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: 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: print(self.shell("ipc", "show"), end="") 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 for line in log.splitlines(): - if "QProcess: Destroyed while process" not in line: + if self.filter_log(line): print(line) def message(self, *args: list[str]) -> None: |