extended feature detection

This commit is contained in:
Jakob Ketterl 2019-05-07 15:50:20 +02:00
parent e937f2bca3
commit df9646aaf9
2 changed files with 36 additions and 17 deletions

View File

@ -39,16 +39,37 @@ class RequirementMissingException(Exception):
pass
class FeatureDetector(object):
def detectAllFeatures(self):
print("Starting Feature detection")
self.detect_csdr()
self.detect_nmux()
print("Feature detection completed.")
features = {
"core": [ "csdr", "nmux" ],
"rtl_sdr": [ "rtl_sdr" ],
"sdrplay": [ "rx_tools" ],
"hackrf": [ "rx_tools" ]
}
def detect_csdr(self):
if os.system("csdr 2> /dev/null") == 32512: #check for csdr
raise RequirementMissingException("You need to install \"csdr\" to run OpenWebRX!")
def is_available(self, feature):
return self.has_requirements(self.get_requirements(feature))
def detect_nmux(self):
if os.system("nmux --help 2> /dev/null") == 32512: #check for nmux
raise RequirementMissingException("You need to install an up-to-date version of \"csdr\" that contains the \"nmux\" tool to run OpenWebRX! Please upgrade \"csdr\"!")
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

View File

@ -21,13 +21,11 @@ def main():
if (name.startswith("__")): continue
pm.getProperty(name).setValue(value)
try:
FeatureDetector().detectAllFeatures()
except RequirementMissingException as e:
featureDetector = FeatureDetector()
if not featureDetector.is_available("core"):
print("you are missing required dependencies to run openwebrx. "
"please check the message and the readme for details:")
print(e)
"please check that the following core requirements are installed:")
print(", ".join(featureDetector.get_requirements("core")))
return
if (pm.getPropertyValue("start_rtl_thread")):