restructure project for packaging

This commit is contained in:
Jakob Ketterl 2019-12-08 17:15:48 +01:00
parent 37086bc6c7
commit 9164a3ed3a
8 changed files with 92 additions and 75 deletions

1
debian/openwebrx.install vendored Normal file
View File

@ -0,0 +1 @@
config_webrx.py etc/

View File

@ -1,66 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from http.server import HTTPServer from owrx.__main__ import main
from owrx.http import RequestHandler
from owrx.config import PropertyManager
from owrx.feature import FeatureDetector
from owrx.source import SdrService
from socketserver import ThreadingMixIn
from owrx.sdrhu import SdrHuUpdater
from owrx.service import Services
from owrx.websocket import WebSocketConnection
from owrx.pskreporter import PskReporter
import logging
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
class ThreadedHttpServer(ThreadingMixIn, HTTPServer):
pass
def main():
print(
"""
OpenWebRX - Open Source SDR Web App for Everyone! | for license see LICENSE file in the package
_________________________________________________________________________________________________
Author contact info: Andras Retzler, HA7ILM <randras@sdr.hu>
Author contact info: Jakob Ketterl, DD5JFK <dd5jfk@darc.de>
"""
)
pm = PropertyManager.getSharedInstance().loadConfig("config_webrx")
featureDetector = FeatureDetector()
if not featureDetector.is_available("core"):
print(
"you are missing required dependencies to run openwebrx. "
"please check that the following core requirements are installed:"
)
print(", ".join(featureDetector.get_requirements("core")))
return
# Get error messages about unknown / unavailable features as soon as possible
SdrService.loadProps()
if "sdrhu_key" in pm and pm["sdrhu_public_listing"]:
updater = SdrHuUpdater()
updater.start()
Services.start()
server = ThreadedHttpServer(("0.0.0.0", pm.getPropertyValue("web_port")), RequestHandler)
server.serve_forever()
if __name__ == "__main__": if __name__ == "__main__":
try: main()
main()
except KeyboardInterrupt:
WebSocketConnection.closeAll()
Services.stop()
PskReporter.stop()

60
owrx/__main__.py Normal file
View File

@ -0,0 +1,60 @@
from http.server import HTTPServer
from owrx.http import RequestHandler
from owrx.config import PropertyManager
from owrx.feature import FeatureDetector
from owrx.source import SdrService
from socketserver import ThreadingMixIn
from owrx.sdrhu import SdrHuUpdater
from owrx.service import Services
from owrx.websocket import WebSocketConnection
from owrx.pskreporter import PskReporter
import logging
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
class ThreadedHttpServer(ThreadingMixIn, HTTPServer):
pass
def main():
print(
"""
OpenWebRX - Open Source SDR Web App for Everyone! | for license see LICENSE file in the package
_________________________________________________________________________________________________
Author contact info: Andras Retzler, HA7ILM <randras@sdr.hu>
Author contact info: Jakob Ketterl, DD5JFK <dd5jfk@darc.de>
"""
)
pm = PropertyManager.getSharedInstance().loadConfig()
featureDetector = FeatureDetector()
if not featureDetector.is_available("core"):
print(
"you are missing required dependencies to run openwebrx. "
"please check that the following core requirements are installed:"
)
print(", ".join(featureDetector.get_requirements("core")))
return
# Get error messages about unknown / unavailable features as soon as possible
SdrService.loadProps()
if "sdrhu_key" in pm and pm["sdrhu_public_listing"]:
updater = SdrHuUpdater()
updater.start()
Services.start()
try:
server = ThreadedHttpServer(("0.0.0.0", pm.getPropertyValue("web_port")), RequestHandler)
server.serve_forever()
except KeyboardInterrupt:
WebSocketConnection.closeAll()
Services.stop()
PskReporter.stop()

View File

@ -1,3 +1,4 @@
import importlib.util
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -50,6 +51,10 @@ class Property(object):
return self return self
class ConfigNotFoundException(Exception):
pass
class PropertyManager(object): class PropertyManager(object):
sharedInstance = None sharedInstance = None
@ -128,10 +133,17 @@ class PropertyManager(object):
p.setValue(other_pm[key]) p.setValue(other_pm[key])
return self return self
def loadConfig(self, filename): def loadConfig(self):
cfg = __import__(filename) for file in ["/etc/config_webrx.py", "./config_webrx.py"]:
for name, value in cfg.__dict__.items(): try:
if name.startswith("__"): spec = importlib.util.spec_from_file_location("config_webrx", file)
continue cfg = importlib.util.module_from_spec(spec)
self[name] = value spec.loader.exec_module(cfg)
return self for name, value in cfg.__dict__.items():
if name.startswith("__"):
continue
self[name] = value
return self
except FileNotFoundError:
logger.debug("not found: %s", file)
raise ConfigNotFoundException("no usable config found! please make sure you have a valid configuration file!")

View File

@ -3,7 +3,7 @@ from owrx.socket import getAvailablePort
from datetime import datetime, timezone, timedelta from datetime import datetime, timezone, timedelta
from owrx.source import SdrService, SdrSource from owrx.source import SdrService, SdrSource
from owrx.bands import Bandplan from owrx.bands import Bandplan
from csdr import dsp, output from csdr.csdr import dsp, output
from owrx.wsjt import WsjtParser from owrx.wsjt import WsjtParser
from owrx.aprs import AprsParser from owrx.aprs import AprsParser
from owrx.config import PropertyManager from owrx.config import PropertyManager

View File

@ -7,7 +7,7 @@ from owrx.aprs import AprsParser
from owrx.metrics import Metrics, DirectMetric from owrx.metrics import Metrics, DirectMetric
from owrx.socket import getAvailablePort from owrx.socket import getAvailablePort
import threading import threading
import csdr from csdr import csdr
import time import time
import os import os
import signal import signal

View File

@ -25,7 +25,7 @@ from owrx.sdrhu import SdrHuUpdater
from owrx.config import PropertyManager from owrx.config import PropertyManager
if __name__ == "__main__": if __name__ == "__main__":
pm = PropertyManager.getSharedInstance().loadConfig("config_webrx") pm = PropertyManager.getSharedInstance().loadConfig()
if not "sdrhu_key" in pm: if not "sdrhu_key" in pm:
exit(1) exit(1)

View File

@ -1,11 +1,14 @@
from setuptools import setup, find_packages from setuptools import setup, find_namespace_packages
from owrx.version import strictversion from owrx.version import strictversion
setup( setup(
name="OpenWebRX", name="OpenWebRX",
version=str(strictversion), version=str(strictversion),
packages=find_packages(), packages=find_namespace_packages(include=["owrx", "csdr", "htdocs"]),
entry_points={"console_scripts": ["openwebrx=openwebrx:main"]}, package_data={
"htdocs": ["*", "**/*"]
},
entry_points={"console_scripts": ["openwebrx=owrx.__main__:main"]},
# use the github page for now # use the github page for now
url="https://github.com/jketterl/openwebrx", url="https://github.com/jketterl/openwebrx",
author="András Retzler, Jakob Ketterl", author="András Retzler, Jakob Ketterl",
@ -13,4 +16,5 @@ setup(
maintainer="Jakob Ketterl", maintainer="Jakob Ketterl",
maintainer_email="jakob.ketterl@gmx.de", maintainer_email="jakob.ketterl@gmx.de",
license="GAGPL", license="GAGPL",
python_requires=">=3.6",
) )