config: Allow None as obsdb, default to it

This commit is contained in:
Teemu Ikonen
2023-03-03 12:31:11 +02:00
parent 237477564a
commit 1ba258fbf9
3 changed files with 36 additions and 3 deletions

View File

@@ -56,7 +56,7 @@ conffile_args = [
(('-o', '--obsdb'), {
'dest': 'obsdb',
'action': 'store',
'default': 'observations.db',
'default': None,
'help': 'Location of the observation database file',
}),
(('-D', '--datadir'), {

View File

@@ -9,7 +9,35 @@ from .utils import mcc_mnc_to_opc
log = logging.getLogger(__name__)
class ObservationDB(object):
class ObservationDBBase(object):
"""A no-op obsdb. Defines the API and can be used as dummy DB."""
def __init__(self, filename):
pass
def insert_locate(self, observation):
pass
def insert_submit(self, submission):
pass
def get_observation(self, timestamp):
return {
'wifis': [],
'cells': [],
}
def get_observation_list(self):
return []
def remove(self, timestamp):
pass
def close(self):
pass
class ObservationDB(ObservationDBBase):
location_sources = {
'No location': 0,
'GNSS': 1,

View File

@@ -213,7 +213,12 @@ def main():
raise ValueError(f'Unknown locator type in config: {mtype}')
log.info(f"Using '{mtype}' locator")
observationdb = obsdb.ObservationDB(conf['obsdb'])
if conf['obsdb'] is None:
# Use the dummy obsdb class
observationdb = obsdb.ObservationDBBase(None)
else:
observationdb = obsdb.ObservationDB(conf['obsdb'])
log.warning(f"Recording all observations to '{conf['obsdb']}'")
app = web.Application()
app.add_routes([