From d08436059949744f68378367c2d237f14f87d31b Mon Sep 17 00:00:00 2001 From: Hemna Date: Fri, 8 Jan 2021 17:23:35 -0500 Subject: [PATCH 1/7] Added Makefile for easy dev setup This patch adds a Makefile for helping setup a dev environment as well as running tox tests for those that aren't used to python development. --- Makefile | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..15d22b2 --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +.PHONY: virtual install build-requirements black isort flake8 + +virtual: .venv/bin/pip # Creates an isolated python 3 environment + +.venv/bin/pip: + virtualenv -p /usr/bin/python3 .venv + +install: + .venv/bin/pip install -Ur requirements.txt + +dev: virtual + .venv/bin/pip install -e . + .venv/bin/pre-commit install + +test: dev + tox -p + +update-requirements: install + .venv/bin/pip freeze > requirements.txt + +.venv/bin/tox: # install tox + .venv/bin/pip install -U tox + +check: .venv/bin/tox # Code format check with isort and black + tox -efmt-check + tox -epep8 + +fix: .venv/bin/tox # fixes code formatting with isort and black + tox -efmt From 4c0150dd975fc6c2303e9eae937abafc6a5f33bc Mon Sep 17 00:00:00 2001 From: Hemna Date: Thu, 7 Jan 2021 17:00:42 -0500 Subject: [PATCH 2/7] Added more pre-commit hook tests also added pre-commit job for tox. --- .pre-commit-config.yaml | 11 +++++++++++ aprsd/client.py | 1 + aprsd/email.py | 1 + aprsd/fake_aprs.py | 1 + aprsd/fuzzyclock.py | 1 + aprsd/messaging.py | 1 + aprsd/plugin.py | 1 + aprsd/threads.py | 1 + aprsd/utils.py | 1 + dev-requirements.in | 10 +++++----- examples/plugins/example_plugin.py | 1 + setup.py | 1 + tox.ini | 7 ++++++- 13 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8f4e04d..2c31010 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,11 +6,22 @@ repos: - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files + - id: fix-encoding-pragma + - id: detect-private-key + - id: check-merge-conflict + - id: check-case-conflict + - id: check-docstring-first + - id: check-builtin-literals - repo: https://github.com/psf/black rev: 19.3b0 hooks: - id: black +- repo: https://github.com/pre-commit/mirrors-isort + rev: v5.7.0 + hooks: + - id: isort + - repo: https://gitlab.com/pycqa/flake8 rev: 3.8.1 hooks: diff --git a/aprsd/client.py b/aprsd/client.py index 9f256c7..281c830 100644 --- a/aprsd/client.py +++ b/aprsd/client.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import logging import select import socket diff --git a/aprsd/email.py b/aprsd/email.py index 85110df..f7084bc 100644 --- a/aprsd/email.py +++ b/aprsd/email.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import datetime import email import imaplib diff --git a/aprsd/fake_aprs.py b/aprsd/fake_aprs.py index 3472feb..086a7e4 100644 --- a/aprsd/fake_aprs.py +++ b/aprsd/fake_aprs.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import argparse import logging import socketserver diff --git a/aprsd/fuzzyclock.py b/aprsd/fuzzyclock.py index 19f105b..ba92596 100644 --- a/aprsd/fuzzyclock.py +++ b/aprsd/fuzzyclock.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # # @author Sinu John # sinuvian at gmail dot com diff --git a/aprsd/messaging.py b/aprsd/messaging.py index 34627f3..fd6cd4d 100644 --- a/aprsd/messaging.py +++ b/aprsd/messaging.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import abc import datetime import logging diff --git a/aprsd/plugin.py b/aprsd/plugin.py index b7f350b..aab9ac3 100644 --- a/aprsd/plugin.py +++ b/aprsd/plugin.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # The base plugin class import abc import fnmatch diff --git a/aprsd/threads.py b/aprsd/threads.py index e352bf9..31fca98 100644 --- a/aprsd/threads.py +++ b/aprsd/threads.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import abc import logging import queue diff --git a/aprsd/utils.py b/aprsd/utils.py index f92c7d9..4257ac9 100644 --- a/aprsd/utils.py +++ b/aprsd/utils.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """Utilities and helper functions.""" import errno diff --git a/dev-requirements.in b/dev-requirements.in index dcd980a..51e6336 100644 --- a/dev-requirements.in +++ b/dev-requirements.in @@ -1,9 +1,9 @@ -tox +black +flake8 +isort +mypy pytest pytest-cov -mypy -flake8 pep8-naming -black -isort Sphinx +tox diff --git a/examples/plugins/example_plugin.py b/examples/plugins/example_plugin.py index c4eb1d0..e01281e 100644 --- a/examples/plugins/example_plugin.py +++ b/examples/plugins/example_plugin.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import logging from aprsd import plugin diff --git a/setup.py b/setup.py index 90623e2..fda5a1c 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tox.ini b/tox.ini index ba64524..dd53ec5 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ minversion = 2.9.0 skipdist = True skip_missing_interpreters = true -envlist = pep8,py{36,37,38},fmt-check +envlist = pre-commit,pep8,fmt-check,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 @@ -91,3 +91,8 @@ deps = -r{toxinidir}/dev-requirements.txt commands = mypy aprsd + +[testenv:pre-commit] +skip_install = true +deps = pre-commit +commands = pre-commit run --all-files --show-diff-on-failure From 231c15b1af4bb384644efcfded90d0bc6c0e8ec2 Mon Sep 17 00:00:00 2001 From: Hemna Date: Fri, 8 Jan 2021 15:47:30 -0500 Subject: [PATCH 3/7] Lots of fixes --- .pre-commit-config.yaml | 71 +++++++++++++++++++----------- aprsd/__init__.py | 2 - aprsd/client.py | 15 ++++--- aprsd/email.py | 62 ++++++++++++++------------ aprsd/fake_aprs.py | 5 +-- aprsd/fuzzyclock.py | 1 - aprsd/main.py | 53 ++++++++++++++-------- aprsd/messaging.py | 38 +++++++++------- aprsd/plugin.py | 54 +++++++++++++---------- aprsd/threads.py | 32 +++++++++----- aprsd/utils.py | 22 +++++---- examples/plugins/example_plugin.py | 1 - pyproject.toml | 36 +++++++++++++++ setup.cfg | 11 ++--- setup.py | 1 - tests/test_main.py | 3 +- tests/test_plugin.py | 6 ++- 17 files changed, 258 insertions(+), 155 deletions(-) create mode 100644 pyproject.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2c31010..f2074b5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,29 +1,48 @@ repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 - hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-yaml - - id: check-added-large-files - - id: fix-encoding-pragma - - id: detect-private-key - - id: check-merge-conflict - - id: check-case-conflict - - id: check-docstring-first - - id: check-builtin-literals -- repo: https://github.com/psf/black - rev: 19.3b0 - hooks: - - id: black +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: detect-private-key + - id: check-merge-conflict + - id: check-case-conflict + - id: check-docstring-first + - id: check-builtin-literals + - id: double-quote-string-fixer -- repo: https://github.com/pre-commit/mirrors-isort - rev: v5.7.0 - hooks: - - id: isort +- repo: https://github.com/asottile/setup-cfg-fmt + rev: v1.16.0 + hooks: + - id: setup-cfg-fmt -- repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.1 - hooks: - - id: flake8 - additional_dependencies: [flake8-bugbear] +- repo: https://github.com/asottile/add-trailing-comma + rev: v2.0.2 + hooks: + - id: add-trailing-comma + args: [--py36-plus] + +- repo: https://github.com/asottile/pyupgrade + rev: v2.7.4 + hooks: + - id: pyupgrade + args: + - --py3-plus + +- repo: https://github.com/pre-commit/mirrors-isort + rev: v5.7.0 + hooks: + - id: isort + +- repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black + +- repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.4 + hooks: + - id: flake8 + additional_dependencies: [flake8-bugbear] diff --git a/aprsd/__init__.py b/aprsd/__init__.py index 0863171..221b6c8 100644 --- a/aprsd/__init__.py +++ b/aprsd/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at diff --git a/aprsd/client.py b/aprsd/client.py index 281c830..0f3fa44 100644 --- a/aprsd/client.py +++ b/aprsd/client.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- import logging import select -import socket import time import aprslib @@ -9,7 +7,7 @@ import aprslib LOG = logging.getLogger("APRSD") -class Client(object): +class Client: """Singleton client class that constructs the aprslib connection.""" _instance = None @@ -19,7 +17,7 @@ class Client(object): def __new__(cls, *args, **kwargs): """This magic turns this into a singleton.""" if cls._instance is None: - cls._instance = super(Client, cls).__new__(cls) + cls._instance = super().__new__(cls) # Put any initialization here. return cls._instance @@ -82,7 +80,7 @@ class Aprsdis(aprslib.IS): """ try: self.sock.setblocking(0) - except socket.error as e: + except OSError as e: self.logger.error("socket error when setblocking(0): %s" % str(e)) raise aprslib.ConnectionDrop("connection dropped") @@ -93,7 +91,10 @@ class Aprsdis(aprslib.IS): # set a select timeout, so we get a chance to exit # when user hits CTRL-C readable, writable, exceptional = select.select( - [self.sock], [], [], self.select_timeout + [self.sock], + [], + [], + self.select_timeout, ) if not readable: continue @@ -105,7 +106,7 @@ class Aprsdis(aprslib.IS): if not short_buf: self.logger.error("socket.recv(): returned empty") raise aprslib.ConnectionDrop("connection dropped") - except socket.error as e: + except OSError as e: # self.logger.error("socket error on recv(): %s" % str(e)) if "Resource temporarily unavailable" in str(e): if not blocking: diff --git a/aprsd/email.py b/aprsd/email.py index f7084bc..ed562e8 100644 --- a/aprsd/email.py +++ b/aprsd/email.py @@ -1,18 +1,15 @@ -# -*- coding: utf-8 -*- import datetime import email +from email.mime.text import MIMEText import imaplib import logging import re import smtplib import time -from email.mime.text import MIMEText - -import imapclient -import six -from validate_email import validate_email from aprsd import messaging, threads +import imapclient +from validate_email import validate_email LOG = logging.getLogger("APRSD") @@ -30,7 +27,10 @@ def _imap_connect(): try: server = imapclient.IMAPClient( - CONFIG["imap"]["host"], port=imap_port, use_uid=True, ssl=use_ssl + CONFIG["imap"]["host"], + port=imap_port, + use_uid=True, + ssl=use_ssl, ) except Exception: LOG.error("Failed to connect IMAP server") @@ -53,7 +53,7 @@ def _smtp_connect(): use_ssl = CONFIG["smtp"].get("use_ssl", False) msg = "{}{}:{}".format("SSL " if use_ssl else "", host, smtp_port) LOG.debug( - "Connect to SMTP host {} with user '{}'".format(msg, CONFIG["imap"]["login"]) + "Connect to SMTP host {} with user '{}'".format(msg, CONFIG["imap"]["login"]), ) try: @@ -84,7 +84,7 @@ def validate_shortcuts(config): LOG.info( "Validating {} Email shortcuts. This can take up to 10 seconds" - " per shortcut".format(len(shortcuts)) + " per shortcut".format(len(shortcuts)), ) delete_keys = [] for key in shortcuts: @@ -102,8 +102,8 @@ def validate_shortcuts(config): if not is_valid: LOG.error( "'{}' is an invalid email address. Removing shortcut".format( - shortcuts[key] - ) + shortcuts[key], + ), ) delete_keys.append(key) @@ -173,14 +173,18 @@ def parse_email(msgid, data, server): if part.get_content_type() == "text/plain": LOG.debug("Email got text/plain") - text = six.text_type( - part.get_payload(decode=True), str(charset), "ignore" + text = str( + part.get_payload(decode=True), + str(charset), + "ignore", ).encode("utf8", "replace") if part.get_content_type() == "text/html": LOG.debug("Email got text/html") - html = six.text_type( - part.get_payload(decode=True), str(charset), "ignore" + html = str( + part.get_payload(decode=True), + str(charset), + "ignore", ).encode("utf8", "replace") if text is not None: @@ -192,12 +196,15 @@ def parse_email(msgid, data, server): # email.uscc.net sends no charset, blows up unicode function below LOG.debug("Email is not multipart") if msg.get_content_charset() is None: - text = six.text_type( - msg.get_payload(decode=True), "US-ASCII", "ignore" - ).encode("utf8", "replace") + text = str(msg.get_payload(decode=True), "US-ASCII", "ignore").encode( + "utf8", + "replace", + ) else: - text = six.text_type( - msg.get_payload(decode=True), msg.get_content_charset(), "ignore" + text = str( + msg.get_payload(decode=True), + msg.get_content_charset(), + "ignore", ).encode("utf8", "replace") body = text.strip() @@ -266,11 +273,11 @@ def resend_email(count, fromcall): month = date.strftime("%B")[:3] # Nov, Mar, Apr day = date.day year = date.year - today = "%s-%s-%s" % (day, month, year) + today = "{}-{}-{}".format(day, month, year) shortcuts = CONFIG["shortcuts"] # swap key/value - shortcuts_inverted = dict([[v, k] for k, v in shortcuts.items()]) + shortcuts_inverted = {v: k for k, v in shortcuts.items()} try: server = _imap_connect() @@ -310,7 +317,7 @@ def resend_email(count, fromcall): # thinking this is a duplicate message. # The FT1XDR pretty much ignores the aprs message number in this # regard. The FTM400 gets it right. - reply = "No new msg %s:%s:%s" % ( + reply = "No new msg {}:{}:{}".format( str(h).zfill(2), str(m).zfill(2), str(s).zfill(2), @@ -328,7 +335,7 @@ def resend_email(count, fromcall): class APRSDEmailThread(threads.APRSDThread): def __init__(self, msg_queues, config): - super(APRSDEmailThread, self).__init__("EmailThread") + super().__init__("EmailThread") self.msg_queues = msg_queues self.config = config @@ -354,13 +361,13 @@ class APRSDEmailThread(threads.APRSDThread): shortcuts = CONFIG["shortcuts"] # swap key/value - shortcuts_inverted = dict([[v, k] for k, v in shortcuts.items()]) + shortcuts_inverted = {v: k for k, v in shortcuts.items()} date = datetime.datetime.now() month = date.strftime("%B")[:3] # Nov, Mar, Apr day = date.day year = date.year - today = "%s-%s-%s" % (day, month, year) + today = "{}-{}-{}".format(day, month, year) server = None try: @@ -378,7 +385,8 @@ class APRSDEmailThread(threads.APRSDThread): envelope = data[b"ENVELOPE"] # LOG.debug('ID:%d "%s" (%s)' % (msgid, envelope.subject.decode(), envelope.date)) f = re.search( - r"'([[A-a][0-9]_-]+@[[A-a][0-9]_-\.]+)", str(envelope.from_[0]) + r"'([[A-a][0-9]_-]+@[[A-a][0-9]_-\.]+)", + str(envelope.from_[0]), ) if f is not None: from_addr = f.group(1) diff --git a/aprsd/fake_aprs.py b/aprsd/fake_aprs.py index 086a7e4..f6ed353 100644 --- a/aprsd/fake_aprs.py +++ b/aprsd/fake_aprs.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- import argparse import logging +from logging.handlers import RotatingFileHandler import socketserver import sys import time -from logging.handlers import RotatingFileHandler from aprsd import utils @@ -74,7 +73,7 @@ def main(): ip = CONFIG["aprs"]["host"] port = CONFIG["aprs"]["port"] - LOG.info("Start server listening on %s:%s" % (args.ip, args.port)) + LOG.info("Start server listening on {}:{}".format(args.ip, args.port)) with socketserver.TCPServer((ip, port), MyAPRSTCPHandler) as server: server.serve_forever() diff --git a/aprsd/fuzzyclock.py b/aprsd/fuzzyclock.py index ba92596..19f105b 100644 --- a/aprsd/fuzzyclock.py +++ b/aprsd/fuzzyclock.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # @author Sinu John # sinuvian at gmail dot com diff --git a/aprsd/main.py b/aprsd/main.py index 2e58e5a..51ab8b2 100644 --- a/aprsd/main.py +++ b/aprsd/main.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Listen on amateur radio aprs-is network for messages and respond to them. # You must have an amateur radio callsign to use this software. You must @@ -22,23 +21,22 @@ # python included libs import logging +from logging import NullHandler +from logging.handlers import RotatingFileHandler import os import queue import signal import sys import threading import time -from logging import NullHandler -from logging.handlers import RotatingFileHandler - -import aprslib -import click -import click_completion -import yaml # local imports here import aprsd from aprsd import client, email, messaging, plugin, threads, utils +import aprslib +import click +import click_completion +import yaml # setup the global logger # logging.basicConfig(level=logging.DEBUG) # level=10 @@ -99,7 +97,9 @@ def main(): @main.command() @click.option( - "-i", "--case-insensitive/--no-case-insensitive", help="Case insensitive completion" + "-i", + "--case-insensitive/--no-case-insensitive", + help="Case insensitive completion", ) @click.argument( "shell", @@ -118,10 +118,14 @@ def show(shell, case_insensitive): @main.command() @click.option( - "--append/--overwrite", help="Append the completion code to the file", default=None + "--append/--overwrite", + help="Append the completion code to the file", + default=None, ) @click.option( - "-i", "--case-insensitive/--no-case-insensitive", help="Case insensitive completion" + "-i", + "--case-insensitive/--no-case-insensitive", + help="Case insensitive completion", ) @click.argument( "shell", @@ -137,16 +141,19 @@ def install(append, case_insensitive, shell, path): else {} ) shell, path = click_completion.core.install( - shell=shell, path=path, append=append, extra_env=extra_env + shell=shell, + path=path, + append=append, + extra_env=extra_env, ) - click.echo("%s completion installed in %s" % (shell, path)) + click.echo("{} completion installed in {}".format(shell, path)) def signal_handler(signal, frame): global server_vent LOG.info( - "Ctrl+C, Sending all threads exit! Can take up to 10 seconds to exit all threads" + "Ctrl+C, Sending all threads exit! Can take up to 10 seconds to exit all threads", ) threads.APRSDThreadList().stop_all() server_event.set() @@ -191,7 +198,8 @@ def sample_config(): default="DEBUG", show_default=True, type=click.Choice( - ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"], case_sensitive=False + ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"], + case_sensitive=False, ), show_choices=True, help="The log level to use for aprsd.log", @@ -220,7 +228,13 @@ def sample_config(): @click.argument("tocallsign") @click.argument("command", nargs=-1) def send_message( - loglevel, quiet, config_file, aprs_login, aprs_password, tocallsign, command + loglevel, + quiet, + config_file, + aprs_login, + aprs_password, + tocallsign, + command, ): """Send a message to a callsign via APRS_IS.""" global got_ack, got_response @@ -273,7 +287,9 @@ def send_message( got_response = True # Send the ack back? ack = messaging.AckMessage( - config["aprs"]["login"], fromcall, msg_id=msg_number + config["aprs"]["login"], + fromcall, + msg_id=msg_number, ) ack.send_direct() @@ -312,7 +328,8 @@ def send_message( default="DEBUG", show_default=True, type=click.Choice( - ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"], case_sensitive=False + ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"], + case_sensitive=False, ), show_choices=True, help="The log level to use for aprsd.log", diff --git a/aprsd/messaging.py b/aprsd/messaging.py index fd6cd4d..3f1f36d 100644 --- a/aprsd/messaging.py +++ b/aprsd/messaging.py @@ -1,14 +1,13 @@ -# -*- coding: utf-8 -*- import abc import datetime import logging +from multiprocessing import RawValue import os import pathlib import pickle import re import threading import time -from multiprocessing import RawValue from aprsd import client, threads, utils @@ -19,7 +18,7 @@ LOG = logging.getLogger("APRSD") NULL_MESSAGE = -1 -class MsgTrack(object): +class MsgTrack: """Class to keep track of outstanding text messages. This is a thread safe class that keeps track of active @@ -47,7 +46,7 @@ class MsgTrack(object): def __new__(cls, *args, **kwargs): if cls._instance is None: - cls._instance = super(MsgTrack, cls).__new__(cls) + cls._instance = super().__new__(cls) cls._instance.track = {} cls._instance.lock = threading.Lock() return cls._instance @@ -129,7 +128,7 @@ class MsgTrack(object): self.track = {} -class MessageCounter(object): +class MessageCounter: """ Global message id counter class. @@ -147,7 +146,7 @@ class MessageCounter(object): def __new__(cls, *args, **kwargs): """Make this a singleton class.""" if cls._instance is None: - cls._instance = super(MessageCounter, cls).__new__(cls) + cls._instance = super().__new__(cls) cls._instance.val = RawValue("i", 1) cls._instance.lock = threading.Lock() return cls._instance @@ -173,7 +172,7 @@ class MessageCounter(object): return str(self.val.value) -class Message(object, metaclass=abc.ABCMeta): +class Message(metaclass=abc.ABCMeta): """Base Message Class.""" # The message id to send over the air @@ -204,7 +203,7 @@ class TextMessage(Message): message = None def __init__(self, fromcall, tocall, message, msg_id=None, allow_delay=True): - super(TextMessage, self).__init__(fromcall, tocall, msg_id) + super().__init__(fromcall, tocall, msg_id) self.message = message # do we try and save this message for later if we don't get # an ack? Some messages we don't want to do this ever. @@ -213,7 +212,10 @@ class TextMessage(Message): def __repr__(self): """Build raw string to send over the air.""" return "{}>APRS::{}:{}{{{}\n".format( - self.fromcall, self.tocall.ljust(9), self._filter_for_send(), str(self.id) + self.fromcall, + self.tocall.ljust(9), + self._filter_for_send(), + str(self.id), ) def __str__(self): @@ -222,7 +224,11 @@ class TextMessage(Message): now = datetime.datetime.now() delta = now - self.last_send_time return "{}>{} Msg({})({}): '{}'".format( - self.fromcall, self.tocall, self.id, delta, self.message + self.fromcall, + self.tocall, + self.id, + delta, + self.message, ) def _filter_for_send(self): @@ -259,9 +265,7 @@ class SendMessageThread(threads.APRSDThread): def __init__(self, message): self.msg = message name = self.msg.message[:5] - super(SendMessageThread, self).__init__( - "SendMessage-{}-{}".format(self.msg.id, name) - ) + super().__init__("SendMessage-{}-{}".format(self.msg.id, name)) def loop(self): """Loop until a message is acked or it gets delayed. @@ -326,11 +330,13 @@ class AckMessage(Message): """Class for building Acks and sending them.""" def __init__(self, fromcall, tocall, msg_id): - super(AckMessage, self).__init__(fromcall, tocall, msg_id=msg_id) + super().__init__(fromcall, tocall, msg_id=msg_id) def __repr__(self): return "{}>APRS::{}:ack{}\n".format( - self.fromcall, self.tocall.ljust(9), self.id + self.fromcall, + self.tocall.ljust(9), + self.id, ) def __str__(self): @@ -378,7 +384,7 @@ class AckMessage(Message): class SendAckThread(threads.APRSDThread): def __init__(self, ack): self.ack = ack - super(SendAckThread, self).__init__("SendAck-{}".format(self.ack.id)) + super().__init__("SendAck-{}".format(self.ack.id)) def loop(self): """Separate thread to send acks with retries.""" diff --git a/aprsd/plugin.py b/aprsd/plugin.py index aab9ac3..eae9569 100644 --- a/aprsd/plugin.py +++ b/aprsd/plugin.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # The base plugin class import abc import fnmatch @@ -12,14 +11,12 @@ import shutil import subprocess import time -import pluggy -import requests -import six -from thesmuggler import smuggle - import aprsd from aprsd import email, messaging from aprsd.fuzzyclock import fuzzy +import pluggy +import requests +from thesmuggler import smuggle # setup the global logger LOG = logging.getLogger("APRSD") @@ -39,7 +36,7 @@ CORE_PLUGINS = [ ] -class PluginManager(object): +class PluginManager: # The singleton instance object for this class _instance = None @@ -52,7 +49,7 @@ class PluginManager(object): def __new__(cls, *args, **kwargs): """This magic turns this into a singleton.""" if cls._instance is None: - cls._instance = super(PluginManager, cls).__new__(cls) + cls._instance = super().__new__(cls) # Put any initialization here. return cls._instance @@ -79,7 +76,7 @@ class PluginManager(object): for mem_name, obj in inspect.getmembers(module): if inspect.isclass(obj) and self.is_plugin(obj): self.obj_list.append( - {"name": mem_name, "obj": obj(self.config)} + {"name": mem_name, "obj": obj(self.config)}, ) return self.obj_list @@ -108,14 +105,16 @@ class PluginManager(object): return assert hasattr(module, class_name), "class {} is not in {}".format( - class_name, module_name + class_name, + module_name, ) # click.echo('reading class {} from module {}'.format( # class_name, module_name)) cls = getattr(module, class_name) if super_cls is not None: assert issubclass(cls, super_cls), "class {} should inherit from {}".format( - class_name, super_cls.__name__ + class_name, + super_cls.__name__, ) # click.echo('initialising {} with params {}'.format(class_name, kwargs)) obj = cls(**kwargs) @@ -131,13 +130,17 @@ class PluginManager(object): plugin_obj = None try: plugin_obj = self._create_class( - plugin_name, APRSDPluginBase, config=self.config + plugin_name, + APRSDPluginBase, + config=self.config, ) if plugin_obj: LOG.info( "Registering Command plugin '{}'({}) '{}'".format( - plugin_name, plugin_obj.version, plugin_obj.command_regex - ) + plugin_name, + plugin_obj.version, + plugin_obj.command_regex, + ), ) self._pluggy_pm.register(plugin_obj) except Exception as ex: @@ -173,8 +176,10 @@ class PluginManager(object): if plugin_obj: LOG.info( "Registering Command plugin '{}'({}) '{}'".format( - o["name"], o["obj"].version, o["obj"].command_regex - ) + o["name"], + o["obj"].version, + o["obj"].command_regex, + ), ) self._pluggy_pm.register(o["obj"]) @@ -203,8 +208,7 @@ class APRSDCommandSpec: pass -@six.add_metaclass(abc.ABCMeta) -class APRSDPluginBase(object): +class APRSDPluginBase(metaclass=abc.ABCMeta): def __init__(self, config): """The aprsd config object is stored.""" self.config = config @@ -257,7 +261,8 @@ class FortunePlugin(APRSDPluginBase): try: process = subprocess.Popen( - [fortune_path, "-s", "-n 60"], stdout=subprocess.PIPE + [fortune_path, "-s", "-n 60"], + stdout=subprocess.PIPE, ) reply = process.communicate()[0] reply = reply.decode(errors="ignore").rstrip() @@ -406,7 +411,10 @@ class TimePlugin(APRSDPluginBase): m = stm.tm_min cur_time = fuzzy(h, m, 1) reply = "{} ({}:{} PDT) ({})".format( - cur_time, str(h), str(m).rjust(2, "0"), message.rstrip() + cur_time, + str(h), + str(m).rjust(2, "0"), + message.rstrip(), ) return reply @@ -497,7 +505,7 @@ class EmailPlugin(APRSDPluginBase): # send recipient link to aprs.fi map if content == "mapme": content = "Click for my location: http://aprs.fi/{}".format( - self.config["ham"]["callsign"] + self.config["ham"]["callsign"], ) too_soon = 0 now = time.time() @@ -521,7 +529,7 @@ class EmailPlugin(APRSDPluginBase): LOG.debug( "DEBUG: email_sent_dict is big (" + str(len(self.email_sent_dict)) - + ") clearing out." + + ") clearing out.", ) self.email_sent_dict.clear() self.email_sent_dict[ack] = now @@ -529,7 +537,7 @@ class EmailPlugin(APRSDPluginBase): LOG.info( "Email for message number " + ack - + " recently sent, not sending again." + + " recently sent, not sending again.", ) else: reply = "Bad email address" diff --git a/aprsd/threads.py b/aprsd/threads.py index 31fca98..4c61779 100644 --- a/aprsd/threads.py +++ b/aprsd/threads.py @@ -1,13 +1,11 @@ -# -*- coding: utf-8 -*- import abc import logging import queue import threading import time -import aprslib - from aprsd import client, messaging, plugin +import aprslib LOG = logging.getLogger("APRSD") @@ -16,7 +14,7 @@ TX_THREAD = "TX" EMAIL_THREAD = "Email" -class APRSDThreadList(object): +class APRSDThreadList: """Singleton class that keeps track of application wide threads.""" _instance = None @@ -26,7 +24,7 @@ class APRSDThreadList(object): def __new__(cls, *args, **kwargs): if cls._instance is None: - cls._instance = super(APRSDThreadList, cls).__new__(cls) + cls._instance = super().__new__(cls) cls.lock = threading.Lock() cls.threads_list = [] return cls._instance @@ -48,7 +46,7 @@ class APRSDThreadList(object): class APRSDThread(threading.Thread, metaclass=abc.ABCMeta): def __init__(self, name): - super(APRSDThread, self).__init__(name=name) + super().__init__(name=name) self.thread_stop = False APRSDThreadList().add(self) @@ -67,7 +65,7 @@ class APRSDThread(threading.Thread, metaclass=abc.ABCMeta): class APRSDRXThread(APRSDThread): def __init__(self, msg_queues, config): - super(APRSDRXThread, self).__init__("RX_MSG") + super().__init__("RX_MSG") self.msg_queues = msg_queues self.config = config @@ -112,7 +110,11 @@ class APRSDRXThread(APRSDThread): ack_num = packet.get("msgNo") LOG.info("Got ack for message {}".format(ack_num)) messaging.log_message( - "ACK", packet["raw"], None, ack=ack_num, fromcall=packet["from"] + "ACK", + packet["raw"], + None, + ack=ack_num, + fromcall=packet["from"], ) tracker = messaging.MsgTrack() tracker.remove(ack_num) @@ -153,7 +155,9 @@ class APRSDRXThread(APRSDThread): LOG.debug("Sending '{}'".format(reply)) msg = messaging.TextMessage( - self.config["aprs"]["login"], fromcall, reply + self.config["aprs"]["login"], + fromcall, + reply, ) self.msg_queues["tx"].put(msg) else: @@ -166,7 +170,9 @@ class APRSDRXThread(APRSDThread): reply = "Usage: {}".format(", ".join(names)) msg = messaging.TextMessage( - self.config["aprs"]["login"], fromcall, reply + self.config["aprs"]["login"], + fromcall, + reply, ) self.msg_queues["tx"].put(msg) except Exception as ex: @@ -178,7 +184,9 @@ class APRSDRXThread(APRSDThread): # let any threads do their thing, then ack # send an ack last ack = messaging.AckMessage( - self.config["aprs"]["login"], fromcall, msg_id=msg_id + self.config["aprs"]["login"], + fromcall, + msg_id=msg_id, ) self.msg_queues["tx"].put(ack) LOG.debug("Packet processing complete") @@ -213,7 +221,7 @@ class APRSDRXThread(APRSDThread): class APRSDTXThread(APRSDThread): def __init__(self, msg_queues, config): - super(APRSDTXThread, self).__init__("TX_MSG") + super().__init__("TX_MSG") self.msg_queues = msg_queues self.config = config diff --git a/aprsd/utils.py b/aprsd/utils.py index 4257ac9..d8bf573 100644 --- a/aprsd/utils.py +++ b/aprsd/utils.py @@ -1,17 +1,15 @@ -# -*- coding: utf-8 -*- """Utilities and helper functions.""" import errno import functools import os +from pathlib import Path import sys import threading -from pathlib import Path - -import click -import yaml from aprsd import plugin +import click +import yaml # an example of what should be in the ~/.aprsd/config.yml DEFAULT_CONFIG_DICT = { @@ -103,13 +101,13 @@ def get_config(config_file): """This tries to read the yaml config from .""" config_file_expanded = os.path.expanduser(config_file) if os.path.exists(config_file_expanded): - with open(config_file_expanded, "r") as stream: + with open(config_file_expanded) as stream: config = yaml.load(stream, Loader=yaml.FullLoader) return config else: if config_file == DEFAULT_CONFIG_FILE: click.echo( - "{} is missing, creating config file".format(config_file_expanded) + "{} is missing, creating config file".format(config_file_expanded), ) create_default_config() msg = ( @@ -144,7 +142,10 @@ def parse_config(config_file): if name and name not in config[section]: if not default: fail( - "'%s' was not in '%s' section of config file" % (name, section) + "'{}' was not in '{}' section of config file".format( + name, + section, + ), ) else: config[section][name] = default @@ -166,7 +167,10 @@ def parse_config(config_file): # special check here to make sure user has edited the config file # and changed the ham callsign check_option( - config, "ham", "callsign", default_fail=DEFAULT_CONFIG_DICT["ham"]["callsign"] + config, + "ham", + "callsign", + default_fail=DEFAULT_CONFIG_DICT["ham"]["callsign"], ) check_option(config, "aprs", "login") check_option(config, "aprs", "password") diff --git a/examples/plugins/example_plugin.py b/examples/plugins/example_plugin.py index e01281e..c4eb1d0 100644 --- a/examples/plugins/example_plugin.py +++ b/examples/plugins/example_plugin.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import logging from aprsd import plugin diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..09592fb --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,36 @@ +[build-system] +requires = ["setuptools>=46.0", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.black] +# Use the more relaxed max line length permitted in PEP8. +line-length = 88 +target-version = ["py36", "py37", "py38"] +# black will automatically exclude all files listed in .gitignore +include = '\.pyi?$' +exclude = ''' +/( + \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist +)/ +''' + +[tool.isort] +profile = "black" +line_length = 88 +force_sort_within_sections = true +# Inform isort of paths to import names that should be considered part of the "First Party" group. +src_paths = ["src/openstack_loadtest"] +skip_gitignore = true +# If you need to skip/exclude folders, consider using skip_glob as that will allow the +# isort defaults for skip to remain without the need to duplicate them. + +[tool.coverage.run] +branch = true diff --git a/setup.cfg b/setup.cfg index ac24c17..125cd1f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,15 +1,16 @@ [metadata] name = aprsd -summary = Amateur radio APRS daemon which listens for messages and responds -description-file = - README.rst -long-description-content-type = text/x-rst; charset=UTF-8 +long_description = file: README.rst +long_description_content_type = text/x-rst author = Craig Lamparter -author-email = something@somewhere.com +author_email = something@somewhere.com classifier = Topic :: Communications :: Ham Radio Operating System :: POSIX :: Linux Programming Language :: Python +description_file = + README.rst +summary = Amateur radio APRS daemon which listens for messages and responds [global] setup-hooks = diff --git a/setup.py b/setup.py index fda5a1c..90623e2 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/test_main.py b/tests/test_main.py index 1aecc1c..7996fcd 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import sys import unittest @@ -7,7 +6,7 @@ from aprsd import email if sys.version_info >= (3, 2): from unittest import mock else: - import mock + from unittest import mock class TestMain(unittest.TestCase): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index c2f860d..8512f34 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import unittest from unittest import mock @@ -57,7 +56,10 @@ class TestPlugin(unittest.TestCase): message = "time" expected = "{} ({}:{} PDT) ({})".format( - cur_time, str(h), str(m).rjust(2, "0"), message.rstrip() + cur_time, + str(h), + str(m).rjust(2, "0"), + message.rstrip(), ) actual = time_plugin.run(fromcall, message, ack) self.assertEqual(expected, actual) From a7c20430fe0611af7c757900adccd98c26cb4c94 Mon Sep 17 00:00:00 2001 From: Hemna Date: Fri, 8 Jan 2021 16:18:48 -0500 Subject: [PATCH 4/7] removed double-quote-string-fixer --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f2074b5..42761b3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,6 @@ repos: - id: check-case-conflict - id: check-docstring-first - id: check-builtin-literals - - id: double-quote-string-fixer - repo: https://github.com/asottile/setup-cfg-fmt rev: v1.16.0 From c51a9452d94fc9a4879eb698eaf648a81bbd0d5f Mon Sep 17 00:00:00 2001 From: Hemna Date: Fri, 8 Jan 2021 20:56:39 -0500 Subject: [PATCH 5/7] Updated Makefile This patch updates the Makefile to only run deps if certain files don't exist already. Also added the build and upload tasks to make it easier to test, build and upload a release to pypi --- Makefile | 45 +++++++-- dev-requirements.in | 1 + dev-requirements.txt | 212 ++++++++++++++++++++++++++++++++----------- requirements.txt | 4 +- 4 files changed, 200 insertions(+), 62 deletions(-) diff --git a/Makefile b/Makefile index 15d22b2..e6cb2aa 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,54 @@ -.PHONY: virtual install build-requirements black isort flake8 +.PHONY: virtual dev build-requirements black isort flake8 + +all: pip dev virtual: .venv/bin/pip # Creates an isolated python 3 environment .venv/bin/pip: virtualenv -p /usr/bin/python3 .venv -install: +.venv/bin/aprsd: virtual + test -s .venv/bin/aprsd || .venv/bin/pip install -q -e . + +install: .venv/bin/aprsd .venv/bin/pip install -Ur requirements.txt -dev: virtual - .venv/bin/pip install -e . - .venv/bin/pre-commit install +dev-pre-commit: + test -s .git/hooks/pre-commit || .venv/bin/pre-commit install + +dev-requirements: + test -s .venv/bin/twine || .venv/bin/pip install -q -r dev-requirements.txt + +pip: virtual + .venv/bin/pip install -q -U pip + +dev: pip .venv/bin/aprsd dev-requirements dev-pre-commit + +pip-tools: + test -s .venv/bin/pip-compile || .venv/bin/pip install pip-tools + +clean: + rm -rf dist/* + rm -rf .venv test: dev + .venv/bin/pre-commit run --all-files tox -p -update-requirements: install - .venv/bin/pip freeze > requirements.txt +build: test + rm -rf dist/* + .venv/bin/python3 setup.py sdist bdist_wheel + .venv/bin/twine check dist/* + +upload: build + .venv/bin/twine upload dist/* + +update-requirements: dev pip-tools + .venv/bin/pip-compile -q -U requirements.in + .venv/bin/pip-compile -q -U dev-requirements.in .venv/bin/tox: # install tox - .venv/bin/pip install -U tox + test -s .venv/bin/tox || .venv/bin/pip install -q -U tox check: .venv/bin/tox # Code format check with isort and black tox -efmt-check diff --git a/dev-requirements.in b/dev-requirements.in index 51e6336..61d89bb 100644 --- a/dev-requirements.in +++ b/dev-requirements.in @@ -7,3 +7,4 @@ pytest-cov pep8-naming Sphinx tox +twine diff --git a/dev-requirements.txt b/dev-requirements.txt index 087a674..57100ae 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -4,58 +4,166 @@ # # pip-compile dev-requirements.in # -alabaster==0.7.12 # via sphinx -appdirs==1.4.4 # via black, virtualenv -attrs==20.3.0 # via pytest -babel==2.9.0 # via sphinx -black==20.8b1 # via -r dev-requirements.in -certifi==2020.12.5 # via requests -chardet==4.0.0 # via requests -click==7.1.2 # via black -coverage==5.3 # via pytest-cov -distlib==0.3.1 # via virtualenv -docutils==0.16 # via sphinx -filelock==3.0.12 # via tox, virtualenv -flake8-polyfill==1.0.2 # via pep8-naming -flake8==3.8.4 # via -r dev-requirements.in, flake8-polyfill -idna==2.10 # via requests -imagesize==1.2.0 # via sphinx -iniconfig==1.1.1 # via pytest -isort==5.6.4 # via -r dev-requirements.in -jinja2==2.11.2 # via sphinx -markupsafe==1.1.1 # via jinja2 -mccabe==0.6.1 # via flake8 -mypy-extensions==0.4.3 # via black, mypy -mypy==0.790 # via -r dev-requirements.in -packaging==20.8 # via pytest, sphinx, tox -pathspec==0.8.1 # via black -pep8-naming==0.11.1 # via -r dev-requirements.in -pluggy==0.13.1 # via pytest, tox -py==1.10.0 # via pytest, tox -pycodestyle==2.6.0 # via flake8 -pyflakes==2.2.0 # via flake8 -pygments==2.7.3 # via sphinx -pyparsing==2.4.7 # via packaging -pytest-cov==2.10.1 # via -r dev-requirements.in -pytest==6.2.1 # via -r dev-requirements.in, pytest-cov -pytz==2020.4 # via babel -regex==2020.11.13 # via black -requests==2.25.1 # via sphinx -six==1.15.0 # via tox, virtualenv -snowballstemmer==2.0.0 # via sphinx -sphinx==3.3.1 # via -r dev-requirements.in -sphinxcontrib-applehelp==1.0.2 # via sphinx -sphinxcontrib-devhelp==1.0.2 # via sphinx -sphinxcontrib-htmlhelp==1.0.3 # via sphinx -sphinxcontrib-jsmath==1.0.1 # via sphinx -sphinxcontrib-qthelp==1.0.3 # via sphinx -sphinxcontrib-serializinghtml==1.1.4 # via sphinx -toml==0.10.2 # via black, pytest, tox -tox==3.20.1 # via -r dev-requirements.in -typed-ast==1.4.1 # via black, mypy -typing-extensions==3.7.4.3 # via black, mypy -urllib3==1.26.2 # via requests -virtualenv==20.2.2 # via tox +alabaster==0.7.12 + # via sphinx +appdirs==1.4.4 + # via + # black + # virtualenv +attrs==20.3.0 + # via pytest +babel==2.9.0 + # via sphinx +black==20.8b1 + # via -r dev-requirements.in +bleach==3.2.1 + # via readme-renderer +certifi==2020.12.5 + # via requests +chardet==4.0.0 + # via requests +click==7.1.2 + # via black +colorama==0.4.4 + # via twine +coverage==5.3.1 + # via pytest-cov +distlib==0.3.1 + # via virtualenv +docutils==0.16 + # via + # readme-renderer + # sphinx +filelock==3.0.12 + # via + # tox + # virtualenv +flake8-polyfill==1.0.2 + # via pep8-naming +flake8==3.8.4 + # via + # -r dev-requirements.in + # flake8-polyfill +idna==2.10 + # via requests +imagesize==1.2.0 + # via sphinx +iniconfig==1.1.1 + # via pytest +isort==5.7.0 + # via -r dev-requirements.in +jinja2==2.11.2 + # via sphinx +keyring==21.8.0 + # via twine +markupsafe==1.1.1 + # via jinja2 +mccabe==0.6.1 + # via flake8 +mypy-extensions==0.4.3 + # via + # black + # mypy +mypy==0.790 + # via -r dev-requirements.in +packaging==20.8 + # via + # bleach + # pytest + # sphinx + # tox +pathspec==0.8.1 + # via black +pep8-naming==0.11.1 + # via -r dev-requirements.in +pkginfo==1.6.1 + # via twine +pluggy==0.13.1 + # via + # pytest + # tox +py==1.10.0 + # via + # pytest + # tox +pycodestyle==2.6.0 + # via flake8 +pyflakes==2.2.0 + # via flake8 +pygments==2.7.3 + # via + # readme-renderer + # sphinx +pyparsing==2.4.7 + # via packaging +pytest-cov==2.10.1 + # via -r dev-requirements.in +pytest==6.2.1 + # via + # -r dev-requirements.in + # pytest-cov +pytz==2020.5 + # via babel +readme-renderer==28.0 + # via twine +regex==2020.11.13 + # via black +requests-toolbelt==0.9.1 + # via twine +requests==2.25.1 + # via + # requests-toolbelt + # sphinx + # twine +rfc3986==1.4.0 + # via twine +six==1.15.0 + # via + # bleach + # readme-renderer + # tox + # virtualenv +snowballstemmer==2.0.0 + # via sphinx +sphinx==3.4.3 + # via -r dev-requirements.in +sphinxcontrib-applehelp==1.0.2 + # via sphinx +sphinxcontrib-devhelp==1.0.2 + # via sphinx +sphinxcontrib-htmlhelp==1.0.3 + # via sphinx +sphinxcontrib-jsmath==1.0.1 + # via sphinx +sphinxcontrib-qthelp==1.0.3 + # via sphinx +sphinxcontrib-serializinghtml==1.1.4 + # via sphinx +toml==0.10.2 + # via + # black + # pytest + # tox +tox==3.21.0 + # via -r dev-requirements.in +tqdm==4.55.1 + # via twine +twine==3.3.0 + # via -r dev-requirements.in +typed-ast==1.4.2 + # via + # black + # mypy +typing-extensions==3.7.4.3 + # via + # black + # mypy +urllib3==1.26.2 + # via requests +virtualenv==20.2.2 + # via tox +webencodings==0.5.1 + # via bleach # The following packages are considered to be unsafe in a requirements file: # setuptools diff --git a/requirements.txt b/requirements.txt index 8fbbf88..ed86b36 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile # To update, run: # -# pip-compile +# pip-compile requirements.in # appdirs==1.4.4 # via virtualenv @@ -22,7 +22,7 @@ click==7.1.2 # click-completion distlib==0.3.1 # via virtualenv -dnspython==2.0.0 +dnspython==2.1.0 # via py3-validate-email filelock==3.0.12 # via From d5a34b4d11dd8350b6b27d1a70b349544f929160 Mon Sep 17 00:00:00 2001 From: Hemna Date: Sat, 9 Jan 2021 09:58:56 -0500 Subject: [PATCH 6/7] refactor Plugin objects to plugins directory This patch moves all of the plugins out of plugin.py into their own separate plugins/.py file. This makes it easier to maintain each plugin. NOTE: You will have to update your ~/.config/aprsd/aprsd.yml to change the python location path for each plugin enabled. For example: OLD: enabled_plugins: - aprsd.plugin.EmailPlugin TO NEW enabled_plugins: - aprsd.plugins.email.EmailPlugin --- Makefile | 2 +- aprsd/plugin.py | 431 +++++--------------------------------- aprsd/plugins/__init__.py | 0 aprsd/plugins/email.py | 88 ++++++++ aprsd/plugins/fortune.py | 37 ++++ aprsd/plugins/location.py | 77 +++++++ aprsd/plugins/ping.py | 25 +++ aprsd/plugins/query.py | 43 ++++ aprsd/plugins/time.py | 28 +++ aprsd/plugins/version.py | 22 ++ aprsd/plugins/weather.py | 53 +++++ tests/test_plugin.py | 29 +-- 12 files changed, 442 insertions(+), 393 deletions(-) create mode 100644 aprsd/plugins/__init__.py create mode 100644 aprsd/plugins/email.py create mode 100644 aprsd/plugins/fortune.py create mode 100644 aprsd/plugins/location.py create mode 100644 aprsd/plugins/ping.py create mode 100644 aprsd/plugins/query.py create mode 100644 aprsd/plugins/time.py create mode 100644 aprsd/plugins/version.py create mode 100644 aprsd/plugins/weather.py diff --git a/Makefile b/Makefile index 5340686..e6cb2aa 100644 --- a/Makefile +++ b/Makefile @@ -55,4 +55,4 @@ check: .venv/bin/tox # Code format check with isort and black tox -epep8 fix: .venv/bin/tox # fixes code formatting with isort and black - tox -efmt \ No newline at end of file + tox -efmt diff --git a/aprsd/plugin.py b/aprsd/plugin.py index eae9569..224b475 100644 --- a/aprsd/plugin.py +++ b/aprsd/plugin.py @@ -3,19 +3,11 @@ import abc import fnmatch import importlib import inspect -import json import logging import os import re -import shutil -import subprocess -import time -import aprsd -from aprsd import email, messaging -from aprsd.fuzzyclock import fuzzy import pluggy -import requests from thesmuggler import smuggle # setup the global logger @@ -25,17 +17,61 @@ hookspec = pluggy.HookspecMarker("aprsd") hookimpl = pluggy.HookimplMarker("aprsd") CORE_PLUGINS = [ - "aprsd.plugin.EmailPlugin", - "aprsd.plugin.FortunePlugin", - "aprsd.plugin.LocationPlugin", - "aprsd.plugin.PingPlugin", - "aprsd.plugin.QueryPlugin", - "aprsd.plugin.TimePlugin", - "aprsd.plugin.WeatherPlugin", - "aprsd.plugin.VersionPlugin", + "aprsd.plugins.email.EmailPlugin", + "aprsd.plugins.fortune.FortunePlugin", + "aprsd.plugins.location.LocationPlugin", + "aprsd.plugins.ping.PingPlugin", + "aprsd.plugins.query.QueryPlugin", + "aprsd.plugins.time.TimePlugin", + "aprsd.plugins.weather.WeatherPlugin", + "aprsd.plugins.version.VersionPlugin", ] +class APRSDCommandSpec: + """A hook specification namespace.""" + + @hookspec + def run(self, fromcall, message, ack): + """My special little hook that you can customize.""" + pass + + +class APRSDPluginBase(metaclass=abc.ABCMeta): + def __init__(self, config): + """The aprsd config object is stored.""" + self.config = config + + @property + def command_name(self): + """The usage string help.""" + raise NotImplementedError + + @property + def command_regex(self): + """The regex to match from the caller""" + raise NotImplementedError + + @property + def version(self): + """Version""" + raise NotImplementedError + + @hookimpl + def run(self, fromcall, message, ack): + if re.search(self.command_regex, message): + return self.command(fromcall, message, ack) + + @abc.abstractmethod + def command(self, fromcall, message, ack): + """This is the command that runs when the regex matches. + + To reply with a message over the air, return a string + to send. + """ + pass + + class PluginManager: # The singleton instance object for this class _instance = None @@ -197,366 +233,3 @@ class PluginManager: def get_plugins(self): return self._pluggy_pm.get_plugins() - - -class APRSDCommandSpec: - """A hook specification namespace.""" - - @hookspec - def run(self, fromcall, message, ack): - """My special little hook that you can customize.""" - pass - - -class APRSDPluginBase(metaclass=abc.ABCMeta): - def __init__(self, config): - """The aprsd config object is stored.""" - self.config = config - - @property - def command_name(self): - """The usage string help.""" - raise NotImplementedError - - @property - def command_regex(self): - """The regex to match from the caller""" - raise NotImplementedError - - @property - def version(self): - """Version""" - raise NotImplementedError - - @hookimpl - def run(self, fromcall, message, ack): - if re.search(self.command_regex, message): - return self.command(fromcall, message, ack) - - @abc.abstractmethod - def command(self, fromcall, message, ack): - """This is the command that runs when the regex matches. - - To reply with a message over the air, return a string - to send. - """ - pass - - -class FortunePlugin(APRSDPluginBase): - """Fortune.""" - - version = "1.0" - command_regex = "^[fF]" - command_name = "fortune" - - def command(self, fromcall, message, ack): - LOG.info("FortunePlugin") - reply = None - - fortune_path = shutil.which("fortune") - if not fortune_path: - reply = "Fortune command not installed" - return reply - - try: - process = subprocess.Popen( - [fortune_path, "-s", "-n 60"], - stdout=subprocess.PIPE, - ) - reply = process.communicate()[0] - reply = reply.decode(errors="ignore").rstrip() - except Exception as ex: - reply = "Fortune command failed '{}'".format(ex) - LOG.error(reply) - - return reply - - -class LocationPlugin(APRSDPluginBase): - """Location!""" - - version = "1.0" - command_regex = "^[lL]" - command_name = "location" - - config_items = {"apikey": "aprs.fi api key here"} - - def command(self, fromcall, message, ack): - LOG.info("Location Plugin") - # get last location of a callsign, get descriptive name from weather service - try: - # optional second argument is a callsign to search - a = re.search(r"^.*\s+(.*)", message) - if a is not None: - searchcall = a.group(1) - searchcall = searchcall.upper() - else: - # if no second argument, search for calling station - searchcall = fromcall - url = ( - "http://api.aprs.fi/api/get?name=" - + searchcall - + "&what=loc&apikey=104070.f9lE8qg34L8MZF&format=json" - ) - response = requests.get(url) - # aprs_data = json.loads(response.read()) - aprs_data = json.loads(response.text) - LOG.debug("LocationPlugin: aprs_data = {}".format(aprs_data)) - lat = aprs_data["entries"][0]["lat"] - lon = aprs_data["entries"][0]["lng"] - try: # altitude not always provided - alt = aprs_data["entries"][0]["altitude"] - except Exception: - alt = 0 - altfeet = int(alt * 3.28084) - aprs_lasttime_seconds = aprs_data["entries"][0]["lasttime"] - # aprs_lasttime_seconds = aprs_lasttime_seconds.encode( - # "ascii", errors="ignore" - # ) # unicode to ascii - delta_seconds = time.time() - int(aprs_lasttime_seconds) - delta_hours = delta_seconds / 60 / 60 - url2 = ( - "https://forecast.weather.gov/MapClick.php?lat=" - + str(lat) - + "&lon=" - + str(lon) - + "&FcstType=json" - ) - response2 = requests.get(url2) - wx_data = json.loads(response2.text) - - reply = "{}: {} {}' {},{} {}h ago".format( - searchcall, - wx_data["location"]["areaDescription"], - str(altfeet), - str(alt), - str(lon), - str("%.1f" % round(delta_hours, 1)), - ).rstrip() - except Exception as e: - LOG.debug("Locate failed with: " + "%s" % str(e)) - reply = "Unable to find station " + searchcall + ". Sending beacons?" - - return reply - - -class PingPlugin(APRSDPluginBase): - """Ping.""" - - version = "1.0" - command_regex = "^[pP]" - command_name = "ping" - - def command(self, fromcall, message, ack): - LOG.info("PINGPlugin") - stm = time.localtime() - h = stm.tm_hour - m = stm.tm_min - s = stm.tm_sec - reply = ( - "Pong! " + str(h).zfill(2) + ":" + str(m).zfill(2) + ":" + str(s).zfill(2) - ) - return reply.rstrip() - - -class QueryPlugin(APRSDPluginBase): - """Query command.""" - - version = "1.0" - command_regex = r"^\?.*" - command_name = "query" - - def command(self, fromcall, message, ack): - LOG.info("Query COMMAND") - - tracker = messaging.MsgTrack() - reply = "Pending Messages ({})".format(len(tracker)) - - searchstring = "^" + self.config["ham"]["callsign"] + ".*" - # only I can do admin commands - if re.search(searchstring, fromcall): - r = re.search(r"^\?-\*", message) - if r is not None: - if len(tracker) > 0: - reply = "Resend ALL Delayed msgs" - LOG.debug(reply) - tracker.restart_delayed() - else: - reply = "No Delayed Msgs" - LOG.debug(reply) - return reply - - r = re.search(r"^\?-[fF]!", message) - if r is not None: - reply = "Deleting ALL Delayed msgs." - LOG.debug(reply) - tracker.flush() - return reply - - return reply - - -class TimePlugin(APRSDPluginBase): - """Time command.""" - - version = "1.0" - command_regex = "^[tT]" - command_name = "time" - - def command(self, fromcall, message, ack): - LOG.info("TIME COMMAND") - stm = time.localtime() - h = stm.tm_hour - m = stm.tm_min - cur_time = fuzzy(h, m, 1) - reply = "{} ({}:{} PDT) ({})".format( - cur_time, - str(h), - str(m).rjust(2, "0"), - message.rstrip(), - ) - return reply - - -class WeatherPlugin(APRSDPluginBase): - """Weather Command""" - - version = "1.0" - command_regex = "^[wW]" - command_name = "weather" - - def command(self, fromcall, message, ack): - LOG.info("Weather Plugin") - try: - url = ( - "http://api.aprs.fi/api/get?" - "&what=loc&apikey=104070.f9lE8qg34L8MZF&format=json" - "&name=%s" % fromcall - ) - response = requests.get(url) - # aprs_data = json.loads(response.read()) - aprs_data = json.loads(response.text) - lat = aprs_data["entries"][0]["lat"] - lon = aprs_data["entries"][0]["lng"] - url2 = ( - "https://forecast.weather.gov/MapClick.php?lat=%s" - "&lon=%s&FcstType=json" % (lat, lon) - ) - response2 = requests.get(url2) - # wx_data = json.loads(response2.read()) - wx_data = json.loads(response2.text) - reply = ( - "%sF(%sF/%sF) %s. %s, %s." - % ( - wx_data["currentobservation"]["Temp"], - wx_data["data"]["temperature"][0], - wx_data["data"]["temperature"][1], - wx_data["data"]["weather"][0], - wx_data["time"]["startPeriodName"][1], - wx_data["data"]["weather"][1], - ) - ).rstrip() - LOG.debug("reply: '{}' ".format(reply)) - except Exception as e: - LOG.debug("Weather failed with: " + "%s" % str(e)) - reply = "Unable to find you (send beacon?)" - - return reply - - -class EmailPlugin(APRSDPluginBase): - """Email Plugin.""" - - version = "1.0" - command_regex = "^-.*" - command_name = "email" - - # message_number:time combos so we don't resend the same email in - # five mins {int:int} - email_sent_dict = {} - - def command(self, fromcall, message, ack): - LOG.info("Email COMMAND") - reply = None - - searchstring = "^" + self.config["ham"]["callsign"] + ".*" - # only I can do email - if re.search(searchstring, fromcall): - # digits only, first one is number of emails to resend - r = re.search("^-([0-9])[0-9]*$", message) - if r is not None: - LOG.debug("RESEND EMAIL") - email.resend_email(r.group(1), fromcall) - reply = messaging.NULL_MESSAGE - # -user@address.com body of email - elif re.search(r"^-([A-Za-z0-9_\-\.@]+) (.*)", message): - # (same search again) - a = re.search(r"^-([A-Za-z0-9_\-\.@]+) (.*)", message) - if a is not None: - to_addr = a.group(1) - content = a.group(2) - - email_address = email.get_email_from_shortcut(to_addr) - if not email_address: - reply = "Bad email address" - return reply - - # send recipient link to aprs.fi map - if content == "mapme": - content = "Click for my location: http://aprs.fi/{}".format( - self.config["ham"]["callsign"], - ) - too_soon = 0 - now = time.time() - # see if we sent this msg number recently - if ack in self.email_sent_dict: - # BUG(hemna) - when we get a 2 different email command - # with the same ack #, we don't send it. - timedelta = now - self.email_sent_dict[ack] - if timedelta < 300: # five minutes - too_soon = 1 - if not too_soon or ack == 0: - LOG.info("Send email '{}'".format(content)) - send_result = email.send_email(to_addr, content) - reply = messaging.NULL_MESSAGE - if send_result != 0: - reply = "-{} failed".format(to_addr) - # messaging.send_message(fromcall, "-" + to_addr + " failed") - else: - # clear email sent dictionary if somehow goes over 100 - if len(self.email_sent_dict) > 98: - LOG.debug( - "DEBUG: email_sent_dict is big (" - + str(len(self.email_sent_dict)) - + ") clearing out.", - ) - self.email_sent_dict.clear() - self.email_sent_dict[ack] = now - else: - LOG.info( - "Email for message number " - + ack - + " recently sent, not sending again.", - ) - else: - reply = "Bad email address" - # messaging.send_message(fromcall, "Bad email address") - - return reply - - -class VersionPlugin(APRSDPluginBase): - """Version of APRSD Plugin.""" - - version = "1.0" - command_regex = "^[vV]" - command_name = "version" - - # message_number:time combos so we don't resend the same email in - # five mins {int:int} - email_sent_dict = {} - - def command(self, fromcall, message, ack): - LOG.info("Version COMMAND") - return "APRSD version '{}'".format(aprsd.__version__) diff --git a/aprsd/plugins/__init__.py b/aprsd/plugins/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/aprsd/plugins/email.py b/aprsd/plugins/email.py new file mode 100644 index 0000000..1372327 --- /dev/null +++ b/aprsd/plugins/email.py @@ -0,0 +1,88 @@ +import logging +import re +import time + +from aprsd import email, messaging, plugin + +LOG = logging.getLogger("APRSD") + + +class EmailPlugin(plugin.APRSDPluginBase): + """Email Plugin.""" + + version = "1.0" + command_regex = "^-.*" + command_name = "email" + + # message_number:time combos so we don't resend the same email in + # five mins {int:int} + email_sent_dict = {} + + def command(self, fromcall, message, ack): + LOG.info("Email COMMAND") + reply = None + + searchstring = "^" + self.config["ham"]["callsign"] + ".*" + # only I can do email + if re.search(searchstring, fromcall): + # digits only, first one is number of emails to resend + r = re.search("^-([0-9])[0-9]*$", message) + if r is not None: + LOG.debug("RESEND EMAIL") + email.resend_email(r.group(1), fromcall) + reply = messaging.NULL_MESSAGE + # -user@address.com body of email + elif re.search(r"^-([A-Za-z0-9_\-\.@]+) (.*)", message): + # (same search again) + a = re.search(r"^-([A-Za-z0-9_\-\.@]+) (.*)", message) + if a is not None: + to_addr = a.group(1) + content = a.group(2) + + email_address = email.get_email_from_shortcut(to_addr) + if not email_address: + reply = "Bad email address" + return reply + + # send recipient link to aprs.fi map + if content == "mapme": + content = "Click for my location: http://aprs.fi/{}".format( + self.config["ham"]["callsign"], + ) + too_soon = 0 + now = time.time() + # see if we sent this msg number recently + if ack in self.email_sent_dict: + # BUG(hemna) - when we get a 2 different email command + # with the same ack #, we don't send it. + timedelta = now - self.email_sent_dict[ack] + if timedelta < 300: # five minutes + too_soon = 1 + if not too_soon or ack == 0: + LOG.info("Send email '{}'".format(content)) + send_result = email.send_email(to_addr, content) + reply = messaging.NULL_MESSAGE + if send_result != 0: + reply = "-{} failed".format(to_addr) + # messaging.send_message(fromcall, "-" + to_addr + " failed") + else: + # clear email sent dictionary if somehow goes over 100 + if len(self.email_sent_dict) > 98: + LOG.debug( + "DEBUG: email_sent_dict is big (" + + str(len(self.email_sent_dict)) + + ") clearing out.", + ) + self.email_sent_dict.clear() + self.email_sent_dict[ack] = now + else: + LOG.info( + "Email for message number " + + ack + + " recently sent, not sending again.", + ) + else: + reply = "Bad email address" + # messaging.send_message(fromcall, "Bad email address") + + return reply diff --git a/aprsd/plugins/fortune.py b/aprsd/plugins/fortune.py new file mode 100644 index 0000000..52e59e1 --- /dev/null +++ b/aprsd/plugins/fortune.py @@ -0,0 +1,37 @@ +import logging +import shutil +import subprocess + +from aprsd import plugin + +LOG = logging.getLogger("APRSD") + + +class FortunePlugin(plugin.APRSDPluginBase): + """Fortune.""" + + version = "1.0" + command_regex = "^[fF]" + command_name = "fortune" + + def command(self, fromcall, message, ack): + LOG.info("FortunePlugin") + reply = None + + fortune_path = shutil.which("fortune") + if not fortune_path: + reply = "Fortune command not installed" + return reply + + try: + process = subprocess.Popen( + [fortune_path, "-s", "-n 60"], + stdout=subprocess.PIPE, + ) + reply = process.communicate()[0] + reply = reply.decode(errors="ignore").rstrip() + except Exception as ex: + reply = "Fortune command failed '{}'".format(ex) + LOG.error(reply) + + return reply diff --git a/aprsd/plugins/location.py b/aprsd/plugins/location.py new file mode 100644 index 0000000..be75e34 --- /dev/null +++ b/aprsd/plugins/location.py @@ -0,0 +1,77 @@ +import json +import logging +import re +import time + +from aprsd import plugin +import requests + +LOG = logging.getLogger("APRSD") + + +class LocationPlugin(plugin.APRSDPluginBase): + """Location!""" + + version = "1.0" + command_regex = "^[lL]" + command_name = "location" + + config_items = {"apikey": "aprs.fi api key here"} + + def command(self, fromcall, message, ack): + LOG.info("Location Plugin") + # get last location of a callsign, get descriptive name from weather service + try: + # optional second argument is a callsign to search + a = re.search(r"^.*\s+(.*)", message) + if a is not None: + searchcall = a.group(1) + searchcall = searchcall.upper() + else: + # if no second argument, search for calling station + searchcall = fromcall + url = ( + "http://api.aprs.fi/api/get?name=" + + searchcall + + "&what=loc&apikey=104070.f9lE8qg34L8MZF&format=json" + ) + response = requests.get(url) + # aprs_data = json.loads(response.read()) + aprs_data = json.loads(response.text) + LOG.debug("LocationPlugin: aprs_data = {}".format(aprs_data)) + lat = aprs_data["entries"][0]["lat"] + lon = aprs_data["entries"][0]["lng"] + try: # altitude not always provided + alt = aprs_data["entries"][0]["altitude"] + except Exception: + alt = 0 + altfeet = int(alt * 3.28084) + aprs_lasttime_seconds = aprs_data["entries"][0]["lasttime"] + # aprs_lasttime_seconds = aprs_lasttime_seconds.encode( + # "ascii", errors="ignore" + # ) # unicode to ascii + delta_seconds = time.time() - int(aprs_lasttime_seconds) + delta_hours = delta_seconds / 60 / 60 + url2 = ( + "https://forecast.weather.gov/MapClick.php?lat=" + + str(lat) + + "&lon=" + + str(lon) + + "&FcstType=json" + ) + response2 = requests.get(url2) + wx_data = json.loads(response2.text) + + reply = "{}: {} {}' {},{} {}h ago".format( + searchcall, + wx_data["location"]["areaDescription"], + str(altfeet), + str(alt), + str(lon), + str("%.1f" % round(delta_hours, 1)), + ).rstrip() + except Exception as e: + LOG.debug("Locate failed with: " + "%s" % str(e)) + reply = "Unable to find station " + searchcall + ". Sending beacons?" + + return reply diff --git a/aprsd/plugins/ping.py b/aprsd/plugins/ping.py new file mode 100644 index 0000000..754da05 --- /dev/null +++ b/aprsd/plugins/ping.py @@ -0,0 +1,25 @@ +import logging +import time + +from aprsd import plugin + +LOG = logging.getLogger("APRSD") + + +class PingPlugin(plugin.APRSDPluginBase): + """Ping.""" + + version = "1.0" + command_regex = "^[pP]" + command_name = "ping" + + def command(self, fromcall, message, ack): + LOG.info("PINGPlugin") + stm = time.localtime() + h = stm.tm_hour + m = stm.tm_min + s = stm.tm_sec + reply = ( + "Pong! " + str(h).zfill(2) + ":" + str(m).zfill(2) + ":" + str(s).zfill(2) + ) + return reply.rstrip() diff --git a/aprsd/plugins/query.py b/aprsd/plugins/query.py new file mode 100644 index 0000000..e5a4bfc --- /dev/null +++ b/aprsd/plugins/query.py @@ -0,0 +1,43 @@ +import logging +import re + +from aprsd import messaging, plugin + +LOG = logging.getLogger("APRSD") + + +class QueryPlugin(plugin.APRSDPluginBase): + """Query command.""" + + version = "1.0" + command_regex = r"^\?.*" + command_name = "query" + + def command(self, fromcall, message, ack): + LOG.info("Query COMMAND") + + tracker = messaging.MsgTrack() + reply = "Pending Messages ({})".format(len(tracker)) + + searchstring = "^" + self.config["ham"]["callsign"] + ".*" + # only I can do admin commands + if re.search(searchstring, fromcall): + r = re.search(r"^\?-\*", message) + if r is not None: + if len(tracker) > 0: + reply = "Resend ALL Delayed msgs" + LOG.debug(reply) + tracker.restart_delayed() + else: + reply = "No Delayed Msgs" + LOG.debug(reply) + return reply + + r = re.search(r"^\?-[fF]!", message) + if r is not None: + reply = "Deleting ALL Delayed msgs." + LOG.debug(reply) + tracker.flush() + return reply + + return reply diff --git a/aprsd/plugins/time.py b/aprsd/plugins/time.py new file mode 100644 index 0000000..3c0c3b9 --- /dev/null +++ b/aprsd/plugins/time.py @@ -0,0 +1,28 @@ +import logging +import time + +from aprsd import fuzzyclock, plugin + +LOG = logging.getLogger("APRSD") + + +class TimePlugin(plugin.APRSDPluginBase): + """Time command.""" + + version = "1.0" + command_regex = "^[tT]" + command_name = "time" + + def command(self, fromcall, message, ack): + LOG.info("TIME COMMAND") + stm = time.localtime() + h = stm.tm_hour + m = stm.tm_min + cur_time = fuzzyclock.fuzzy(h, m, 1) + reply = "{} ({}:{} PDT) ({})".format( + cur_time, + str(h), + str(m).rjust(2, "0"), + message.rstrip(), + ) + return reply diff --git a/aprsd/plugins/version.py b/aprsd/plugins/version.py new file mode 100644 index 0000000..d037ac7 --- /dev/null +++ b/aprsd/plugins/version.py @@ -0,0 +1,22 @@ +import logging + +import aprsd +from aprsd import plugin + +LOG = logging.getLogger("APRSD") + + +class VersionPlugin(plugin.APRSDPluginBase): + """Version of APRSD Plugin.""" + + version = "1.0" + command_regex = "^[vV]" + command_name = "version" + + # message_number:time combos so we don't resend the same email in + # five mins {int:int} + email_sent_dict = {} + + def command(self, fromcall, message, ack): + LOG.info("Version COMMAND") + return "APRSD version '{}'".format(aprsd.__version__) diff --git a/aprsd/plugins/weather.py b/aprsd/plugins/weather.py new file mode 100644 index 0000000..6071c1e --- /dev/null +++ b/aprsd/plugins/weather.py @@ -0,0 +1,53 @@ +import json +import logging + +from aprsd import plugin +import requests + +LOG = logging.getLogger("APRSD") + + +class WeatherPlugin(plugin.APRSDPluginBase): + """Weather Command""" + + version = "1.0" + command_regex = "^[wW]" + command_name = "weather" + + def command(self, fromcall, message, ack): + LOG.info("Weather Plugin") + try: + url = ( + "http://api.aprs.fi/api/get?" + "&what=loc&apikey=104070.f9lE8qg34L8MZF&format=json" + "&name=%s" % fromcall + ) + response = requests.get(url) + # aprs_data = json.loads(response.read()) + aprs_data = json.loads(response.text) + lat = aprs_data["entries"][0]["lat"] + lon = aprs_data["entries"][0]["lng"] + url2 = ( + "https://forecast.weather.gov/MapClick.php?lat=%s" + "&lon=%s&FcstType=json" % (lat, lon) + ) + response2 = requests.get(url2) + # wx_data = json.loads(response2.read()) + wx_data = json.loads(response2.text) + reply = ( + "%sF(%sF/%sF) %s. %s, %s." + % ( + wx_data["currentobservation"]["Temp"], + wx_data["data"]["temperature"][0], + wx_data["data"]["temperature"][1], + wx_data["data"]["weather"][0], + wx_data["time"]["startPeriodName"][1], + wx_data["data"]["weather"][1], + ) + ).rstrip() + LOG.debug("reply: '{}' ".format(reply)) + except Exception as e: + LOG.debug("Weather failed with: " + "%s" % str(e)) + reply = "Unable to find you (send beacon?)" + + return reply diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 8512f34..48e3c44 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -2,8 +2,11 @@ import unittest from unittest import mock import aprsd -from aprsd import plugin from aprsd.fuzzyclock import fuzzy +from aprsd.plugins import fortune as fortune_plugin +from aprsd.plugins import ping as ping_plugin +from aprsd.plugins import time as time_plugin +from aprsd.plugins import version as version_plugin class TestPlugin(unittest.TestCase): @@ -14,17 +17,17 @@ class TestPlugin(unittest.TestCase): @mock.patch("shutil.which") def test_fortune_fail(self, mock_which): - fortune_plugin = plugin.FortunePlugin(self.config) + fortune = fortune_plugin.FortunePlugin(self.config) mock_which.return_value = None message = "fortune" expected = "Fortune command not installed" - actual = fortune_plugin.run(self.fromcall, message, self.ack) + actual = fortune.run(self.fromcall, message, self.ack) self.assertEqual(expected, actual) @mock.patch("subprocess.Popen") @mock.patch("shutil.which") def test_fortune_success(self, mock_which, mock_popen): - fortune_plugin = plugin.FortunePlugin(self.config) + fortune = fortune_plugin.FortunePlugin(self.config) mock_which.return_value = "/usr/bin/games" mock_process = mock.MagicMock() @@ -33,7 +36,7 @@ class TestPlugin(unittest.TestCase): message = "fortune" expected = "Funny fortune" - actual = fortune_plugin.run(self.fromcall, message, self.ack) + actual = fortune.run(self.fromcall, message, self.ack) self.assertEqual(expected, actual) @mock.patch("time.localtime") @@ -43,13 +46,13 @@ class TestPlugin(unittest.TestCase): m = fake_time.tm_min = 12 fake_time.tm_sec = 55 mock_time.return_value = fake_time - time_plugin = plugin.TimePlugin(self.config) + time = time_plugin.TimePlugin(self.config) fromcall = "KFART" message = "location" ack = 1 - actual = time_plugin.run(fromcall, message, ack) + actual = time.run(fromcall, message, ack) self.assertEqual(None, actual) cur_time = fuzzy(h, m, 1) @@ -61,7 +64,7 @@ class TestPlugin(unittest.TestCase): str(m).rjust(2, "0"), message.rstrip(), ) - actual = time_plugin.run(fromcall, message, ack) + actual = time.run(fromcall, message, ack) self.assertEqual(expected, actual) @mock.patch("time.localtime") @@ -72,7 +75,7 @@ class TestPlugin(unittest.TestCase): s = fake_time.tm_sec = 55 mock_time.return_value = fake_time - ping = plugin.PingPlugin(self.config) + ping = ping_plugin.PingPlugin(self.config) fromcall = "KFART" message = "location" @@ -102,19 +105,19 @@ class TestPlugin(unittest.TestCase): def test_version(self): expected = "APRSD version '{}'".format(aprsd.__version__) - version_plugin = plugin.VersionPlugin(self.config) + version = version_plugin.VersionPlugin(self.config) fromcall = "KFART" message = "No" ack = 1 - actual = version_plugin.run(fromcall, message, ack) + actual = version.run(fromcall, message, ack) self.assertEqual(None, actual) message = "version" - actual = version_plugin.run(fromcall, message, ack) + actual = version.run(fromcall, message, ack) self.assertEqual(expected, actual) message = "Version" - actual = version_plugin.run(fromcall, message, ack) + actual = version.run(fromcall, message, ack) self.assertEqual(expected, actual) From ee2aeb5157344ea02852c61e6acb25c3e7272f28 Mon Sep 17 00:00:00 2001 From: Hemna Date: Sat, 9 Jan 2021 14:12:13 -0500 Subject: [PATCH 7/7] Added Sphinx based documentation This patch adds the docuemntation source tree in docs. You can build the documentation with tox -edocs View the documentation by opening a browser and viewing aprsd/docs/_build/index.html --- LICENSE | 175 +++++++++++++++ README.rst | 127 +++++------ docs/_static/.keep | 0 docs/_templates/.keep | 0 docs/apidoc/aprsd.plugins.rst | 77 +++++++ docs/apidoc/aprsd.rst | 93 ++++++++ docs/apidoc/modules.rst | 7 + docs/clean_docs.py | 22 ++ docs/conf.py | 188 ++++++++++++++++ docs/configure.rst | 71 ++++++ docs/index.rst | 30 +++ docs/install.rst | 67 ++++++ docs/links.rst | 31 +++ docs/plugin.rst | 55 +++++ docs/readme.rst | 392 ++++++++++++++++++++++++++++++++++ docs/server.rst | 53 +++++ setup.cfg | 20 +- tox.ini | 11 +- 18 files changed, 1338 insertions(+), 81 deletions(-) create mode 100644 LICENSE create mode 100644 docs/_static/.keep create mode 100644 docs/_templates/.keep create mode 100644 docs/apidoc/aprsd.plugins.rst create mode 100644 docs/apidoc/aprsd.rst create mode 100644 docs/apidoc/modules.rst create mode 100644 docs/clean_docs.py create mode 100644 docs/conf.py create mode 100644 docs/configure.rst create mode 100644 docs/index.rst create mode 100644 docs/install.rst create mode 100644 docs/links.rst create mode 100644 docs/plugin.rst create mode 100644 docs/readme.rst create mode 100644 docs/server.rst diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..67db858 --- /dev/null +++ b/LICENSE @@ -0,0 +1,175 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. diff --git a/README.rst b/README.rst index a540d8d..3ba3bd0 100644 --- a/README.rst +++ b/README.rst @@ -2,6 +2,9 @@ APRSD ===== +.. image:: https://badge.fury.io/py/aprsd.svg + :target: https://badge.fury.io/py/aprsd + .. image:: https://github.com/craigerl/aprsd/workflows/python/badge.svg :target: https://github.com/craigerl/aprsd/actions @@ -11,9 +14,17 @@ APRSD .. image:: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336 :target: https://timothycrosley.github.io/isort/ +.. image:: https://static.pepy.tech/personalized-badge/aprsd?period=month&units=international_system&left_color=black&right_color=orange&left_text=Downloads + :target: https://pepy.tech/project/aprsd + .. contents:: :local: -Listen on amateur radio aprs-is network for messages and respond to them. +`APRSD `_ is a Ham radio `APRS `_ message command gateway built on python. + +APRSD listens on amateur radio aprs-is network for messages and respond to them. +It has a plugin architecture for extensibility. Users of APRSD can write their own +plugins that can respond to APRS-IS messages. + You must have an amateur radio callsign to use this software. APRSD gets messages for the configured HAM callsign, and sends those messages to a list of plugins for processing. There are a set of core plugins that @@ -27,14 +38,13 @@ Typical use case Ham radio operator using an APRS enabled HAM radio sends a message to check the weather. an APRS message is sent, and then picked up by APRSD. The APRS packet is decoded, and the message is sent through the list of plugins -for processing. The WeatherPlugin picks up the message, fetches the weather +for processing. For example, the WeatherPlugin picks up the message, fetches the weather for the area around the user who sent the request, and then responds with the weather conditions in that area. - APRSD Capabilities ------------------- +================== * server - The main aprsd server processor. Send/Rx APRS messages to HAM callsign * send-message - use aprsd to send a command/message to aprsd server. Used for development testing @@ -52,6 +62,7 @@ If it matches, the plugin runs. IF the regex doesn't match, the plugin is skipp * FortunePlugin - Replies with old unix fortune random fortune! * LocationPlugin - Checks location of ham operator * PingPlugin - Sends pong with timestamp +* QueryPlugin - Allows querying the list of delayed messages that were not ACK'd by radio * TimePlugin - Current time of day * WeatherPlugin - Get weather conditions for current location of HAM callsign * VersionPlugin - Reports the version information for aprsd @@ -72,6 +83,7 @@ Current messages this will respond to: -email_addr email text = send an email, say "mapme" to send a current position/map -2 = resend the last 2 emails from your imap inbox to this radio p(ing) = respond with Pong!/time + v(ersion) = Respond with current APRSD Version string anything else = respond with usage @@ -86,7 +98,7 @@ email server, and associated logins, passwords. search for "yourdomain", Installation: -------------- +============= pip install aprsd @@ -118,13 +130,14 @@ Help show Show the click-completion-command completion code -Commands --------- -sample-config +Commands +======== + +Configuration ============= This command outputs a sample config yml formatted block that you can edit -and use to pass in to aprsd with -c. +and use to pass in to aprsd with -c. By default aprsd looks in ~/.config/aprsd/aprsd.yml aprsd sample-config @@ -235,8 +248,9 @@ test messages -h, --help Show this message and exit. + Example output: ---------------- +=============== SEND EMAIL (radio to smtp server) @@ -278,60 +292,30 @@ RECEIVE EMAIL (imap server to radio) Msg number : 0 -WEATHER -======= - -:: - - Received message______________ - Raw : KM6XXX>APY400,WIDE1-1,qAO,KM6XXX-1::KM6XXX-9 :weather{27 - From : KM6XXX - Message : weather - Msg number : 27 - - Sending message_______________ 6(Tx3) - Raw : KM6XXX-9>APRS::KM6XXX :58F(58F/46F) Partly cloudy. Tonight, Heavy Rain.{6 - To : KM6XXX - Message : 58F(58F/46F) Party Cloudy. Tonight, Heavy Rain. - - Sending ack __________________ Tx(3) - Raw : KM6XXX-9>APRS::KM6XXX :ack27 - To : KM6XXX - Ack number : 27 - - Received message______________ - Raw : KM6XXX>APY400,WIDE1-1,qAO,KM6XXX-1::KM6XXX-9 :ack6 - From : KM6XXX - Message : ack6 - Msg number : 0 - - LOCATION ======== :: - Received message______________ - Raw : KM6XXX>APY400,WIDE1-1,qAO,KM6XXX-1::KM6XXX-9 :location{28 - From : KM6XXX + Received Message _______________ + Raw : KM6XXX-6>APRS,TCPIP*,qAC,T2CAEAST::KM6XXX-14:location{2 + From : KM6XXX-6 Message : location - Msg number : 28 + Msg number : 2 + Received Message _______________ Complete - Sending message_______________ 7(Tx3) - Raw : KM6XXX-9>APRS::KM6XXX :8 Miles NE Auburn CA 1673' 39.91150,-120.93450 0.1h ago{7 - To : KM6XXX - Message : 8 Miles E Auburn CA 1673' 38.91150,-120.93450 0.1h ago + Sending Message _______________ + Raw : KM6XXX-14>APRS::KM6XXX-6 :KM6XXX-6: 8 Miles E Auburn CA 0' 0,-120.93584 1873.7h ago{2 + To : KM6XXX-6 + Message : KM6XXX-6: 8 Miles E Auburn CA 0' 0,-120.93584 1873.7h ago + Msg number : 2 + Sending Message _______________ Complete - Sending ack __________________ Tx(3) - Raw : KM6XXX-9>APRS::KM6XXX :ack28 - To : KM6XXX - Ack number : 28 - - Received message______________ - Raw : KM6XXX>APY400,WIDE1-1,qAO,KM6XXX-1::KM6XXX-9 :ack7 - From : KM6XXX - Message : ack7 - Msg number : 0 + Sending ack _______________ + Raw : KM6XXX-14>APRS::KM6XXX-6 :ack2 + To : KM6XXX-6 + Ack : 2 + Sending ack _______________ Complete AND... ping, fortune, time..... @@ -341,25 +325,21 @@ Development * git clone git@github.com:craigerl/aprsd.git * cd aprsd -* virtualenv .venv -* source .venv/bin/activate -* pip install -e . -* pre-commit install +* make Workflow --------- +======== While working aprsd, The workflow is as follows * Edit code, save file -* run tox -epep8 * run tox -efmt * run tox -p * git commit ( This will run the pre-commit hooks which does checks too ) Release -------- +======= To do release to pypi: @@ -371,25 +351,20 @@ To do release to pypi: git push origin master --tags -* Build dist and wheel +* Do a test build and verify build is valid - python setup.py sdist bdist_wheel - -* Verify build is valid for pypi (need twine installed ) - - pip install twine - twine check dist/* + make build * Once twine is happy, upload release to pypi - twine upload dist/* + make upload Docker Container ----------------- +================ Building --------- +======== There are 2 versions of the container Dockerfile that can be used. The main Dockerfile, which is for building the official release container @@ -398,18 +373,18 @@ which is used for building a container based off of a git branch of the repo. Official Build --------------- +============== docker build -t hemna6969/aprsd:latest . Development Build ------------------ +================= docker build -t hemna6969/aprsd:latest -f Dockerfile-dev . Running the container ---------------------- +===================== There is a docker-compose.yml file that can be used to run your container. There are 2 volumes defined that can be used to store your configuration diff --git a/docs/_static/.keep b/docs/_static/.keep new file mode 100644 index 0000000..e69de29 diff --git a/docs/_templates/.keep b/docs/_templates/.keep new file mode 100644 index 0000000..e69de29 diff --git a/docs/apidoc/aprsd.plugins.rst b/docs/apidoc/aprsd.plugins.rst new file mode 100644 index 0000000..7c6718a --- /dev/null +++ b/docs/apidoc/aprsd.plugins.rst @@ -0,0 +1,77 @@ +aprsd.plugins package +===================== + +Submodules +---------- + +aprsd.plugins.email module +-------------------------- + +.. automodule:: aprsd.plugins.email + :members: + :undoc-members: + :show-inheritance: + +aprsd.plugins.fortune module +---------------------------- + +.. automodule:: aprsd.plugins.fortune + :members: + :undoc-members: + :show-inheritance: + +aprsd.plugins.location module +----------------------------- + +.. automodule:: aprsd.plugins.location + :members: + :undoc-members: + :show-inheritance: + +aprsd.plugins.ping module +------------------------- + +.. automodule:: aprsd.plugins.ping + :members: + :undoc-members: + :show-inheritance: + +aprsd.plugins.query module +-------------------------- + +.. automodule:: aprsd.plugins.query + :members: + :undoc-members: + :show-inheritance: + +aprsd.plugins.time module +------------------------- + +.. automodule:: aprsd.plugins.time + :members: + :undoc-members: + :show-inheritance: + +aprsd.plugins.version module +---------------------------- + +.. automodule:: aprsd.plugins.version + :members: + :undoc-members: + :show-inheritance: + +aprsd.plugins.weather module +---------------------------- + +.. automodule:: aprsd.plugins.weather + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: aprsd.plugins + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/apidoc/aprsd.rst b/docs/apidoc/aprsd.rst new file mode 100644 index 0000000..2056c90 --- /dev/null +++ b/docs/apidoc/aprsd.rst @@ -0,0 +1,93 @@ +aprsd package +============= + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + aprsd.plugins + +Submodules +---------- + +aprsd.client module +------------------- + +.. automodule:: aprsd.client + :members: + :undoc-members: + :show-inheritance: + +aprsd.email module +------------------ + +.. automodule:: aprsd.email + :members: + :undoc-members: + :show-inheritance: + +aprsd.fake\_aprs module +----------------------- + +.. automodule:: aprsd.fake_aprs + :members: + :undoc-members: + :show-inheritance: + +aprsd.fuzzyclock module +----------------------- + +.. automodule:: aprsd.fuzzyclock + :members: + :undoc-members: + :show-inheritance: + +aprsd.main module +----------------- + +.. automodule:: aprsd.main + :members: + :undoc-members: + :show-inheritance: + +aprsd.messaging module +---------------------- + +.. automodule:: aprsd.messaging + :members: + :undoc-members: + :show-inheritance: + +aprsd.plugin module +------------------- + +.. automodule:: aprsd.plugin + :members: + :undoc-members: + :show-inheritance: + +aprsd.threads module +-------------------- + +.. automodule:: aprsd.threads + :members: + :undoc-members: + :show-inheritance: + +aprsd.utils module +------------------ + +.. automodule:: aprsd.utils + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: aprsd + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/apidoc/modules.rst b/docs/apidoc/modules.rst new file mode 100644 index 0000000..ab430eb --- /dev/null +++ b/docs/apidoc/modules.rst @@ -0,0 +1,7 @@ +aprsd +===== + +.. toctree:: + :maxdepth: 4 + + aprsd diff --git a/docs/clean_docs.py b/docs/clean_docs.py new file mode 100644 index 0000000..771bfd3 --- /dev/null +++ b/docs/clean_docs.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +"""Removes temporary Sphinx build artifacts to ensure a clean build. + +This is needed if the Python source being documented changes significantly. Old sphinx-apidoc +RST files can be left behind. +""" + +from pathlib import Path +import shutil + + +def main() -> None: + docs_dir = Path(__file__).resolve().parent + for folder in ("_build", "apidoc"): + delete_dir = docs_dir / folder + if delete_dir.exists(): + shutil.rmtree(delete_dir) + + +if __name__ == "__main__": + main() diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..b71f155 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,188 @@ +# +# Configuration file for the Sphinx documentation builder. +# +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/master/config + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. + +import os +import sys + +sys.path.insert(0, os.path.abspath("../src")) + + +# -- Project information ----------------------------------------------------- + +project = "APRSD" +copyright = "" +author = "Craig Lamparter" + +# The short X.Y version +version = "v1.5.0" +# The full version, including alpha/beta/rc tags +release = "" + + +# -- General configuration --------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.doctest", + "sphinx.ext.todo", + "sphinx.ext.viewcode", + "sphinx.ext.napoleon", +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = ".rst" + +# The master toctree document. +master_doc = "index" + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = None + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "alabaster" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +html_theme_options = { + # Override the default alabaster line wrap, which wraps tightly at 940px. + "page_width": "auto", +} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = "adoc" + + +# -- Options for LaTeX output ------------------------------------------------ + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, "a.tex", "a Documentation", "a", "manual"), +] + + +# -- Options for manual page output ------------------------------------------ + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [(master_doc, "a", "a Documentation", [author], 1)] + + +# -- Options for Texinfo output ---------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ( + master_doc, + "a", + "a Documentation", + author, + "a", + "One line description of project.", + "Miscellaneous", + ), +] + + +# -- Options for Epub output ------------------------------------------------- + +# Bibliographic Dublin Core info. +epub_title = project + +# The unique identifier of the text. This can be a ISBN number +# or the project homepage. +# +# epub_identifier = '' + +# A unique identification for the text. +# +# epub_uid = '' + +# A list of files that should not be packed into the epub file. +epub_exclude_files = ["search.html"] + + +# -- Extension configuration ------------------------------------------------- + +# -- Options for todo extension ---------------------------------------------- + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True diff --git a/docs/configure.rst b/docs/configure.rst new file mode 100644 index 0000000..dfb2a6c --- /dev/null +++ b/docs/configure.rst @@ -0,0 +1,71 @@ +APRSD Configure +=============== + +Configure APRSD +------------------------ + +Once APRSD is :doc:`installed ` You will need to configure the config file +for running. + + +Generate config file +--------------------- +If you have never run the server, running it the first time will generate +a sample config file in the default location of ~/.config/aprsd/aprsd.yml + +.. code-block:: shell + + └─[$] -> aprsd server + Load config + /home/aprsd/.config/aprsd/aprsd.yml is missing, creating config file + Default config file created at /home/aprsd/.config/aprsd/aprsd.yml. Please edit with your settings. + +You can see the sample config file output + +Sample config file +------------------ + +.. code-block:: shell + + └─[$] -> cat ~/.config/aprsd/aprsd.yml + aprs: + host: rotate.aprs.net + logfile: /tmp/arsd.log + login: someusername + password: somepassword + port: 14580 + aprsd: + enabled_plugins: + - aprsd.plugins.email.EmailPlugin + - aprsd.plugins.fortune.FortunePlugin + - aprsd.plugins.location.LocationPlugin + - aprsd.plugins.ping.PingPlugin + - aprsd.plugins.query.QueryPlugin + - aprsd.plugins.time.TimePlugin + - aprsd.plugins.weather.WeatherPlugin + - aprsd.plugins.version.VersionPlugin + plugin_dir: ~/.config/aprsd/plugins + ham: + callsign: KFART + imap: + host: imap.gmail.com + login: imapuser + password: something here too + port: 993 + use_ssl: true + shortcuts: + aa: 5551239999@vtext.com + cl: craiglamparter@somedomain.org + wb: 555309@vtext.com + smtp: + host: imap.gmail.com + login: something + password: some lame password + port: 465 + use_ssl: false + + +Note, You must edit the config file and change the ham callsign to your +legal FCC HAM callsign, or aprsd server will not start. + +.. include:: links.rst diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..8b1a043 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,30 @@ +.. a documentation master file, created by + sphinx-quickstart on Wed Dec 19 18:34:22 2018. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +``APRSD`` Documentation +======================= + +.. include:: readme.rst + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + readme + install + configure + server + plugin + + apidoc/modules.rst + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + +.. include:: links.rst diff --git a/docs/install.rst b/docs/install.rst new file mode 100644 index 0000000..d904432 --- /dev/null +++ b/docs/install.rst @@ -0,0 +1,67 @@ +APRSD installation +================== + +Install info in a nutshell +-------------------------- + +**Pythons**: Python 3.6 or later + +**Operating systems**: Linux, OSX, Unix + +**Installer Requirements**: setuptools_ + +**License**: Apache license + +**git repository**: https://github.com/craigerl/aprsd + +Installation with pip +-------------------------------------- + +Use the following command: + +.. code-block:: shell + + pip install aprsd + +It is fine to install ``aprsd`` itself into a virtualenv_ environment. + +Install from clone +------------------------- + +Consult the GitHub page how to clone the git repository: + + https://github.com/craigerl/aprsd + +and then install in your environment with something like: + +.. code-block:: shell + + $ cd + $ pip install . + +or install it `editable `_ if you want code changes to propagate automatically: + +.. code-block:: shell + + $ cd + $ pip install --editable . + +so that you can do changes and submit patches. + + +Install for development +---------------------------- + +For developers you should clone the repo from github, then use the Makefile + +.. code-block:: shell + + $ cd + $ make + +This creates a virtualenv_ directory, install all the requirements for +development as well as aprsd in `editable `_ mode. +It will install all of the pre-commit git hooks required to test prior to committing code. + + +.. include:: links.rst diff --git a/docs/links.rst b/docs/links.rst new file mode 100644 index 0000000..ba75c60 --- /dev/null +++ b/docs/links.rst @@ -0,0 +1,31 @@ +.. _`Cookiecutter`: https://cookiecutter.readthedocs.io +.. _`pluggy`: https://pluggy.readthedocs.io +.. _`cookiecutter-tox-plugin`: https://github.com/tox-dev/cookiecutter-tox-plugin +.. _devpi: https://doc.devpi.net +.. _Python: https://www.python.org +.. _virtualenv: https://pypi.org/project/virtualenv +.. _`pytest`: https://pytest.org +.. _nosetests: +.. _`nose`: https://pypi.org/project/nose +.. _`Holger Krekel`: https://twitter.com/hpk42 +.. _`pytest-xdist`: https://pypi.org/project/pytest-xdist +.. _ConfigParser: https://docs.python.org/3/library/configparser.html + +.. _`easy_install`: http://peak.telecommunity.com/DevCenter/EasyInstall +.. _pip: https://pypi.org/project/pip +.. _setuptools: https://pypi.org/project/setuptools +.. _`jenkins`: https://jenkins.io/index.html +.. _sphinx: https://pypi.org/project/Sphinx +.. _discover: https://pypi.org/project/discover +.. _unittest2: https://pypi.org/project/unittest2 +.. _mock: https://pypi.org/project/mock/ +.. _flit: https://flit.readthedocs.io/en/latest/ +.. _poetry: https://poetry.eustace.io/ +.. _pypy: https://pypy.org + +.. _`Python Packaging Guide`: https://packaging.python.org/tutorials/packaging-projects/ +.. _`tox.ini`: :doc:configfile + +.. _`PEP-508`: https://www.python.org/dev/peps/pep-0508/ +.. _`PEP-517`: https://www.python.org/dev/peps/pep-0517/ +.. _`PEP-518`: https://www.python.org/dev/peps/pep-0518/ diff --git a/docs/plugin.rst b/docs/plugin.rst new file mode 100644 index 0000000..6f74ce3 --- /dev/null +++ b/docs/plugin.rst @@ -0,0 +1,55 @@ +APRSD Command Plugin Development +================================ + +APRSDPluginBase +------------------------ + +Plugins are written as python objects that extend the APRSDPluginBase class. +This is an abstract class that has several properties and a method that must be implemented +by your subclass. + +Properties +---------- + +* name - the Command name +* regex - The regular expression that if matched against the incoming APRS message, + will cause your plugin to be called. + +Methods +------- + +* command - This method is called when the regex matches the incoming message from APRS. + If you want to send a message back to the sending, just return a string + in your method implementation. If you get called and don't want to reply, then + you should return a messaging.NULL_MESSAGE to signal to the plugin processor + that you got called and processed the message correctly. Otherwise a usage + string may get returned to the sender. + + +Example Plugin +-------------- + +There is an example plugin in the aprsd source code here: +aprsd/examples/plugins/example_plugin.py + +.. code-block:: python + + import logging + + from aprsd import plugin + + LOG = logging.getLogger("APRSD") + + + class HelloPlugin(plugin.APRSDPluginBase): + """Hello World.""" + + version = "1.0" + # matches any string starting with h or H + command_regex = "^[hH]" + command_name = "hello" + + def command(self, fromcall, message, ack): + LOG.info("HelloPlugin") + reply = "Hello '{}'".format(fromcall) + return reply diff --git a/docs/readme.rst b/docs/readme.rst new file mode 100644 index 0000000..9f44907 --- /dev/null +++ b/docs/readme.rst @@ -0,0 +1,392 @@ +APRSD +----- + +.. image:: https://badge.fury.io/py/aprsd.svg + :target: https://badge.fury.io/py/aprsd + +.. image:: https://github.com/craigerl/aprsd/workflows/python/badge.svg + :target: https://github.com/craigerl/aprsd/actions + +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://black.readthedocs.io/en/stable/ + +.. image:: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336 + :target: https://timothycrosley.github.io/isort/ + +.. image:: https://static.pepy.tech/personalized-badge/aprsd?period=month&units=international_system&left_color=black&right_color=orange&left_text=Downloads + :target: https://pepy.tech/project/aprsd + + +Summary +======= + +`APRSD `_ is a Ham radio `APRS `_ message command gateway built on python. + +APRSD listens on amateur radio aprs-is network for messages and respond to them. +It has a plugin architecture for extensibility. Users of APRSD can write their own +plugins that can respond to APRS-IS messages. + +You must have an amateur radio callsign to use this software. APRSD gets +messages for the configured HAM callsign, and sends those messages to a +list of plugins for processing. There are a set of core plugins that +provide responding to messages to check email, get location, ping, +time of day, get weather, and fortune telling as well as version information +of aprsd itself. + +Typical use case +================ + +Ham radio operator using an APRS enabled HAM radio sends a message to check +the weather. an APRS message is sent, and then picked up by APRSD. The +APRS packet is decoded, and the message is sent through the list of plugins +for processing. For example, the WeatherPlugin picks up the message, fetches the weather +for the area around the user who sent the request, and then responds with +the weather conditions in that area. + + +APRSD Capabilities +================== + +* server - The main aprsd server processor. Send/Rx APRS messages to HAM callsign +* send-message - use aprsd to send a command/message to aprsd server. Used for development testing +* sample-config - generate a sample aprsd.yml config file for use/editing +* bash completion generation. Uses python click bash completion to generate completion code for your .bashrc/.zshrc + + +List of core server plugins +=========================== + +Plugins function by specifying a regex that is searched for in the APRS message. +If it matches, the plugin runs. IF the regex doesn't match, the plugin is skipped. + +* EmailPlugin - Check email and reply with contents. Have to configure IMAP and SMTP settings in aprs.yml +* FortunePlugin - Replies with old unix fortune random fortune! +* LocationPlugin - Checks location of ham operator +* PingPlugin - Sends pong with timestamp +* QueryPlugin - Allows querying the list of delayed messages that were not ACK'd by radio +* TimePlugin - Current time of day +* WeatherPlugin - Get weather conditions for current location of HAM callsign +* VersionPlugin - Reports the version information for aprsd + + +Current messages this will respond to: +====================================== + +:: + + APRS messages: + l(ocation) [callsign] = descriptive current location of your radio + 8 Miles E Auburn CA 1673' 39.92150,-120.93950 0.1h ago + w(eather) = weather forecast for your radio's current position + 58F(58F/46F) Partly Cloudy. Tonight, Heavy Rain. + t(ime) = respond with the current time + f(ortune) = respond with a short fortune + -email_addr email text = send an email, say "mapme" to send a current position/map + -2 = resend the last 2 emails from your imap inbox to this radio + p(ing) = respond with Pong!/time + v(ersion) = Respond with current APRSD Version string + anything else = respond with usage + + +Meanwhile this code will monitor a single imap mailbox and forward email +to your BASECALLSIGN over the air. Only radios using the BASECALLSIGN are allowed +to send email, so consider this security risk before using this (or Amatuer radio in +general). Email is single user at this time. + +There are additional parameters in the code (sorry), so be sure to set your +email server, and associated logins, passwords. search for "yourdomain", +"password". Search for "shortcuts" to setup email aliases as well. + + +Example usage: +============== + + aprsd -h + +Help +==== +:: + + └─[$] > aprsd -h + Usage: aprsd [OPTIONS] COMMAND [ARGS]... + + Shell completion for click-completion-command Available shell types: + bash Bourne again shell fish Friendly interactive shell + powershell Windows PowerShell zsh Z shell Default type: auto + + Options: + --version Show the version and exit. + -h, --help Show this message and exit. + + Commands: + install Install the click-completion-command completion + sample-config This dumps the config to stdout. + send-message Send a message to a callsign via APRS_IS. + server Start the aprsd server process. + show Show the click-completion-command completion code + + + + +Configuration +------------- +This command outputs a sample config yml formatted block that you can edit +and use to pass in to aprsd with -c. By default aprsd looks in ~/.config/aprsd/aprsd.yml + + aprsd sample-config + +Output +====== +:: + + └─[$] > aprsd sample-config + + aprs: + host: rotate.aprs.net + logfile: /tmp/arsd.log + login: someusername + password: somepassword + port: 14580 + aprsd: + enabled_plugins: + - aprsd.plugin.EmailPlugin + - aprsd.plugin.FortunePlugin + - aprsd.plugin.LocationPlugin + - aprsd.plugin.PingPlugin + - aprsd.plugin.TimePlugin + - aprsd.plugin.WeatherPlugin + - aprsd.plugin.VersionPlugin + plugin_dir: ~/.config/aprsd/plugins + ham: + callsign: KFART + imap: + host: imap.gmail.com + login: imapuser + password: something here too + port: 993 + use_ssl: true + shortcuts: + aa: 5551239999@vtext.com + cl: craiglamparter@somedomain.org + wb: 555309@vtext.com + smtp: + host: imap.gmail.com + login: something + password: some lame password + port: 465 + use_ssl: false + + +server +------ + +This is the main server command that will listen to APRS-IS servers and +look for incomming commands to the callsign configured in the config file + +:: + + └─[$] > aprsd server --help + Usage: aprsd server [OPTIONS] + + Start the aprsd server process. + + Options: + --loglevel [CRITICAL|ERROR|WARNING|INFO|DEBUG] + The log level to use for aprsd.log + [default: DEBUG] + + --quiet Don't log to stdout + --disable-validation Disable email shortcut validation. Bad + email addresses can result in broken email + responses!! + + -c, --config TEXT The aprsd config file to use for options. + [default: ~/.config/aprsd/aprsd.yml] + + -h, --help Show this message and exit. + (.venv3) ┌─[waboring@dl360-1] - [~/devel/aprsd] - [Sun Dec 20, 12:32] - + └─[$] aprsd server + Load config + [12/20/2020 12:33:03 PM] [MainThread ] [INFO ] APRSD Started version: 1.0.2 + [12/20/2020 12:33:03 PM] [MainThread ] [INFO ] Checking IMAP configuration + [12/20/2020 12:33:04 PM] [MainThread ] [INFO ] Checking SMTP configuration + + +send-message +------------ + +This command is typically used for development to send another aprsd instance +test messages + +:: + + └─[$] > aprsd send-message -h + Usage: aprsd send-message [OPTIONS] TOCALLSIGN [COMMAND]... + + Send a message to a callsign via APRS_IS. + + Options: + --loglevel [CRITICAL|ERROR|WARNING|INFO|DEBUG] + The log level to use for aprsd.log + [default: DEBUG] + + --quiet Don't log to stdout + -c, --config TEXT The aprsd config file to use for options. + [default: ~/.config/aprsd/aprsd.yml] + + --aprs-login TEXT What callsign to send the message from. + [env var: APRS_LOGIN] + + --aprs-password TEXT the APRS-IS password for APRS_LOGIN [env + var: APRS_PASSWORD] + + -h, --help Show this message and exit. + + +Example Message output: +----------------------- + + +SEND EMAIL (radio to smtp server) +================================= + +:: + + Received message______________ + Raw : KM6XXX>APY400,WIDE1-1,qAO,KM6XXX-1::KM6XXX-9 :-user@host.com test new shortcuts global, radio to pc{29 + From : KM6XXX + Message : -user@host.com test new shortcuts global, radio to pc + Msg number : 29 + + Sending Email_________________ + To : user@host.com + Subject : KM6XXX + Body : test new shortcuts global, radio to pc + + Sending ack __________________ Tx(3) + Raw : KM6XXX-9>APRS::KM6XXX :ack29 + To : KM6XXX + Ack number : 29 + + +RECEIVE EMAIL (imap server to radio) +==================================== + +:: + + Sending message_______________ 6(Tx3) + Raw : KM6XXX-9>APRS::KM6XXX :-somebody@gmail.com email from internet to radio{6 + To : KM6XXX + Message : -somebody@gmail.com email from internet to radio + + Received message______________ + Raw : KM6XXX>APY400,WIDE1-1,qAO,KM6XXX-1::KM6XXX-9 :ack6 + From : KM6XXX + Message : ack6 + Msg number : 0 + + +LOCATION +======== + +:: + + Received Message _______________ + Raw : KM6XXX-6>APRS,TCPIP*,qAC,T2CAEAST::KM6XXX-14:location{2 + From : KM6XXX-6 + Message : location + Msg number : 2 + Received Message _______________ Complete + + Sending Message _______________ + Raw : KM6XXX-14>APRS::KM6XXX-6 :KM6XXX-6: 8 Miles E Auburn CA 0' 0,-120.93584 1873.7h ago{2 + To : KM6XXX-6 + Message : KM6XXX-6: 8 Miles E Auburn CA 0' 0,-120.93584 1873.7h ago + Msg number : 2 + Sending Message _______________ Complete + + Sending ack _______________ + Raw : KM6XXX-14>APRS::KM6XXX-6 :ack2 + To : KM6XXX-6 + Ack : 2 + Sending ack _______________ Complete + +AND... ping, fortune, time..... + + +Development +----------- + +* git clone git@github.com:craigerl/aprsd.git +* cd aprsd +* make + +Workflow +======== + +While working aprsd, The workflow is as follows + +* Edit code, save file +* run tox -efmt +* run tox -p +* git commit ( This will run the pre-commit hooks which does checks too ) + + +Release +======= + +To do release to pypi: + +* Tag release with + + git tag -v1.XX -m "New release" + +* push release tag up + + git push origin master --tags + +* Do a test build and verify build is valid + + make build + +* Once twine is happy, upload release to pypi + + make upload + + +Docker Container +---------------- + +Building +======== + +There are 2 versions of the container Dockerfile that can be used. +The main Dockerfile, which is for building the official release container +based off of the pip install version of aprsd and the Dockerfile-dev, +which is used for building a container based off of a git branch of +the repo. + +Official Build +============== + + docker build -t hemna6969/aprsd:latest . + +Development Build +================= + + docker build -t hemna6969/aprsd:latest -f Dockerfile-dev . + + +Running the container +===================== + +There is a docker-compose.yml file that can be used to run your container. +There are 2 volumes defined that can be used to store your configuration +and the plugins directory: /config and /plugins + +If you want to install plugins at container start time, then use the +environment var in docker-compose.yml specified as APRS_PLUGINS +Provide a csv list of pypi installable plugins. Then make sure the plugin +python file is in your /plugins volume and the plugin will be installed at +container startup. The plugin may have dependencies that are required. +The plugin file should be copied to /plugins for loading by aprsd diff --git a/docs/server.rst b/docs/server.rst new file mode 100644 index 0000000..8fc28fd --- /dev/null +++ b/docs/server.rst @@ -0,0 +1,53 @@ +APRSD server +============ + +Running the APRSD server +------------------------ + +Once APRSD is :doc:`installed ` and :doc:`configured ` the server can be started by +running. + +.. code-block:: shell + + aprsd server + +The server will start several threads to deal handle incoming messages, outgoing +messages, checking and sending email. + +.. code-block:: shell + + [MainThread ] [INFO ] APRSD Started version: 1.5.1 + [MainThread ] [INFO ] Checking IMAP configuration + [MainThread ] [INFO ] Checking SMTP configuration + [MainThread ] [DEBUG] Connect to SMTP host SSL smtp.gmail.com:465 with user 'test@hemna.com' + [MainThread ] [DEBUG] Connected to smtp host SSL smtp.gmail.com:465 + [MainThread ] [DEBUG] Logged into SMTP server SSL smtp.gmail.com:465 + [MainThread ] [INFO ] Validating 2 Email shortcuts. This can take up to 10 seconds per shortcut + [MainThread ] [ERROR] 'craiglamparter@somedomain.org' is an invalid email address. Removing shortcut + [MainThread ] [INFO ] Available shortcuts: {'wb': 'waboring@hemna.com'} + [MainThread ] [INFO ] Loading Core APRSD Command Plugins + [MainThread ] [INFO ] Registering Command plugin 'aprsd.plugins.email.EmailPlugin'(1.0) '^-.*' + [MainThread ] [INFO ] Registering Command plugin 'aprsd.plugins.fortune.FortunePlugin'(1.0) '^[fF]' + [MainThread ] [INFO ] Registering Command plugin 'aprsd.plugins.location.LocationPlugin'(1.0) '^[lL]' + [MainThread ] [INFO ] Registering Command plugin 'aprsd.plugins.ping.PingPlugin'(1.0) '^[pP]' + [MainThread ] [INFO ] Registering Command plugin 'aprsd.plugins.query.QueryPlugin'(1.0) '^\?.*' + [MainThread ] [INFO ] Registering Command plugin 'aprsd.plugins.time.TimePlugin'(1.0) '^[tT]' + [MainThread ] [INFO ] Registering Command plugin 'aprsd.plugins.weather.WeatherPlugin'(1.0) '^[wW]' + [MainThread ] [INFO ] Registering Command plugin 'aprsd.plugins.version.VersionPlugin'(1.0) '^[vV]' + [MainThread ] [INFO ] Skipping Custom Plugins directory. + [MainThread ] [INFO ] Completed Plugin Loading. + [MainThread ] [DEBUG] Loading saved MsgTrack object. + [RX_MSG ] [INFO ] Starting + [TX_MSG ] [INFO ] Starting + [MainThread ] [DEBUG] KeepAlive Tracker(0): {} + [RX_MSG ] [INFO ] Creating aprslib client + [RX_MSG ] [INFO ] Attempting connection to noam.aprs2.net:14580 + [RX_MSG ] [INFO ] Connected to ('198.50.198.139', 14580) + [RX_MSG ] [DEBUG] Banner: # aprsc 2.1.8-gf8824e8 + [RX_MSG ] [INFO ] Sending login information + [RX_MSG ] [DEBUG] Server: # logresp KM6XXX-14 verified, server T2VAN + [RX_MSG ] [INFO ] Login successful + [RX_MSG ] [DEBUG] Logging in to APRS-IS with user 'KM6XXX-14' + + +.. include:: links.rst diff --git a/setup.cfg b/setup.cfg index 125cd1f..e89d7a8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,14 +2,25 @@ name = aprsd long_description = file: README.rst long_description_content_type = text/x-rst +url = http://aprsd.readthedocs.org author = Craig Lamparter author_email = something@somewhere.com +license = Apache +license_file = LICENSE classifier = + License :: OSI Approved :: Apache Software License Topic :: Communications :: Ham Radio Operating System :: POSIX :: Linux Programming Language :: Python + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 description_file = README.rst +project_urls = + Source=https://github.com/craigerl/aprsd + Tracker=https://github.com/craigerl/aprsd/issues summary = Amateur radio APRS daemon which listens for messages and responds [global] @@ -26,9 +37,12 @@ console_scripts = fake_aprs = aprsd.fake_aprs:main [build_sphinx] -source-dir = doc/source -build-dir = doc/build +source-dir = docs +build-dir = docs/_build all_files = 1 [upload_sphinx] -upload-dir = doc/build/html +upload-dir = docs/_build + +[bdist_wheel] +universal = 1 diff --git a/tox.ini b/tox.ini index dd53ec5..69103ef 100644 --- a/tox.ini +++ b/tox.ini @@ -23,8 +23,15 @@ commands = {envpython} -bb -m pytest {posargs} [testenv:docs] -deps = -r{toxinidir}/test-requirements.txt -commands = sphinx-build -b html docs/source docs/html +skip_install = true +deps = + -r{toxinidir}/requirements.txt + -r{toxinidir}/dev-requirements.txt +changedir = {toxinidir}/docs +commands = + {envpython} clean_docs.py + sphinx-apidoc --force --output-dir apidoc {toxinidir}/aprsd + sphinx-build -a -W . _build [testenv:pep8] commands =