Merge pull request #241 from Arvedui/format_param_shell

Add format parameter to shell module
This commit is contained in:
enkore 2015-09-10 12:59:45 +02:00
commit 73b6d96e20

View File

@ -2,12 +2,14 @@ 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
"""
color = "#FFFFFF"
@ -16,10 +18,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 = "{output}"
def run(self):
retvalue, out, stderr = run_through_shell(self.command, enable_shell=True)
@ -33,6 +37,6 @@ class Shell(IntervalModule):
out = stderr
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
}