From c96410e92d5a4c883b7bda88daaea58bfff3e2d1 Mon Sep 17 00:00:00 2001 From: enkore Date: Sat, 23 Feb 2013 20:52:07 +0100 Subject: [PATCH] Automagic name attribute in JSON output If name is not set by the module, it's set automatically to the fully qualified python dotted path to the module :-) --- i3pystatus/__init__.py | 4 ++++ i3pystatus/batterychecker.py | 1 - i3pystatus/clock.py | 1 - i3pystatus/modsde.py | 1 - i3pystatus/regex.py | 1 - 5 files changed, 4 insertions(+), 4 deletions(-) diff --git a/i3pystatus/__init__.py b/i3pystatus/__init__.py index 9242ed9..4b8496c 100644 --- a/i3pystatus/__init__.py +++ b/i3pystatus/__init__.py @@ -95,6 +95,8 @@ class SettingsBase: if len(required) != len(self.required): raise ConfigMissingError(type(self).__name__, self.required-required) + self.__name__ = "{}.{}".format(self.__module__, self.__class__.__name__) + self.init() def init(self): @@ -111,6 +113,8 @@ class Module(SettingsBase): def inject(self, json): if self.output: + if "name" not in self.output: + self.output["name"] = self.__name__ json.insert(self.position, self.output) class AsyncModule(Module): diff --git a/i3pystatus/batterychecker.py b/i3pystatus/batterychecker.py index 3f05190..ac98493 100644 --- a/i3pystatus/batterychecker.py +++ b/i3pystatus/batterychecker.py @@ -75,7 +75,6 @@ class BatteryChecker(IntervalModule): self.output = { "full_text": full_text, - "name": "pybattery", "instance": self.battery_ident, "urgent": urgent, "color": color diff --git a/i3pystatus/clock.py b/i3pystatus/clock.py index e450ed2..3eb3fc9 100644 --- a/i3pystatus/clock.py +++ b/i3pystatus/clock.py @@ -43,7 +43,6 @@ class Clock(IntervalModule): def run(self): self.output = { "full_text": datetime.datetime.now().strftime(self.format), - "name": "pyclock", "urgent": False, "color": "#ffffff" } diff --git a/i3pystatus/modsde.py b/i3pystatus/modsde.py index b9d8f2b..5b35b08 100644 --- a/i3pystatus/modsde.py +++ b/i3pystatus/modsde.py @@ -46,7 +46,6 @@ class ModsDeChecker(IntervalModule): else: self.output = { "full_text" : self.format.format(unread=unread), - "name" : "modsde", "urgent" : "true", "color" : self.color } diff --git a/i3pystatus/regex.py b/i3pystatus/regex.py index b65d254..6061369 100644 --- a/i3pystatus/regex.py +++ b/i3pystatus/regex.py @@ -25,5 +25,4 @@ class Regex(IntervalModule): match = self.re.search(f.read()) self.output = self.output = { "full_text" : self.format.format(*match.groups()), - "name" : "regex", } \ No newline at end of file