Merge pull request #230 from SyxbEaEQ2/uptime_format
Added proper formatter for uptime module
This commit is contained in:
commit
50d396d761
@ -1,11 +1,18 @@
|
|||||||
|
|
||||||
from i3pystatus import IntervalModule, formatp
|
from i3pystatus import IntervalModule, formatp
|
||||||
from i3pystatus.core.util import TimeWrapper
|
|
||||||
|
|
||||||
|
|
||||||
class Uptime(IntervalModule):
|
class Uptime(IntervalModule):
|
||||||
"""
|
"""
|
||||||
Outputs Uptime
|
Outputs Uptime
|
||||||
|
|
||||||
|
.. rubric:: Available formatters
|
||||||
|
|
||||||
|
* `{days}` - uptime in days
|
||||||
|
* `{hours}` - rest of uptime in hours
|
||||||
|
* `{mins}` - rest of uptime in minutes
|
||||||
|
* `{secs}` - rest of uptime in seconds
|
||||||
|
* `{uptime}` - deprecated: equals '`{hours}:{mins}`'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
settings = (
|
settings = (
|
||||||
@ -17,18 +24,36 @@ class Uptime(IntervalModule):
|
|||||||
)
|
)
|
||||||
|
|
||||||
file = "/proc/uptime"
|
file = "/proc/uptime"
|
||||||
format = "up {uptime}"
|
format = "up {hours}:{mins}"
|
||||||
color = "#ffffff"
|
color = "#ffffff"
|
||||||
alert = False
|
alert = False
|
||||||
seconds_alert = 3600
|
seconds_alert = 60 * 60 * 24 * 30 # 30 days
|
||||||
color_alert = "#ff0000"
|
color_alert = "#ff0000"
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
with open(self.file, "r") as f:
|
with open(self.file, "r") as f:
|
||||||
seconds = float(f.read().split()[0])
|
seconds = int(float(f.read().split()[0]))
|
||||||
fdict = {
|
|
||||||
"uptime": TimeWrapper(seconds, "%h:%m"),
|
days = seconds // (60 * 60 * 24)
|
||||||
}
|
hours = seconds // (60 * 60)
|
||||||
|
minutes = seconds // 60
|
||||||
|
if "{days}" in self.format:
|
||||||
|
hours = (seconds % (60 * 60 * 24)) // (60 * 60)
|
||||||
|
minutes = (seconds % (60 * 60 * 24)) // 60
|
||||||
|
seconds = (seconds % (60 * 60 * 24))
|
||||||
|
if "{hours}" in self.format:
|
||||||
|
minutes = (seconds % (60 * 60)) // 60
|
||||||
|
seconds = (seconds % (60 * 60))
|
||||||
|
if "{mins}" in self.format:
|
||||||
|
seconds = seconds % 60
|
||||||
|
|
||||||
|
fdict = {
|
||||||
|
"days": days,
|
||||||
|
"hours": hours,
|
||||||
|
"mins": minutes,
|
||||||
|
"secs": seconds,
|
||||||
|
"uptime": "{}:{}".format(hours, minutes),
|
||||||
|
}
|
||||||
|
|
||||||
if self.alert:
|
if self.alert:
|
||||||
if seconds > self.seconds_alert:
|
if seconds > self.seconds_alert:
|
||||||
|
Loading…
Reference in New Issue
Block a user