openwebrx-clone/owrx/config.py

76 lines
2.2 KiB
Python
Raw Normal View History

2019-05-05 17:59:03 +00:00
import os
2019-05-04 14:56:23 +00:00
class Property(object):
def __init__(self, value = None):
self.value = value
2019-05-05 13:51:33 +00:00
self.callbacks = []
2019-05-04 14:56:23 +00:00
def getValue(self):
return self.value
def setValue(self, value):
self.value = value
2019-05-05 13:51:33 +00:00
for c in self.callbacks:
c(self.value)
return self
def wire(self, callback):
self.callbacks.append(callback)
if not self.value is None: callback(self.value)
return self
2019-05-04 14:56:23 +00:00
class PropertyManager(object):
sharedInstance = None
@staticmethod
def getSharedInstance():
if PropertyManager.sharedInstance is None:
PropertyManager.sharedInstance = PropertyManager()
return PropertyManager.sharedInstance
def __init__(self):
self.properties = {}
def getProperty(self, name):
if not name in self.properties:
self.properties[name] = Property()
return self.properties[name]
2019-05-04 18:26:11 +00:00
def getPropertyValue(self, name):
return self.getProperty(name).getValue()
2019-05-05 17:59:03 +00:00
class RequirementMissingException(Exception):
pass
class FeatureDetector(object):
2019-05-07 13:50:20 +00:00
features = {
"core": [ "csdr", "nmux" ],
"rtl_sdr": [ "rtl_sdr" ],
"sdrplay": [ "rx_tools" ],
"hackrf": [ "rx_tools" ]
}
def is_available(self, feature):
return self.has_requirements(self.get_requirements(feature))
def get_requirements(self, feature):
return FeatureDetector.features[feature]
def has_requirements(self, requirements):
passed = True
for requirement in requirements:
methodname = "has_" + requirement
if hasattr(self, methodname) and callable(getattr(self, methodname)):
passed = passed and getattr(self, methodname)()
else:
print("detection of requirement {0} not implement. please fix in code!".format(requirement))
return passed
def has_csdr(self):
return os.system("csdr 2> /dev/null") != 32512
def has_nmux(self):
return os.system("nmux --help 2> /dev/null") != 32512
def has_rtl_sdr(self):
return os.system("rtl_sdr --help 2> /dev/null") != 32512
def has_rx_tools(self):
return os.system("rx_sdr --help 2> /dev/null") != 32512