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 :-)
This commit is contained in:
parent
13c684860d
commit
c96410e92d
@ -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):
|
||||
|
@ -75,7 +75,6 @@ class BatteryChecker(IntervalModule):
|
||||
|
||||
self.output = {
|
||||
"full_text": full_text,
|
||||
"name": "pybattery",
|
||||
"instance": self.battery_ident,
|
||||
"urgent": urgent,
|
||||
"color": color
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ class ModsDeChecker(IntervalModule):
|
||||
else:
|
||||
self.output = {
|
||||
"full_text" : self.format.format(unread=unread),
|
||||
"name" : "modsde",
|
||||
"urgent" : "true",
|
||||
"color" : self.color
|
||||
}
|
||||
|
@ -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",
|
||||
}
|
Loading…
Reference in New Issue
Block a user