config migration for receiver_gps

This commit is contained in:
Jakob Ketterl 2020-03-29 18:08:26 +02:00
parent 2b7d6738f1
commit fd9e913a49
7 changed files with 45 additions and 11 deletions

View File

@ -219,8 +219,8 @@
map = new google.maps.Map($('.openwebrx-map')[0], { map = new google.maps.Map($('.openwebrx-map')[0], {
center: { center: {
lat: config.receiver_gps[0], lat: config.receiver_gps.lat,
lng: config.receiver_gps[1] lng: config.receiver_gps.lon
}, },
zoom: 5, zoom: 5,
mapTypeId: mapTypeId mapTypeId: mapTypeId

View File

@ -1097,7 +1097,7 @@ function on_ws_recv(evt) {
case "receiver_details": case "receiver_details":
var r = json['value']; var r = json['value'];
e('webrx-rx-title').innerHTML = r['receiver_name']; e('webrx-rx-title').innerHTML = r['receiver_name'];
var query = encodeURIComponent(r['receiver_gps'][0] + ',' + r['receiver_gps'][1]); var query = encodeURIComponent(r['receiver_gps']['lat'] + ',' + r['receiver_gps']['lon']);
e('webrx-rx-desc').innerHTML = r['receiver_location'] + ' | Loc: ' + r['locator'] + ', ASL: ' + r['receiver_asl'] + ' m, <a href="https://www.google.com/maps/search/?api=1&query=' + query + '" target="_blank" onclick="dont_toggle_rx_photo();">[maps]</a>'; e('webrx-rx-desc').innerHTML = r['receiver_location'] + ' | Loc: ' + r['locator'] + ', ASL: ' + r['receiver_asl'] + ' m, <a href="https://www.google.com/maps/search/?api=1&query=' + query + '" target="_blank" onclick="dont_toggle_rx_photo();">[maps]</a>';
e('webrx-rx-photo-title').innerHTML = r['photo_title']; e('webrx-rx-photo-title').innerHTML = r['photo_title'];
e('webrx-rx-photo-desc').innerHTML = r['photo_desc']; e('webrx-rx-photo-desc').innerHTML = r['photo_desc'];

View File

@ -3,6 +3,7 @@ import importlib.util
import os import os
import logging import logging
import json import json
from abc import ABC, abstractmethod
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -20,8 +21,27 @@ class ConfigError(object):
return "Configuration Error (key: {0}): {1}".format(self.key, self.message) return "Configuration Error (key: {0}): {1}".format(self.key, self.message)
class ConfigMigrator(ABC):
@abstractmethod
def migrate(self, config):
pass
class ConfigMigratorVersion1(ConfigMigrator):
def migrate(self, config):
gps = config["receiver_gps"]
config["receiver_gps"] = {"lat": gps[0], "lon": gps[1]}
config["version"] = 2
return config
class Config: class Config:
sharedConfig = None sharedConfig = None
currentVersion = 2
migrators = {
1: ConfigMigratorVersion1()
}
@staticmethod @staticmethod
def _loadPythonFile(file): def _loadPythonFile(file):
@ -45,7 +65,7 @@ class Config:
@staticmethod @staticmethod
def _loadConfig(): def _loadConfig():
for file in ["settings.json", "/etc/openwebrx/config_webrx.py", "./config_webrx.py"]: for file in ["./settings.json", "/etc/openwebrx/config_webrx.py", "./config_webrx.py"]:
try: try:
if file.endswith(".py"): if file.endswith(".py"):
return Config._loadPythonFile(file) return Config._loadPythonFile(file)
@ -60,7 +80,7 @@ class Config:
@staticmethod @staticmethod
def get(): def get():
if Config.sharedConfig is None: if Config.sharedConfig is None:
Config.sharedConfig = Config._loadConfig() Config.sharedConfig = Config._migrate(Config._loadConfig())
return Config.sharedConfig return Config.sharedConfig
@staticmethod @staticmethod
@ -89,3 +109,13 @@ class Config:
if not os.access(pm[key], os.W_OK): if not os.access(pm[key], os.W_OK):
return ConfigError(key, "temporary directory is not writable") return ConfigError(key, "temporary directory is not writable")
return None return None
@staticmethod
def _migrate(config):
version = config["version"] if "version" in config else 1
if version == Config.currentVersion:
return config
logger.debug("migrating config from version %i", version)
migrator = Config.migrators[version]
return migrator.migrate(config)

View File

@ -10,6 +10,8 @@ import json
class StatusController(Controller): class StatusController(Controller):
def indexAction(self): def indexAction(self):
pm = Config.get() pm = Config.get()
# convert to old format
gps = (pm["receiver_gps"]["lat"], pm["receiver_gps"]["lon"])
# TODO keys that have been left out since they are no longer simple strings: sdr_hw, bands, antenna # TODO keys that have been left out since they are no longer simple strings: sdr_hw, bands, antenna
vars = { vars = {
"status": "active", "status": "active",
@ -17,7 +19,7 @@ class StatusController(Controller):
"op_email": pm["receiver_admin"], "op_email": pm["receiver_admin"],
"users": ClientRegistry.getSharedInstance().clientCount(), "users": ClientRegistry.getSharedInstance().clientCount(),
"users_max": pm["max_clients"], "users_max": pm["max_clients"],
"gps": pm["receiver_gps"], "gps": gps,
"asl": pm["receiver_asl"], "asl": pm["receiver_asl"],
"loc": pm["receiver_location"], "loc": pm["receiver_location"],
"sw_version": openwebrx_version, "sw_version": openwebrx_version,
@ -44,12 +46,11 @@ class StatusController(Controller):
def jsonAction(self): def jsonAction(self):
pm = Config.get() pm = Config.get()
gps = pm["receiver_gps"]
status = { status = {
"receiver": { "receiver": {
"name": pm["receiver_name"], "name": pm["receiver_name"],
"admin": pm["receiver_admin"], "admin": pm["receiver_admin"],
"gps": {"lat": gps[0], "lon": gps[1]}, "gps": pm["receiver_gps"],
"asl": pm["receiver_asl"], "asl": pm["receiver_asl"],
"location": pm["receiver_location"], "location": pm["receiver_location"],
}, },

View File

@ -39,7 +39,8 @@ IGLOGIN {callsign} {password}
) )
if pm["aprs_igate_beacon"]: if pm["aprs_igate_beacon"]:
(lat, lon) = pm["receiver_gps"] lat = pm["receiver_gps"]["lat"]
lon = pm["receiver_gps"]["lon"]
direction_ns = "N" if lat > 0 else "S" direction_ns = "N" if lat > 0 else "S"
direction_we = "E" if lon > 0 else "W" direction_we = "E" if lon > 0 else "W"
lat = abs(lat) lat = abs(lat)

View File

@ -2,7 +2,8 @@ class Locator(object):
@staticmethod @staticmethod
def fromCoordinates(coordinates, depth=3): def fromCoordinates(coordinates, depth=3):
lat, lon = coordinates lat = coordinates["lat"]
lon = coordinates["lon"]
lon = lon + 180 lon = lon + 180
lat = lat + 90 lat = lat + 90

View File

@ -135,7 +135,8 @@ class DaylightSchedule(TimerangeSchedule):
def getSunTimes(self, date): def getSunTimes(self, date):
pm = Config.get() pm = Config.get()
lat, lng = pm["receiver_gps"] lat = pm["receiver_gps"]["lat"]
lng = pm["receiver_gps"]["lon"]
degtorad = math.pi / 180 degtorad = math.pi / 180
radtodeg = 180 / math.pi radtodeg = 180 / math.pi