mirror of
https://github.com/craigerl/aprsd.git
synced 2024-11-18 06:11:49 -05:00
Enable configuring where to save the objectstore data
This patch adds a new config entry aprsd.save_location which is the directory used to store and load the objectstore data.
This commit is contained in:
parent
135e21cd8d
commit
0d51634ec2
@ -10,6 +10,12 @@ import yaml
|
|||||||
from aprsd import utils
|
from aprsd import utils
|
||||||
|
|
||||||
|
|
||||||
|
home = str(Path.home())
|
||||||
|
DEFAULT_CONFIG_DIR = f"{home}/.config/aprsd/"
|
||||||
|
DEFAULT_SAVE_FILE = f"{home}/.config/aprsd/aprsd.p"
|
||||||
|
DEFAULT_CONFIG_FILE = f"{home}/.config/aprsd/aprsd.yml"
|
||||||
|
|
||||||
|
|
||||||
LOG_LEVELS = {
|
LOG_LEVELS = {
|
||||||
"CRITICAL": logging.CRITICAL,
|
"CRITICAL": logging.CRITICAL,
|
||||||
"ERROR": logging.ERROR,
|
"ERROR": logging.ERROR,
|
||||||
@ -72,6 +78,7 @@ DEFAULT_CONFIG_DICT = {
|
|||||||
"logfile": "/tmp/aprsd.log",
|
"logfile": "/tmp/aprsd.log",
|
||||||
"logformat": DEFAULT_LOG_FORMAT,
|
"logformat": DEFAULT_LOG_FORMAT,
|
||||||
"dateformat": DEFAULT_DATE_FORMAT,
|
"dateformat": DEFAULT_DATE_FORMAT,
|
||||||
|
"save_location": DEFAULT_CONFIG_DIR,
|
||||||
"trace": False,
|
"trace": False,
|
||||||
"enabled_plugins": CORE_MESSAGE_PLUGINS,
|
"enabled_plugins": CORE_MESSAGE_PLUGINS,
|
||||||
"units": "imperial",
|
"units": "imperial",
|
||||||
@ -129,11 +136,6 @@ DEFAULT_CONFIG_DICT = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
home = str(Path.home())
|
|
||||||
DEFAULT_CONFIG_DIR = f"{home}/.config/aprsd/"
|
|
||||||
DEFAULT_SAVE_FILE = f"{home}/.config/aprsd/aprsd.p"
|
|
||||||
DEFAULT_CONFIG_FILE = f"{home}/.config/aprsd/aprsd.yml"
|
|
||||||
|
|
||||||
|
|
||||||
class Config(collections.UserDict):
|
class Config(collections.UserDict):
|
||||||
def _get(self, d, keys, default=None):
|
def _get(self, d, keys, default=None):
|
||||||
|
@ -479,15 +479,14 @@ def server(
|
|||||||
if flush:
|
if flush:
|
||||||
LOG.debug("Deleting saved MsgTrack.")
|
LOG.debug("Deleting saved MsgTrack.")
|
||||||
messaging.MsgTrack().flush()
|
messaging.MsgTrack().flush()
|
||||||
|
packets.PacketList(config=config)
|
||||||
|
packets.WatchList(config=config)
|
||||||
else:
|
else:
|
||||||
# Try and load saved MsgTrack list
|
# Try and load saved MsgTrack list
|
||||||
LOG.debug("Loading saved MsgTrack object.")
|
LOG.debug("Loading saved MsgTrack object.")
|
||||||
messaging.MsgTrack().load()
|
messaging.MsgTrack().load()
|
||||||
packets.WatchList().load()
|
packets.WatchList(config=config).load()
|
||||||
packets.SeenList().load()
|
packets.SeenList(config=config).load()
|
||||||
|
|
||||||
packets.PacketList(config=config)
|
|
||||||
packets.WatchList(config=config)
|
|
||||||
|
|
||||||
rx_thread = threads.APRSDRXThread(
|
rx_thread = threads.APRSDRXThread(
|
||||||
msg_queues=threads.msg_queues,
|
msg_queues=threads.msg_queues,
|
||||||
|
@ -35,9 +35,27 @@ class ObjectStoreMixin:
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
return self.data[id]
|
return self.data[id]
|
||||||
|
|
||||||
|
def _init_store(self):
|
||||||
|
sl = self._save_location()
|
||||||
|
if not os.path.exists(sl):
|
||||||
|
LOG.warning(f"Save location {sl} doesn't exist")
|
||||||
|
try:
|
||||||
|
os.makedirs(sl)
|
||||||
|
except Exception as ex:
|
||||||
|
LOG.exception(ex)
|
||||||
|
|
||||||
|
def _save_location(self):
|
||||||
|
save_location = self.config.get("aprsd.save_location", None)
|
||||||
|
if not save_location:
|
||||||
|
save_location = aprsd_config.DEFAULT_CONFIG_DIR
|
||||||
|
return save_location
|
||||||
|
|
||||||
def _save_filename(self):
|
def _save_filename(self):
|
||||||
|
save_location = self._save_location()
|
||||||
|
|
||||||
|
LOG.debug(f"{self.__class__.__name__}::Using save location {save_location}")
|
||||||
return "{}/{}.p".format(
|
return "{}/{}.p".format(
|
||||||
aprsd_config.DEFAULT_CONFIG_DIR,
|
save_location,
|
||||||
self.__class__.__name__.lower(),
|
self.__class__.__name__.lower(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ class WatchList(objectstore.ObjectStoreMixin):
|
|||||||
ring_size,
|
ring_size,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
self._init_store()
|
||||||
|
|
||||||
def is_enabled(self):
|
def is_enabled(self):
|
||||||
if self.config and "watch_list" in self.config["aprsd"]:
|
if self.config and "watch_list" in self.config["aprsd"]:
|
||||||
@ -165,6 +166,11 @@ class SeenList(objectstore.ObjectStoreMixin):
|
|||||||
cls.data = {}
|
cls.data = {}
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
||||||
|
def __init__(self, config=None):
|
||||||
|
if config:
|
||||||
|
self.config = config
|
||||||
|
self._init_store()
|
||||||
|
|
||||||
def update_seen(self, packet):
|
def update_seen(self, packet):
|
||||||
callsign = None
|
callsign = None
|
||||||
if "fromcall" in packet:
|
if "fromcall" in packet:
|
||||||
|
Loading…
Reference in New Issue
Block a user