Skip to content

Commit

Permalink
fix: more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewthetechie committed Mar 23, 2024
1 parent 1e96541 commit 7efa29f
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 19 deletions.
21 changes: 17 additions & 4 deletions aprs_backend/aprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@
from aprs_backend.threads.tx import check_sender_config
from aprs_backend.threads.tx import ErrbotAPRSSender
from aprs_backend.utils import check_object_store_config
from aprs_backend.utils.log import log
from aprsd.packets import core
from errbot.backends.base import Message
from errbot.backends.base import ONLINE
from errbot.core import ErrBot

import logging


log = logging.getLogger(__name__)
for handler in log.handlers:
handler.setFormatter(logging.Formatter('%(filename)s: '
'%(levelname)s: '
'%(funcName)s(): '
'%(lineno)d:\t'
'%(message)s'))


class APRSBackend(ErrBot):
def __init__(self, config):
Expand Down Expand Up @@ -112,7 +122,8 @@ def setup_threads(self) -> None:
def build_reply(
self, msg: Message, text: str, private: bool = False, threaded: bool = False
) -> Message:
msg = Message(
log.debug(msg)
reply = Message(
body=text,
to=msg.frm,
frm=self.bot_identifier,
Expand All @@ -124,9 +135,10 @@ def build_reply(
"packet": msg.extras["packet"],
},
)
return msg
log.debug(reply)
return reply

def set_message_size_limit(self, limit=67, hard_limit=67):
def set_message_size_limit(self, limit=64, hard_limit=67):
"""
APRS supports upto 67 characters per message
http://www.aprs.org/txt/messages.txt
Expand Down Expand Up @@ -179,6 +191,7 @@ def change_presence(self, status: str = ONLINE, message: str = "") -> None:

def send_message(self, msg: Message) -> None:
super().send_message(msg)
log.debug("Sending %s", msg)
packet = core.MessagePacket(
from_call=self.callsign,
to_call=msg.to.callsign,
Expand Down
5 changes: 4 additions & 1 deletion aprs_backend/clients/aprsis.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import time

from aprs_backend.utils.log import log
from aprsd.client import APRSISClient
from aprsd.clients.aprsis import Aprsdis
from aprslib.exceptions import LoginError

import logging


log = logging.getLogger(__name__)

class ErrbotAPRSISClient(APRSISClient):
callsign: str = None
Expand Down
4 changes: 3 additions & 1 deletion aprs_backend/packets/seen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

import wrapt
from aprs_backend.utils import ErrbotObjectStoreMixin
from aprs_backend.utils.log import log
import logging


log = logging.getLogger(__name__)

class ErrbotPacketsSeenList(ErrbotObjectStoreMixin):
"""Global callsign seen list"""

Expand Down
5 changes: 4 additions & 1 deletion aprs_backend/packets/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import wrapt
from aprs_backend.threads import send_queue
from aprs_backend.utils import ErrbotObjectStoreMixin
from aprs_backend.utils.log import log
import logging
from aprsd.packets import core

log = logging.getLogger(__name__)



class ErrbotPacketTrack(ErrbotObjectStoreMixin):
"""Class to keep track of outstanding text messages.
Expand Down
4 changes: 3 additions & 1 deletion aprs_backend/threads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from queue import Queue

import wrapt
from aprs_backend.utils.log import log
from aprsd.threads import APRSDThread
from aprsd.threads.aprsd import APRSDThreadList
import logging


log = logging.getLogger(__name__)

send_queue = Queue(maxsize=25)


Expand Down
5 changes: 4 additions & 1 deletion aprs_backend/threads/beacon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

from aprs_backend.threads import ErrbotAPRSDThread
from aprs_backend.threads.tx import send_via_queue
from aprs_backend.utils.log import log
from aprsd.packets import core

import logging


log = logging.getLogger(__name__)

def check_beacon_config(config: object) -> dict:
kwargs = {
Expand Down
4 changes: 3 additions & 1 deletion aprs_backend/threads/keep_alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
from aprs_backend.threads import ErrbotAPRSDThread
from aprs_backend.threads import ErrbotAPRSDThreadList
from aprs_backend.utils import strfdelta
from aprs_backend.utils.log import log
import logging


log = logging.getLogger(__name__)

class KeepAliveThread(ErrbotAPRSDThread):
def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions aprs_backend/threads/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def process_packet(self, packet):
else:
to_call = packet.to_call
msg_id = packet.msgNo
log.debug(msg_id)

# We don't put ack or rejection packets destined for us
# through the plugins. These are purely message control
Expand Down
4 changes: 3 additions & 1 deletion aprs_backend/threads/rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from aprs_backend.clients import ErrbotKISSClient
from aprs_backend.packets.list import ErrbotPacketList
from aprs_backend.threads import ErrbotAPRSDThread
from aprs_backend.utils.log import log
from aprsd import packets
import logging


log = logging.getLogger(__name__)

class ErrbotRXThread(ErrbotAPRSDThread):
def __init__(
self, packet_queue: Queue, client: ErrbotAPRSISClient | ErrbotKISSClient
Expand Down
5 changes: 4 additions & 1 deletion aprs_backend/threads/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
from aprs_backend.packets.tracker import ErrbotPacketTrack
from aprs_backend.threads import ErrbotAPRSDThread
from aprs_backend.threads import send_queue
from aprs_backend.utils.log import log
from aprsd.packets import core

import logging


log = logging.getLogger(__name__)

def send_via_queue(packet: core.Packet, block: bool = True, timeout: int = 90) -> None:
try:
Expand Down
13 changes: 9 additions & 4 deletions aprs_backend/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
from datetime import timedelta
from functools import cached_property

from aprs_backend.utils.log import log
from aprsd.utils.objectstore import ObjectStoreMixin as APRSDObjectStoreMixing

# yeah, pickle isn't great.
# TODO: move to using errbot's storage backend

import logging


log = logging.getLogger(__name__)

def strfdelta(
tdelta: timedelta, fmt: str = "{hours:{width}}:{minutes:{width}}:{seconds:{width}}"
Expand Down Expand Up @@ -65,6 +68,7 @@ def configure(
aprs_packet_store_filename_suffix: str = "",
aprs_packet_store_file_extension: str = ".aprsb",
) -> None:
log.debug("Name: %s-configure called", self.__class__.__qualname__)
self._config = {
"enable_save": enable_save,
"save_location": save_location,
Expand All @@ -79,11 +83,9 @@ def configure(
if not os.path.exists(self._config["save_location"]):
os.makedirs(self._config["save_location"])
self.configured = True
log.debug("Name: %s-configure end of, Configured: %s", self.__class__.__qualname__, self.configured)

def _init_store(self):
if not self.configured:
raise ObjectStoreNotConfiguredError("Object store is not yet configured")

if not self._config["enable_save"]:
return
save_location = self._config["save_location"]
Expand Down Expand Up @@ -118,6 +120,7 @@ def save_filename(self):
def save(self):
"""Save any queued to disk?"""
if not self.configured:
log.debug("Name: %s-load Configured: %s COnfig: %s", self.__class__.__qualname__, self.configured, self._config)
raise ObjectStoreNotConfiguredError("Object store is not yet configured")
if not self.enable_save:
return
Expand All @@ -140,6 +143,7 @@ def save(self):

def load(self):
if not self.configured:
log.debug("Name: %s-load Configured: %s COnfig: %s", self.__class__.__qualname__, self.configured, self._config)
raise ObjectStoreNotConfiguredError("Object store is not yet configured")
if not self.enable_save:
return
Expand Down Expand Up @@ -168,6 +172,7 @@ def load(self):
def flush(self):
"""Nuke the old pickle file that stored the old results from last aprsd run."""
if not self.configured:
log.debug("Name: %s-flush Configured: %s COnfig: %s", self.__class__.__qualname__, self.configured, self._config)
raise ObjectStoreNotConfiguredError("Object store is not yet configured")
if not self.enable_save:
return
Expand Down
3 changes: 0 additions & 3 deletions aprs_backend/utils/log.py

This file was deleted.

0 comments on commit 7efa29f

Please sign in to comment.