From 9dea4258a4fe6a6991d5f4e99c0cb00f961136f5 Mon Sep 17 00:00:00 2001 From: SyxbEaEQ2 Date: Fri, 24 Jul 2015 14:52:43 +0200 Subject: [PATCH] Added proper formatter for uptime module --- i3pystatus/uptime.py | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/i3pystatus/uptime.py b/i3pystatus/uptime.py index 6062a03..6027e0e 100644 --- a/i3pystatus/uptime.py +++ b/i3pystatus/uptime.py @@ -1,11 +1,18 @@ from i3pystatus import IntervalModule, formatp -from i3pystatus.core.util import TimeWrapper class Uptime(IntervalModule): """ 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 = ( @@ -17,18 +24,36 @@ class Uptime(IntervalModule): ) file = "/proc/uptime" - format = "up {uptime}" + format = "up {hours}:{mins}" color = "#ffffff" alert = False - seconds_alert = 3600 + seconds_alert = 60 * 60 * 24 * 30 # 30 days color_alert = "#ff0000" def run(self): with open(self.file, "r") as f: - seconds = float(f.read().split()[0]) - fdict = { - "uptime": TimeWrapper(seconds, "%h:%m"), - } + seconds = int(float(f.read().split()[0])) + + 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 seconds > self.seconds_alert: