forked from ultrabug/py3status
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
external_script and static_string modules code QA
- Loading branch information
Showing
2 changed files
with
31 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Display output of given script | ||
Display output of given script. | ||
Display output of any executable script set by script_path | ||
Pay attention. The output must be one liner, or will break your i3status | ||
The script should not have any parameters, but it could work | ||
Display output of any executable script set by 'script_path'. | ||
Pay attention. The output must be one liner, or will break your i3status ! | ||
The script should not have any parameters, but it could work. | ||
Configuration parameters: | ||
- cache_timeout : how often we refresh this module in seconds | ||
- script_path : script you want to show output of (compulsory) | ||
- color : color of printed text | ||
- on_click : read goo.gl/u10n0x | ||
- format : see placeholders below | ||
- script_path : script you want to show output of (compulsory) | ||
Format of status string placeholders: | ||
{output} - output of script given by "script_path" | ||
i3status.conf example: | ||
external_script { | ||
script_path = "/usr/bin/whoami" | ||
format = "my name is {output}" | ||
color = "#00FF00" | ||
format = "my name is {output}" | ||
script_path = "/usr/bin/whoami" | ||
@author frimdo [email protected] | ||
""" | ||
|
@@ -31,31 +30,32 @@ | |
|
||
|
||
class Py3status: | ||
""" | ||
""" | ||
# available configuration parameters | ||
cache_timeout = 15 | ||
format = '{output}' | ||
color = None | ||
format = '{output}' | ||
script_path = None | ||
|
||
def external_script(self, i3s_output_list, i3s_config): | ||
|
||
if self.script_path: | ||
|
||
return_value = subprocess.check_output(self.script_path, shell=True, universal_newlines=True) | ||
return_value = subprocess.check_output(self.script_path, | ||
shell=True, | ||
universal_newlines=True) | ||
response = { | ||
'cached_until': time() + self.cache_timeout, | ||
'full_text': self.format.format( | ||
output=return_value.rstrip()), | ||
'color': self.color | ||
} | ||
|
||
'color': self.color, | ||
'full_text': self.format.format(output=return_value.rstrip()) | ||
} | ||
else: | ||
response = { | ||
'cached_until': time() + self.cache_timeout, | ||
'full_text': "" | ||
'full_text': '' | ||
} | ||
|
||
return response | ||
|
||
|
||
if __name__ == "__main__": | ||
from time import sleep | ||
x = Py3status() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Display static text | ||
Display static text given by "format" parameter | ||
Display static text. | ||
Configuration parameters: | ||
- text : text that should be printed | ||
- separator : whether the separator is shown or not (True or False) | ||
- format : text that should be printed | ||
- color : color of printed text | ||
- on_click : read goo.gl/u10n0x | ||
- format : text that should be printed | ||
- separator : whether the separator is shown or not (true or false) | ||
@author frimdo [email protected] | ||
""" | ||
|
||
from time import time | ||
|
||
|
||
class Py3status: | ||
""" | ||
""" | ||
# available configuration parameters | ||
color = None | ||
format = '' | ||
separator = True | ||
|
||
def static_string(self, i3s_output_list, i3s_config): | ||
|
||
response = { | ||
'full_text': self.format, | ||
'cached_until': time() + 60, | ||
'color': self.color, | ||
'full_text': self.format, | ||
'separator': self.separator | ||
} | ||
|
||
} | ||
return response | ||
|
||
|
||
if __name__ == "__main__": | ||
x = Py3status() | ||
config = { | ||
|