From f6e9e4d456ff94494703c24635d4f391bd391876 Mon Sep 17 00:00:00 2001 From: Argish42 Date: Wed, 6 Aug 2014 23:57:06 +0200 Subject: [PATCH 1/3] Uptime --- i3pystatus/uptime.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 i3pystatus/uptime.py diff --git a/i3pystatus/uptime.py b/i3pystatus/uptime.py new file mode 100644 index 0000000..3127bec --- /dev/null +++ b/i3pystatus/uptime.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from i3pystatus import IntervalModule + +class Uptime(IntervalModule): + """ + Outputs Uptime + It's possible to include hours, minutes and seconds as: {h},{m} and {s} + """ + + settings = ( + ("format","Format string"), + ("color","String color"), + ("alert","If you want the string to change color"), + ("seconds_alert","How many seconds necessary to start the alert"), + ("color_alert","Alert color"), + ) + + file = "/proc/uptime" + format = "up {h} hours {m} min" + color = "#ffffff" + alert = False + seconds_alert = 3600 + color_alert = "#ff0000" + + def run(self): + with open(self.file,'r') as f: + data = f.read().split()[0] + seconds = float(data) + m, s = divmod(int(seconds), 60) + h, m = divmod(int(m), 60) + + if self.alert: + if seconds > self.seconds_alert: + self.color = self.color_alert + self.output = { + "full_text": self.format.format(h=h,m=m,s=s), + "color": self.color + } From 84ecfc46a062fcf902164e49854ebd405f0d672e Mon Sep 17 00:00:00 2001 From: Argish42 Date: Thu, 7 Aug 2014 11:05:13 +0200 Subject: [PATCH 2/3] TimeWrapper --- uptime.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 uptime.py diff --git a/uptime.py b/uptime.py new file mode 100644 index 0000000..1272b48 --- /dev/null +++ b/uptime.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from i3pystatus import IntervalModule, formatp +from i3pystatus.core.util import TimeWrapper + +class Uptime(IntervalModule): + """ + Outputs Uptime + """ + + settings = ( + ("format","Format string"), + ("color","String color"), + ("alert","If you want the string to change color"), + ("seconds_alert","How many seconds necessary to start the alert"), + ("color_alert","Alert color"), + ) + + file = "/proc/uptime" + format = "up {uptime}" + color = "#ffffff" + alert = False + seconds_alert = 3600 + 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"), + } + + if self.alert: + if seconds > self.seconds_alert: + self.color = self.color_alert + self.output = { + "full_text": formatp(self.format, **fdict), + "color": self.color + } From e2cb6b8d49f3cbb11996c41153e85600385193be Mon Sep 17 00:00:00 2001 From: Argish42 Date: Thu, 7 Aug 2014 11:08:22 +0200 Subject: [PATCH 3/3] TimeWrapper --- i3pystatus/uptime.py | 16 ++++++++-------- uptime.py | 40 ---------------------------------------- 2 files changed, 8 insertions(+), 48 deletions(-) delete mode 100644 uptime.py diff --git a/i3pystatus/uptime.py b/i3pystatus/uptime.py index 3127bec..1272b48 100644 --- a/i3pystatus/uptime.py +++ b/i3pystatus/uptime.py @@ -1,12 +1,12 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from i3pystatus import IntervalModule +from i3pystatus import IntervalModule, formatp +from i3pystatus.core.util import TimeWrapper class Uptime(IntervalModule): """ Outputs Uptime - It's possible to include hours, minutes and seconds as: {h},{m} and {s} """ settings = ( @@ -18,7 +18,7 @@ class Uptime(IntervalModule): ) file = "/proc/uptime" - format = "up {h} hours {m} min" + format = "up {uptime}" color = "#ffffff" alert = False seconds_alert = 3600 @@ -26,15 +26,15 @@ class Uptime(IntervalModule): def run(self): with open(self.file,'r') as f: - data = f.read().split()[0] - seconds = float(data) - m, s = divmod(int(seconds), 60) - h, m = divmod(int(m), 60) + seconds = float(f.read().split()[0]) + fdict = { + "uptime" : TimeWrapper(seconds, "%h:%m"), + } if self.alert: if seconds > self.seconds_alert: self.color = self.color_alert self.output = { - "full_text": self.format.format(h=h,m=m,s=s), + "full_text": formatp(self.format, **fdict), "color": self.color } diff --git a/uptime.py b/uptime.py deleted file mode 100644 index 1272b48..0000000 --- a/uptime.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from i3pystatus import IntervalModule, formatp -from i3pystatus.core.util import TimeWrapper - -class Uptime(IntervalModule): - """ - Outputs Uptime - """ - - settings = ( - ("format","Format string"), - ("color","String color"), - ("alert","If you want the string to change color"), - ("seconds_alert","How many seconds necessary to start the alert"), - ("color_alert","Alert color"), - ) - - file = "/proc/uptime" - format = "up {uptime}" - color = "#ffffff" - alert = False - seconds_alert = 3600 - 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"), - } - - if self.alert: - if seconds > self.seconds_alert: - self.color = self.color_alert - self.output = { - "full_text": formatp(self.format, **fdict), - "color": self.color - }