From 1334eded622aad15b85cf313360d237d540786e7 Mon Sep 17 00:00:00 2001 From: Adam Fourney Date: Thu, 26 Sep 2024 11:24:16 -0700 Subject: [PATCH 1/2] Added an option to disable the loading of the help plugin. --- aprsd/conf/common.py | 5 +++++ aprsd/plugin.py | 6 +++++- aprsd/threads/rx.py | 18 ++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/aprsd/conf/common.py b/aprsd/conf/common.py index 89725b4..e6eee38 100644 --- a/aprsd/conf/common.py +++ b/aprsd/conf/common.py @@ -136,6 +136,11 @@ aprsd_opts = [ default=True, help="Set this to False, to disable logging of packets to the log file.", ), + cfg.BoolOpt( + "load_help_plugin", + default=True, + help="Set this to False to disable the help plugin.", + ), ] watch_list_opts = [ diff --git a/aprsd/plugin.py b/aprsd/plugin.py index 6c5f973..5574463 100644 --- a/aprsd/plugin.py +++ b/aprsd/plugin.py @@ -473,9 +473,13 @@ class PluginManager: del self._pluggy_pm self.setup_plugins() - def setup_plugins(self, load_help_plugin=True): + def setup_plugins(self, load_help_plugin=None): """Create the plugin manager and register plugins.""" + # If load_help_plugin is not specified, load it from the config + if load_help_plugin is None: + load_help_plugin = CONF.load_help_plugin + LOG.info("Loading APRSD Plugins") # Help plugin is always enabled. if load_help_plugin: diff --git a/aprsd/threads/rx.py b/aprsd/threads/rx.py index 3c88958..4002541 100644 --- a/aprsd/threads/rx.py +++ b/aprsd/threads/rx.py @@ -328,8 +328,22 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread): # If the message was for us and we didn't have a # response, then we send a usage statement. if to_call == CONF.callsign and not replied: - LOG.warning("Sending help!") - message_text = "Unknown command! Send 'help' message for help" + + # Is the help plugin installed? + help_available = False + for p in pm.get_message_plugins(): + if isinstance(p, plugin.HelpPlugin): + help_available = True + break + + # Tailor the messages accordingly + if help_available: + LOG.warning("Sending help!") + message_text = "Unknown command! Send 'help' message for help" + else: + LOG.warning("Unknown command!") + message_text = "Unknown command!" + tx.send( packets.MessagePacket( from_call=CONF.callsign, From 24714923be4c55fdac434a868707e917b6ed21b1 Mon Sep 17 00:00:00 2001 From: Adam Fourney Date: Mon, 11 Nov 2024 20:49:23 -0800 Subject: [PATCH 2/2] Addressing comments in PR. --- aprsd/cmds/dev.py | 2 +- aprsd/cmds/server.py | 2 +- aprsd/plugin.py | 2 +- aprsd/threads/rx.py | 9 +-------- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/aprsd/cmds/dev.py b/aprsd/cmds/dev.py index 0754b6d..dc760e8 100644 --- a/aprsd/cmds/dev.py +++ b/aprsd/cmds/dev.py @@ -101,7 +101,7 @@ def test_plugin( pm = plugin.PluginManager() if load_all: - pm.setup_plugins() + pm.setup_plugins(load_help_plugin=CONF.load_help_plugin) obj = pm._create_class(plugin_path, plugin.APRSDPluginBase) if not obj: click.echo(ctx.get_help()) diff --git a/aprsd/cmds/server.py b/aprsd/cmds/server.py index 6f66ddb..176d592 100644 --- a/aprsd/cmds/server.py +++ b/aprsd/cmds/server.py @@ -65,7 +65,7 @@ def server(ctx, flush): # log file output. LOG.info("Loading Plugin Manager and registering plugins") plugin_manager = plugin.PluginManager() - plugin_manager.setup_plugins() + plugin_manager.setup_plugins(load_help_plugin=CONF.load_help_plugin) # Dump all the config options now. CONF.log_opt_values(LOG, logging.DEBUG) diff --git a/aprsd/plugin.py b/aprsd/plugin.py index 9a8ae64..20d8d5e 100644 --- a/aprsd/plugin.py +++ b/aprsd/plugin.py @@ -470,7 +470,7 @@ class PluginManager: def reload_plugins(self): with self.lock: del self._pluggy_pm - self.setup_plugins() + self.setup_plugins(load_help_plugin=CONF.load_help_plugin) def setup_plugins( self, load_help_plugin=True, diff --git a/aprsd/threads/rx.py b/aprsd/threads/rx.py index 444aff8..b75f520 100644 --- a/aprsd/threads/rx.py +++ b/aprsd/threads/rx.py @@ -334,15 +334,8 @@ class APRSDPluginProcessPacketThread(APRSDProcessPacketThread): # response, then we send a usage statement. if to_call == CONF.callsign and not replied: - # Is the help plugin installed? - help_available = False - for p in pm.get_message_plugins(): - if isinstance(p, plugin.HelpPlugin): - help_available = True - break - # Tailor the messages accordingly - if help_available: + if CONF.load_help_plugin: LOG.warning("Sending help!") message_text = "Unknown command! Send 'help' message for help" else: