mirror of
https://github.com/craigerl/aprsd.git
synced 2026-07-16 15:54:22 -04:00
Added aprsd version checking
This patch adds usage of update_checker to check to make sure the version of APRSD being launched is the latest version. Also added a call to upate_checker as part of the KeepAlive thread. It will call update_check every hour. If there is no aprsd connectivitity, the update check will silently fail.
This commit is contained in:
@@ -199,6 +199,43 @@ def setup_logging(config, loglevel, quiet):
|
||||
imap_logger.addHandler(sh)
|
||||
|
||||
|
||||
@main.command()
|
||||
@click.option(
|
||||
"--loglevel",
|
||||
default="INFO",
|
||||
show_default=True,
|
||||
type=click.Choice(
|
||||
["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"],
|
||||
case_sensitive=False,
|
||||
),
|
||||
show_choices=True,
|
||||
help="The log level to use for aprsd.log",
|
||||
)
|
||||
@click.option(
|
||||
"-c",
|
||||
"--config",
|
||||
"config_file",
|
||||
show_default=True,
|
||||
default=utils.DEFAULT_CONFIG_FILE,
|
||||
help="The aprsd config file to use for options.",
|
||||
)
|
||||
def check_version(loglevel, config_file):
|
||||
config = utils.parse_config(config_file)
|
||||
|
||||
# Force setting the config to the modules that need it
|
||||
# TODO(Walt): convert these modules to classes that can
|
||||
# Accept the config as a constructor param, instead of this
|
||||
# hacky global setting
|
||||
email.CONFIG = config
|
||||
|
||||
setup_logging(config, loglevel, False)
|
||||
level, msg = utils._check_version()
|
||||
if level:
|
||||
LOG.warning(msg)
|
||||
else:
|
||||
LOG.info(msg)
|
||||
|
||||
|
||||
@main.command()
|
||||
def sample_config():
|
||||
"""This dumps the config to stdout."""
|
||||
@@ -417,6 +454,12 @@ def server(
|
||||
email.CONFIG = config
|
||||
|
||||
setup_logging(config, loglevel, quiet)
|
||||
level, msg = utils._check_version()
|
||||
if level:
|
||||
LOG.warning(msg)
|
||||
else:
|
||||
LOG.info(msg)
|
||||
|
||||
if config["aprsd"].get("trace", False):
|
||||
trace.setup_tracing(["method", "api"])
|
||||
LOG.info("APRSD Started version: {}".format(aprsd.__version__))
|
||||
|
||||
+9
-1
@@ -67,10 +67,11 @@ class APRSDThread(threading.Thread, metaclass=abc.ABCMeta):
|
||||
|
||||
class KeepAliveThread(APRSDThread):
|
||||
cntr = 0
|
||||
checker_time = datetime.datetime.now()
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("KeepAlive")
|
||||
tracemalloc.start()
|
||||
super().__init__("KeepAlive")
|
||||
|
||||
def loop(self):
|
||||
if self.cntr % 6 == 0:
|
||||
@@ -102,6 +103,13 @@ class KeepAliveThread(APRSDThread):
|
||||
)
|
||||
)
|
||||
LOG.debug(keepalive)
|
||||
# Check version every hour
|
||||
delta = now - self.checker_time
|
||||
if delta > datetime.timedelta(hours=1):
|
||||
self.checker_time = now
|
||||
level, msg = utils._check_version()
|
||||
if level:
|
||||
LOG.warning(msg)
|
||||
self.cntr += 1
|
||||
time.sleep(10)
|
||||
return True
|
||||
|
||||
+20
-1
@@ -8,8 +8,10 @@ from pathlib import Path
|
||||
import sys
|
||||
import threading
|
||||
|
||||
import aprsd
|
||||
from aprsd import plugin
|
||||
import click
|
||||
import update_checker
|
||||
import yaml
|
||||
|
||||
LOG_LEVELS = {
|
||||
@@ -364,7 +366,7 @@ def parse_config(config_file):
|
||||
|
||||
|
||||
def human_size(bytes, units=None):
|
||||
""" Returns a human readable string representation of bytes """
|
||||
"""Returns a human readable string representation of bytes"""
|
||||
if not units:
|
||||
units = [" bytes", "KB", "MB", "GB", "TB", "PB", "EB"]
|
||||
return str(bytes) + units[0] if bytes < 1024 else human_size(bytes >> 10, units[1:])
|
||||
@@ -375,3 +377,20 @@ def strfdelta(tdelta, fmt="{hours}:{minutes}:{seconds}"):
|
||||
d["hours"], rem = divmod(tdelta.seconds, 3600)
|
||||
d["minutes"], d["seconds"] = divmod(rem, 60)
|
||||
return fmt.format(**d)
|
||||
|
||||
|
||||
def _check_version():
|
||||
# check for a newer version
|
||||
try:
|
||||
check = update_checker.UpdateChecker()
|
||||
result = check.check("aprsd", aprsd.__version__)
|
||||
if result:
|
||||
# Looks like there is an updated version.
|
||||
return 1, result
|
||||
else:
|
||||
return 0, "APRSD is up to date"
|
||||
except Exception:
|
||||
# probably can't get in touch with pypi for some reason
|
||||
# Lets put up an error and move on. We might not
|
||||
# have internet in this aprsd deployment.
|
||||
return 1, "Couldn't check for new version of APRSD"
|
||||
|
||||
Reference in New Issue
Block a user