Rebase from master and run gray

This patch is a rebase of master after the introduction
of switching from black to gray code formatting.
This commit is contained in:
Hemna 2021-08-23 14:08:14 -04:00
parent 8e627c98b3
commit 8b5f21eece
7 changed files with 21 additions and 40 deletions

View File

@ -14,7 +14,7 @@ import click_completion
# local imports here # local imports here
import aprsd import aprsd
from aprsd import client, email, plugin, utils from aprsd import client, plugin, utils
# setup the global logger # setup the global logger
@ -192,15 +192,10 @@ def test_plugin(
packet = {"from": fromcall, "message_text": message, "msgNo": 1} packet = {"from": fromcall, "message_text": message, "msgNo": 1}
<<<<<<< HEAD
reply = obj.run(packet)
LOG.info(f"Result = '{reply}'")
=======
reply = obj.filter(packet) reply = obj.filter(packet)
# Plugin might have threads, so lets stop them so we can exit. # Plugin might have threads, so lets stop them so we can exit.
obj.stop_threads() obj.stop_threads()
LOG.info("Result = '{}'".format(reply)) LOG.info(f"Result = '{reply}'")
>>>>>>> f8f84c4 (Added threads functions to APRSDPluginBase)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -37,8 +37,7 @@ import click_completion
# local imports here # local imports here
import aprsd import aprsd
from aprsd import ( from aprsd import (
client, email, flask, messaging, packets, plugin, stats, threads, trace, client, flask, messaging, packets, plugin, stats, threads, trace, utils,
utils,
) )

View File

@ -8,10 +8,11 @@ import os
import re import re
import threading import threading
from aprsd import messaging, packets, threads
import pluggy import pluggy
from thesmuggler import smuggle from thesmuggler import smuggle
from aprsd import messaging, packets, threads
# setup the global logger # setup the global logger
LOG = logging.getLogger("APRSD") LOG = logging.getLogger("APRSD")
@ -98,7 +99,6 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
def setup(self): def setup(self):
"""Do any plugin setup here.""" """Do any plugin setup here."""
pass
def create_threads(self): def create_threads(self):
"""Gives the plugin writer the ability start a background thread.""" """Gives the plugin writer the ability start a background thread."""
@ -124,7 +124,6 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
@abc.abstractmethod @abc.abstractmethod
def process(self, packet): def process(self, packet):
"""This is called when the filter passes.""" """This is called when the filter passes."""
pass
class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta): class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
@ -153,15 +152,7 @@ class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
return result 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): class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
>>>>>>> 2e7c884 (Refactor Message processing and MORE)
"""Base Message plugin class. """Base Message plugin class.
When you want to search for a particular command in an When you want to search for a particular command in an
@ -200,13 +191,7 @@ class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
if result: if result:
self.tx_inc() self.tx_inc()
<<<<<<< HEAD
To reply with a message over the air, return a string
to send.
"""
=======
return result return result
>>>>>>> 2e7c884 (Refactor Message processing and MORE)
class PluginManager: class PluginManager:

View File

@ -7,10 +7,11 @@ import re
import smtplib import smtplib
import time import time
from aprsd import messaging, plugin, stats, threads, trace
import imapclient import imapclient
from validate_email import validate_email from validate_email import validate_email
from aprsd import messaging, plugin, stats, threads, trace
LOG = logging.getLogger("APRSD") LOG = logging.getLogger("APRSD")
@ -171,7 +172,7 @@ def _imap_connect():
) )
except (imaplib.IMAP4.error, Exception) as e: except (imaplib.IMAP4.error, Exception) as e:
msg = getattr(e, "message", repr(e)) msg = getattr(e, "message", repr(e))
LOG.error("Failed to login {}".format(msg)) LOG.error(f"Failed to login {msg}")
return return
server.select_folder("INBOX") server.select_folder("INBOX")
@ -213,7 +214,7 @@ def _smtp_connect():
LOG.error("Couldn't connect to SMTP Server") LOG.error("Couldn't connect to SMTP Server")
return 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) debug = CONFIG["aprsd"]["email"]["smtp"].get("debug", False)
if debug: if debug:
@ -229,7 +230,7 @@ def _smtp_connect():
LOG.error("Couldn't connect to SMTP Server") LOG.error("Couldn't connect to SMTP Server")
return return
LOG.debug("Logged into SMTP server {}".format(msg)) LOG.debug(f"Logged into SMTP server {msg}")
return server return server
@ -244,7 +245,7 @@ def validate_shortcuts(config):
) )
delete_keys = [] delete_keys = []
for key in shortcuts: for key in shortcuts:
LOG.info("Validating {}:{}".format(key, shortcuts[key])) LOG.info(f"Validating {key}:{shortcuts[key]}")
is_valid = validate_email( is_valid = validate_email(
email_address=shortcuts[key], email_address=shortcuts[key],
check_regex=True, check_regex=True,
@ -313,7 +314,7 @@ def parse_email(msgid, data, server):
from_addr = f.group(1) from_addr = f.group(1)
else: else:
from_addr = "noaddr" from_addr = "noaddr"
LOG.debug("Got a message from '{}'".format(from_addr)) LOG.debug(f"Got a message from '{from_addr}'")
try: try:
m = server.fetch([msgid], ["RFC822"]) m = server.fetch([msgid], ["RFC822"])
except Exception as e: except Exception as e:
@ -447,7 +448,7 @@ def resend_email(count, fromcall):
month = date.strftime("%B")[:3] # Nov, Mar, Apr month = date.strftime("%B")[:3] # Nov, Mar, Apr
day = date.day day = date.day
year = date.year year = date.year
today = "{}-{}-{}".format(day, month, year) today = f"{day}-{month}-{year}"
shortcuts = CONFIG["aprsd"]["email"]["shortcuts"] shortcuts = CONFIG["aprsd"]["email"]["shortcuts"]
# swap key/value # swap key/value
@ -564,7 +565,7 @@ class APRSDEmailThread(threads.APRSDThread):
month = date.strftime("%B")[:3] # Nov, Mar, Apr month = date.strftime("%B")[:3] # Nov, Mar, Apr
day = date.day day = date.day
year = date.year year = date.year
today = "{}-{}-{}".format(day, month, year) today = f"{day}-{month}-{year}"
try: try:
server = _imap_connect() server = _imap_connect()
@ -580,7 +581,7 @@ class APRSDEmailThread(threads.APRSDThread):
e, e,
) )
return True return True
LOG.debug("{} messages received today".format(len(messages))) LOG.debug(f"{len(messages)} messages received today")
try: try:
_msgs = server.fetch(messages, ["ENVELOPE"]) _msgs = server.fetch(messages, ["ENVELOPE"])

View File

@ -209,7 +209,7 @@ class APRSDRXThread(APRSDThread):
msg = packet.get("message_text", None) msg = packet.get("message_text", None)
msg_id = packet.get("msgNo", "0") msg_id = packet.get("msgNo", "0")
msg_response = packet.get("response", None) 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 # We don't put ack packets destined for us through the
# plugins. # plugins.
@ -240,14 +240,14 @@ class APRSDRXThread(APRSDThread):
pm = plugin.PluginManager() pm = plugin.PluginManager()
try: try:
results = pm.run(packet) results = pm.run(packet)
LOG.debug("RESULTS {}".format(results)) LOG.debug(f"RESULTS {results}")
replied = False replied = False
for reply in results: for reply in results:
if isinstance(reply, list): if isinstance(reply, list):
# one of the plugins wants to send multiple messages # one of the plugins wants to send multiple messages
replied = True replied = True
for subreply in reply: for subreply in reply:
LOG.debug("Sending '{}'".format(subreply)) LOG.debug(f"Sending '{subreply}'")
msg = messaging.TextMessage( msg = messaging.TextMessage(
self.config["aprs"]["login"], self.config["aprs"]["login"],
@ -263,7 +263,7 @@ class APRSDRXThread(APRSDThread):
# nothing to reply with, so we avoid replying with a # nothing to reply with, so we avoid replying with a
# usage string # usage string
if reply is not messaging.NULL_MESSAGE: if reply is not messaging.NULL_MESSAGE:
LOG.debug("Sending '{}'".format(reply)) LOG.debug(f"Sending '{reply}'")
msg = messaging.TextMessage( msg = messaging.TextMessage(
self.config["aprs"]["login"], self.config["aprs"]["login"],

View File

@ -1,5 +1,6 @@
from aprsd import packets, plugin, threads from aprsd import packets, plugin, threads
FAKE_MESSAGE_TEXT = "fake MeSSage" FAKE_MESSAGE_TEXT = "fake MeSSage"
FAKE_FROM_CALLSIGN = "KFART" FAKE_FROM_CALLSIGN = "KFART"
FAKE_TO_CALLSIGN = "KMINE" FAKE_TO_CALLSIGN = "KMINE"

View File

@ -2,7 +2,7 @@
minversion = 2.9.0 minversion = 2.9.0
skipdist = True skipdist = True
skip_missing_interpreters = 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 # Activate isolated build environment. tox will use a virtual environment
# to build a source distribution from the source tree. For build tools and # to build a source distribution from the source tree. For build tools and