mirror of
https://github.com/craigerl/aprsd.git
synced 2025-07-31 12:52:24 -04:00
Fixed notify plugins
The notify base filter() was missing the @hookimpl
This commit is contained in:
parent
491644ece6
commit
e3c5c7b408
@ -17,9 +17,6 @@ from aprsd import client, messaging, packets, threads
|
|||||||
# setup the global logger
|
# setup the global logger
|
||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
|
|
||||||
hookspec = pluggy.HookspecMarker("aprsd")
|
|
||||||
hookimpl = pluggy.HookimplMarker("aprsd")
|
|
||||||
|
|
||||||
CORE_MESSAGE_PLUGINS = [
|
CORE_MESSAGE_PLUGINS = [
|
||||||
"aprsd.plugins.email.EmailPlugin",
|
"aprsd.plugins.email.EmailPlugin",
|
||||||
"aprsd.plugins.fortune.FortunePlugin",
|
"aprsd.plugins.fortune.FortunePlugin",
|
||||||
@ -36,8 +33,11 @@ CORE_NOTIFY_PLUGINS = [
|
|||||||
"aprsd.plugins.notify.NotifySeenPlugin",
|
"aprsd.plugins.notify.NotifySeenPlugin",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
hookspec = pluggy.HookspecMarker("aprsd")
|
||||||
|
hookimpl = pluggy.HookimplMarker("aprsd")
|
||||||
|
|
||||||
class APRSDCommandSpec:
|
|
||||||
|
class APRSDPluginSpec:
|
||||||
"""A hook specification namespace."""
|
"""A hook specification namespace."""
|
||||||
|
|
||||||
@hookspec
|
@hookspec
|
||||||
@ -62,11 +62,8 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
|
|||||||
self.config = config
|
self.config = config
|
||||||
self.message_counter = 0
|
self.message_counter = 0
|
||||||
self.setup()
|
self.setup()
|
||||||
threads = self.create_threads()
|
self.threads = self.create_threads()
|
||||||
if threads:
|
self.start_threads()
|
||||||
self.threads = threads
|
|
||||||
if self.threads:
|
|
||||||
self.start_threads()
|
|
||||||
|
|
||||||
def start_threads(self):
|
def start_threads(self):
|
||||||
if self.enabled and self.threads:
|
if self.enabled and self.threads:
|
||||||
@ -96,11 +93,6 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
|
|||||||
def message_count(self):
|
def message_count(self):
|
||||||
return self.message_counter
|
return self.message_counter
|
||||||
|
|
||||||
@property
|
|
||||||
def version(self):
|
|
||||||
"""Version"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def setup(self):
|
def setup(self):
|
||||||
"""Do any plugin setup here."""
|
"""Do any plugin setup here."""
|
||||||
@ -122,7 +114,6 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
|
|||||||
if isinstance(thread, threads.APRSDThread):
|
if isinstance(thread, threads.APRSDThread):
|
||||||
thread.stop()
|
thread.stop()
|
||||||
|
|
||||||
@hookimpl
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def filter(self, packet):
|
def filter(self, packet):
|
||||||
pass
|
pass
|
||||||
@ -164,14 +155,22 @@ class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
|
|||||||
else:
|
else:
|
||||||
LOG.warning("Watch list enabled, but no callsigns set.")
|
LOG.warning("Watch list enabled, but no callsigns set.")
|
||||||
|
|
||||||
|
@hookimpl
|
||||||
def filter(self, packet):
|
def filter(self, packet):
|
||||||
|
result = messaging.NULL_MESSAGE
|
||||||
if self.enabled:
|
if self.enabled:
|
||||||
wl = packets.WatchList()
|
wl = packets.WatchList()
|
||||||
result = messaging.NULL_MESSAGE
|
|
||||||
if wl.callsign_in_watchlist(packet["from"]):
|
if wl.callsign_in_watchlist(packet["from"]):
|
||||||
# packet is from a callsign in the watch list
|
# packet is from a callsign in the watch list
|
||||||
self.rx_inc()
|
self.rx_inc()
|
||||||
result = self.process()
|
try:
|
||||||
|
result = self.process(packet)
|
||||||
|
except Exception as ex:
|
||||||
|
LOG.error(
|
||||||
|
"Plugin {} failed to process packet {}".format(
|
||||||
|
self.__class__, ex,
|
||||||
|
),
|
||||||
|
)
|
||||||
if result:
|
if result:
|
||||||
self.tx_inc()
|
self.tx_inc()
|
||||||
wl.update_seen(packet)
|
wl.update_seen(packet)
|
||||||
@ -221,7 +220,14 @@ class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
|
|||||||
if re.search(self.command_regex, message):
|
if re.search(self.command_regex, message):
|
||||||
self.rx_inc()
|
self.rx_inc()
|
||||||
if self.enabled:
|
if self.enabled:
|
||||||
result = self.process(packet)
|
try:
|
||||||
|
result = self.process(packet)
|
||||||
|
except Exception as ex:
|
||||||
|
LOG.error(
|
||||||
|
"Plugin {} failed to process packet {}".format(
|
||||||
|
self.__class__, ex,
|
||||||
|
),
|
||||||
|
)
|
||||||
if result:
|
if result:
|
||||||
self.tx_inc()
|
self.tx_inc()
|
||||||
else:
|
else:
|
||||||
@ -255,6 +261,10 @@ class PluginManager:
|
|||||||
if config:
|
if config:
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
|
def _init(self):
|
||||||
|
self._pluggy_pm = pluggy.PluginManager("aprsd")
|
||||||
|
self._pluggy_pm.add_hookspecs(APRSDPluginSpec)
|
||||||
|
|
||||||
def load_plugins_from_path(self, module_path):
|
def load_plugins_from_path(self, module_path):
|
||||||
if not os.path.exists(module_path):
|
if not os.path.exists(module_path):
|
||||||
LOG.error(f"plugin path '{module_path}' doesn't exist.")
|
LOG.error(f"plugin path '{module_path}' doesn't exist.")
|
||||||
@ -356,8 +366,7 @@ class PluginManager:
|
|||||||
|
|
||||||
LOG.info("Loading APRSD Plugins")
|
LOG.info("Loading APRSD Plugins")
|
||||||
enabled_plugins = self.config["aprsd"].get("enabled_plugins", None)
|
enabled_plugins = self.config["aprsd"].get("enabled_plugins", None)
|
||||||
self._pluggy_pm = pluggy.PluginManager("aprsd")
|
self._init()
|
||||||
self._pluggy_pm.add_hookspecs(APRSDCommandSpec)
|
|
||||||
if enabled_plugins:
|
if enabled_plugins:
|
||||||
for p_name in enabled_plugins:
|
for p_name in enabled_plugins:
|
||||||
self._load_plugin(p_name)
|
self._load_plugin(p_name)
|
||||||
|
@ -17,12 +17,8 @@ class NotifySeenPlugin(plugin.APRSDWatchListPluginBase):
|
|||||||
|
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|
||||||
def __init__(self, config):
|
|
||||||
"""The aprsd config object is stored."""
|
|
||||||
super().__init__(config)
|
|
||||||
|
|
||||||
def process(self, packet):
|
def process(self, packet):
|
||||||
LOG.info("BaseNotifyPlugin")
|
LOG.info("NotifySeenPlugin")
|
||||||
|
|
||||||
notify_callsign = self.config["aprsd"]["watch_list"]["alert_callsign"]
|
notify_callsign = self.config["aprsd"]["watch_list"]["alert_callsign"]
|
||||||
fromcall = packet.get("from")
|
fromcall = packet.get("from")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user