From 2a432c6bb2e62b39585f0b00214241547252ce81 Mon Sep 17 00:00:00 2001 From: Arvedui Date: Sun, 2 Aug 2015 19:00:42 +0200 Subject: [PATCH 1/3] add format parameter to shell module --- i3pystatus/shell.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/i3pystatus/shell.py b/i3pystatus/shell.py index 67f4637..90261fb 100644 --- a/i3pystatus/shell.py +++ b/i3pystatus/shell.py @@ -8,6 +8,9 @@ import logging class Shell(IntervalModule): """ Shows output of shell command + + .. rubric:: Available formatters + * `{output}` — just the striped command output without newlines """ color = "#FFFFFF" @@ -16,10 +19,12 @@ class Shell(IntervalModule): settings = ( ("command", "command to be executed"), ("color", "standard color"), - ("error_color", "color to use when non zero exit code is returned") + ("error_color", "color to use when non zero exit code is returned"), + "format" ) required = ("command",) + format = "{command}" def run(self): retvalue, out, stderr = run_through_shell(self.command, enable_shell=True) @@ -32,6 +37,8 @@ class Shell(IntervalModule): elif stderr: out = stderr + out = self.format.format(command=out) + self.output = { "full_text": out if out else "Command `%s` returned %d" % (self.command, retvalue), "color": self.color if retvalue == 0 else self.error_color From 05a9cd551e08185ff2846385622b1072010e1dbf Mon Sep 17 00:00:00 2001 From: Arvedui Date: Sun, 6 Sep 2015 14:01:42 +0200 Subject: [PATCH 2/3] fix docs code discrepancy and error reporting with non empty format strings --- i3pystatus/shell.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/i3pystatus/shell.py b/i3pystatus/shell.py index 90261fb..b015879 100644 --- a/i3pystatus/shell.py +++ b/i3pystatus/shell.py @@ -24,7 +24,7 @@ class Shell(IntervalModule): ) required = ("command",) - format = "{command}" + format = "{output}" def run(self): retvalue, out, stderr = run_through_shell(self.command, enable_shell=True) @@ -37,9 +37,7 @@ class Shell(IntervalModule): elif stderr: out = stderr - out = self.format.format(command=out) - self.output = { - "full_text": out if out else "Command `%s` returned %d" % (self.command, retvalue), + "full_text": self.format.format(output=out) if out else "Command `%s` returned %d" % (self.command, retvalue), "color": self.color if retvalue == 0 else self.error_color } From 97ea1f76d339e7abcc12b0da9e4888c9b703f51e Mon Sep 17 00:00:00 2001 From: Arvedui Date: Sun, 6 Sep 2015 14:43:18 +0200 Subject: [PATCH 3/3] fix docs build error --- i3pystatus/shell.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/i3pystatus/shell.py b/i3pystatus/shell.py index b015879..9961eac 100644 --- a/i3pystatus/shell.py +++ b/i3pystatus/shell.py @@ -2,14 +2,13 @@ from i3pystatus import IntervalModule from i3pystatus.core.command import run_through_shell import logging -# logger = logging.getLogger(__name__) - class Shell(IntervalModule): """ Shows output of shell command .. rubric:: Available formatters + * `{output}` — just the striped command output without newlines """