add format parameter to shell module
This commit is contained in:
parent
e85425c8c6
commit
2a432c6bb2
@ -8,6 +8,9 @@ import logging
|
|||||||
class Shell(IntervalModule):
|
class Shell(IntervalModule):
|
||||||
"""
|
"""
|
||||||
Shows output of shell command
|
Shows output of shell command
|
||||||
|
|
||||||
|
.. rubric:: Available formatters
|
||||||
|
* `{output}` — just the striped command output without newlines
|
||||||
"""
|
"""
|
||||||
|
|
||||||
color = "#FFFFFF"
|
color = "#FFFFFF"
|
||||||
@ -16,10 +19,12 @@ class Shell(IntervalModule):
|
|||||||
settings = (
|
settings = (
|
||||||
("command", "command to be executed"),
|
("command", "command to be executed"),
|
||||||
("color", "standard color"),
|
("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",)
|
required = ("command",)
|
||||||
|
format = "{command}"
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
retvalue, out, stderr = run_through_shell(self.command, enable_shell=True)
|
retvalue, out, stderr = run_through_shell(self.command, enable_shell=True)
|
||||||
@ -32,6 +37,8 @@ class Shell(IntervalModule):
|
|||||||
elif stderr:
|
elif stderr:
|
||||||
out = stderr
|
out = stderr
|
||||||
|
|
||||||
|
out = self.format.format(command=out)
|
||||||
|
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": out if out else "Command `%s` returned %d" % (self.command, retvalue),
|
"full_text": out if out else "Command `%s` returned %d" % (self.command, retvalue),
|
||||||
"color": self.color if retvalue == 0 else self.error_color
|
"color": self.color if retvalue == 0 else self.error_color
|
||||||
|
Loading…
Reference in New Issue
Block a user