2019-05-12 12:35:25 +00:00
|
|
|
import threading
|
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
from owrx.config import PropertyManager
|
|
|
|
|
|
|
|
import logging
|
2019-07-21 17:40:28 +00:00
|
|
|
|
2019-05-12 12:35:25 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class SdrHuUpdater(threading.Thread):
|
|
|
|
def __init__(self):
|
|
|
|
self.doRun = True
|
2019-07-21 17:40:28 +00:00
|
|
|
super().__init__(daemon=True)
|
2019-05-12 12:35:25 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
pm = PropertyManager.getSharedInstance()
|
2019-07-21 17:40:28 +00:00
|
|
|
cmd = 'wget --timeout=15 -4qO- https://sdr.hu/update --post-data "url=http://{server_hostname}:{web_port}&apikey={sdrhu_key}" 2>&1'.format(
|
|
|
|
**pm.__dict__()
|
|
|
|
)
|
2019-05-12 12:35:25 +00:00
|
|
|
logger.debug(cmd)
|
2019-07-21 17:40:28 +00:00
|
|
|
returned = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).communicate()
|
|
|
|
returned = returned[0].decode("utf-8")
|
2019-05-12 12:35:25 +00:00
|
|
|
if "UPDATE:" in returned:
|
|
|
|
retrytime_mins = 20
|
2019-07-21 17:40:28 +00:00
|
|
|
value = returned.split("UPDATE:")[1].split("\n", 1)[0]
|
2019-05-12 12:35:25 +00:00
|
|
|
if value.startswith("SUCCESS"):
|
|
|
|
logger.info("Update succeeded!")
|
|
|
|
else:
|
|
|
|
logger.warning("Update failed, your receiver cannot be listed on sdr.hu! Reason: %s", value)
|
|
|
|
else:
|
|
|
|
retrytime_mins = 2
|
|
|
|
logger.warning("wget failed while updating, your receiver cannot be listed on sdr.hu!")
|
|
|
|
return retrytime_mins
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
while self.doRun:
|
|
|
|
retrytime_mins = self.update()
|
2019-07-21 17:40:28 +00:00
|
|
|
time.sleep(60 * retrytime_mins)
|