diff --git a/aprsd/dev.py b/aprsd/dev.py index 5c70835..f5d9528 100644 --- a/aprsd/dev.py +++ b/aprsd/dev.py @@ -14,7 +14,7 @@ import click_completion # local imports here import aprsd -from aprsd import client, email, plugin, utils +from aprsd import client, plugin, utils # setup the global logger @@ -192,15 +192,10 @@ def test_plugin( packet = {"from": fromcall, "message_text": message, "msgNo": 1} -<<<<<<< HEAD - reply = obj.run(packet) - LOG.info(f"Result = '{reply}'") -======= reply = obj.filter(packet) # Plugin might have threads, so lets stop them so we can exit. obj.stop_threads() - LOG.info("Result = '{}'".format(reply)) ->>>>>>> f8f84c4 (Added threads functions to APRSDPluginBase) + LOG.info(f"Result = '{reply}'") if __name__ == "__main__": diff --git a/aprsd/main.py b/aprsd/main.py index 8403e69..1e1c3c6 100644 --- a/aprsd/main.py +++ b/aprsd/main.py @@ -37,8 +37,7 @@ import click_completion # local imports here import aprsd from aprsd import ( - client, email, flask, messaging, packets, plugin, stats, threads, trace, - utils, + client, flask, messaging, packets, plugin, stats, threads, trace, utils, ) diff --git a/aprsd/plugin.py b/aprsd/plugin.py index 14601c2..b67898d 100644 --- a/aprsd/plugin.py +++ b/aprsd/plugin.py @@ -8,10 +8,11 @@ import os import re import threading -from aprsd import messaging, packets, threads import pluggy from thesmuggler import smuggle +from aprsd import messaging, packets, threads + # setup the global logger LOG = logging.getLogger("APRSD") @@ -98,7 +99,6 @@ class APRSDPluginBase(metaclass=abc.ABCMeta): def setup(self): """Do any plugin setup here.""" - pass def create_threads(self): """Gives the plugin writer the ability start a background thread.""" @@ -124,7 +124,6 @@ class APRSDPluginBase(metaclass=abc.ABCMeta): @abc.abstractmethod def process(self, packet): """This is called when the filter passes.""" - pass class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta): @@ -153,15 +152,7 @@ class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta): return result -<<<<<<< HEAD - This will get called when a packet is seen by a callsign - registered in the watch list in the config file.""" - - -class APRSDMessagePluginBase(metaclass=abc.ABCMeta): -======= class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta): ->>>>>>> 2e7c884 (Refactor Message processing and MORE) """Base Message plugin class. When you want to search for a particular command in an @@ -200,13 +191,7 @@ class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta): if result: self.tx_inc() -<<<<<<< HEAD - To reply with a message over the air, return a string - to send. - """ -======= return result ->>>>>>> 2e7c884 (Refactor Message processing and MORE) class PluginManager: diff --git a/aprsd/plugins/email.py b/aprsd/plugins/email.py index 317eb37..2af05c6 100644 --- a/aprsd/plugins/email.py +++ b/aprsd/plugins/email.py @@ -7,10 +7,11 @@ import re import smtplib import time -from aprsd import messaging, plugin, stats, threads, trace import imapclient from validate_email import validate_email +from aprsd import messaging, plugin, stats, threads, trace + LOG = logging.getLogger("APRSD") @@ -171,7 +172,7 @@ def _imap_connect(): ) except (imaplib.IMAP4.error, Exception) as e: msg = getattr(e, "message", repr(e)) - LOG.error("Failed to login {}".format(msg)) + LOG.error(f"Failed to login {msg}") return server.select_folder("INBOX") @@ -213,7 +214,7 @@ def _smtp_connect(): LOG.error("Couldn't connect to SMTP Server") return - LOG.debug("Connected to smtp host {}".format(msg)) + LOG.debug(f"Connected to smtp host {msg}") debug = CONFIG["aprsd"]["email"]["smtp"].get("debug", False) if debug: @@ -229,7 +230,7 @@ def _smtp_connect(): LOG.error("Couldn't connect to SMTP Server") return - LOG.debug("Logged into SMTP server {}".format(msg)) + LOG.debug(f"Logged into SMTP server {msg}") return server @@ -244,7 +245,7 @@ def validate_shortcuts(config): ) delete_keys = [] for key in shortcuts: - LOG.info("Validating {}:{}".format(key, shortcuts[key])) + LOG.info(f"Validating {key}:{shortcuts[key]}") is_valid = validate_email( email_address=shortcuts[key], check_regex=True, @@ -313,7 +314,7 @@ def parse_email(msgid, data, server): from_addr = f.group(1) else: from_addr = "noaddr" - LOG.debug("Got a message from '{}'".format(from_addr)) + LOG.debug(f"Got a message from '{from_addr}'") try: m = server.fetch([msgid], ["RFC822"]) except Exception as e: @@ -447,7 +448,7 @@ def resend_email(count, fromcall): month = date.strftime("%B")[:3] # Nov, Mar, Apr day = date.day year = date.year - today = "{}-{}-{}".format(day, month, year) + today = f"{day}-{month}-{year}" shortcuts = CONFIG["aprsd"]["email"]["shortcuts"] # swap key/value @@ -564,7 +565,7 @@ class APRSDEmailThread(threads.APRSDThread): month = date.strftime("%B")[:3] # Nov, Mar, Apr day = date.day year = date.year - today = "{}-{}-{}".format(day, month, year) + today = f"{day}-{month}-{year}" try: server = _imap_connect() @@ -580,7 +581,7 @@ class APRSDEmailThread(threads.APRSDThread): e, ) return True - LOG.debug("{} messages received today".format(len(messages))) + LOG.debug(f"{len(messages)} messages received today") try: _msgs = server.fetch(messages, ["ENVELOPE"]) diff --git a/aprsd/threads.py b/aprsd/threads.py index 0ae0ed3..4ad6be4 100644 --- a/aprsd/threads.py +++ b/aprsd/threads.py @@ -209,7 +209,7 @@ class APRSDRXThread(APRSDThread): msg = packet.get("message_text", None) msg_id = packet.get("msgNo", "0") msg_response = packet.get("response", None) - LOG.debug("Got packet from '{}' - {}".format(fromcall, packet)) + LOG.debug(f"Got packet from '{fromcall}' - {packet}") # We don't put ack packets destined for us through the # plugins. @@ -240,14 +240,14 @@ class APRSDRXThread(APRSDThread): pm = plugin.PluginManager() try: results = pm.run(packet) - LOG.debug("RESULTS {}".format(results)) + LOG.debug(f"RESULTS {results}") replied = False for reply in results: if isinstance(reply, list): # one of the plugins wants to send multiple messages replied = True for subreply in reply: - LOG.debug("Sending '{}'".format(subreply)) + LOG.debug(f"Sending '{subreply}'") msg = messaging.TextMessage( self.config["aprs"]["login"], @@ -263,7 +263,7 @@ class APRSDRXThread(APRSDThread): # nothing to reply with, so we avoid replying with a # usage string if reply is not messaging.NULL_MESSAGE: - LOG.debug("Sending '{}'".format(reply)) + LOG.debug(f"Sending '{reply}'") msg = messaging.TextMessage( self.config["aprs"]["login"], diff --git a/tests/fake.py b/tests/fake.py index 24c3ee1..a45ead3 100644 --- a/tests/fake.py +++ b/tests/fake.py @@ -1,5 +1,6 @@ from aprsd import packets, plugin, threads + FAKE_MESSAGE_TEXT = "fake MeSSage" FAKE_FROM_CALLSIGN = "KFART" FAKE_TO_CALLSIGN = "KMINE" diff --git a/tox.ini b/tox.ini index 0a415d1..95e1349 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ minversion = 2.9.0 skipdist = True skip_missing_interpreters = true -envlist = pre-commit,pep8,fmt-check,py{36,37,38} +envlist = pre-commit,pep8,py{36,37,38} # Activate isolated build environment. tox will use a virtual environment # to build a source distribution from the source tree. For build tools and