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):
|
if len(required) != len(self.required):
|
||||||
raise ConfigMissingError(type(self).__name__, self.required-required)
|
raise ConfigMissingError(type(self).__name__, self.required-required)
|
||||||
|
|
||||||
|
self.__name__ = "{}.{}".format(self.__module__, self.__class__.__name__)
|
||||||
|
|
||||||
self.init()
|
self.init()
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
@ -111,6 +113,8 @@ class Module(SettingsBase):
|
|||||||
|
|
||||||
def inject(self, json):
|
def inject(self, json):
|
||||||
if self.output:
|
if self.output:
|
||||||
|
if "name" not in self.output:
|
||||||
|
self.output["name"] = self.__name__
|
||||||
json.insert(self.position, self.output)
|
json.insert(self.position, self.output)
|
||||||
|
|
||||||
class AsyncModule(Module):
|
class AsyncModule(Module):
|
||||||
|
@ -75,7 +75,6 @@ class BatteryChecker(IntervalModule):
|
|||||||
|
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": full_text,
|
"full_text": full_text,
|
||||||
"name": "pybattery",
|
|
||||||
"instance": self.battery_ident,
|
"instance": self.battery_ident,
|
||||||
"urgent": urgent,
|
"urgent": urgent,
|
||||||
"color": color
|
"color": color
|
||||||
|
@ -43,7 +43,6 @@ class Clock(IntervalModule):
|
|||||||
def run(self):
|
def run(self):
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": datetime.datetime.now().strftime(self.format),
|
"full_text": datetime.datetime.now().strftime(self.format),
|
||||||
"name": "pyclock",
|
|
||||||
"urgent": False,
|
"urgent": False,
|
||||||
"color": "#ffffff"
|
"color": "#ffffff"
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ class ModsDeChecker(IntervalModule):
|
|||||||
else:
|
else:
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text" : self.format.format(unread=unread),
|
"full_text" : self.format.format(unread=unread),
|
||||||
"name" : "modsde",
|
|
||||||
"urgent" : "true",
|
"urgent" : "true",
|
||||||
"color" : self.color
|
"color" : self.color
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,4 @@ class Regex(IntervalModule):
|
|||||||
match = self.re.search(f.read())
|
match = self.re.search(f.read())
|
||||||
self.output = self.output = {
|
self.output = self.output = {
|
||||||
"full_text" : self.format.format(*match.groups()),
|
"full_text" : self.format.format(*match.groups()),
|
||||||
"name" : "regex",
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user