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.
Merge branch 'master' into fix-nvidia
- Loading branch information
Showing
2 changed files
with
44 additions
and
69 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 |
---|---|---|
|
@@ -30,6 +30,9 @@ | |
@author frimdo [email protected] | ||
""" | ||
|
||
STRING_UNAVAILABLE = "external_script: N/A" | ||
STRING_ERROR = "external_script: error" | ||
|
||
|
||
class Py3status: | ||
""" | ||
|
@@ -41,34 +44,29 @@ class Py3status: | |
strip_output = False | ||
|
||
def external_script(self): | ||
if self.script_path: | ||
return_value = self.py3.command_output(self.script_path, shell=True) | ||
# this is a convenience cleanup code to avoid breaking i3bar which | ||
# does not support multi lines output | ||
if len(return_value.split('\n')) > 2: | ||
return_value = return_value.split('\n')[0] | ||
self.py3.notify_user( | ||
'Script {} output contains new lines.'.format( | ||
self.script_path) + | ||
' Only the first one is being displayed to avoid breaking your i3bar', | ||
rate_limit=None) | ||
elif return_value[-1] == '\n': | ||
return_value = return_value.rstrip('\n') | ||
|
||
if self.strip_output: | ||
return_value = return_value.strip() | ||
|
||
response = { | ||
'cached_until': self.py3.time_in(self.cache_timeout), | ||
'full_text': self.py3.safe_format(self.format, | ||
{'output': return_value}) | ||
if not self.script_path: | ||
return { | ||
'cached_until': self.py3.CACHE_FOREVER, | ||
'color': self.py3.COLOR_BAD, | ||
'full_text': STRING_UNAVAILABLE | ||
} | ||
else: | ||
response = { | ||
try: | ||
output = self.py3.command_output(self.script_path, shell=True) | ||
output = output.splitlines()[0] | ||
except: | ||
return { | ||
'cached_until': self.py3.time_in(self.cache_timeout), | ||
'full_text': '' | ||
'color': self.py3.COLOR_BAD, | ||
'full_text': STRING_ERROR | ||
} | ||
return response | ||
|
||
if self.strip_output: | ||
output = output.strip() | ||
|
||
return { | ||
'cached_until': self.py3.time_in(self.cache_timeout), | ||
'full_text': self.py3.safe_format(self.format, {'output': output}) | ||
} | ||
|
||
|
||
if __name__ == "__main__": | ||
|
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