reformat with black

This commit is contained in:
Jakob Ketterl 2019-12-28 01:24:07 +01:00
parent e5724620a8
commit 1a3a5b43a0
15 changed files with 48 additions and 47 deletions

View File

@ -54,7 +54,6 @@ class Bookmarks(object):
return [] return []
return [] return []
def getBookmarks(self, range): def getBookmarks(self, range):
(lo, hi) = range (lo, hi) = range
return [b for b in self.bookmarks if lo <= b.getFrequency() <= hi] return [b for b in self.bookmarks if lo <= b.getFrequency() <= hi]

View File

@ -58,7 +58,7 @@ class Option(CommandMapping):
def map(self, value): def map(self, value):
if value is not None: if value is not None:
if isinstance(value, str) and " " in value: if isinstance(value, str) and " " in value:
template = "{0} \"{1}\"" template = '{0} "{1}"'
else: else:
template = "{0} {1}" template = "{0} {1}"
return template.format(self.option, value) return template.format(self.option, value)

View File

@ -186,7 +186,7 @@ class OpenWebRxReceiverClient(Client):
# keep trying until we find a suitable SDR # keep trying until we find a suitable SDR
if self.sdr.getState() == SdrSource.STATE_FAILED: if self.sdr.getState() == SdrSource.STATE_FAILED:
self.write_log_message("SDR device \"{0}\" has failed, selecting new device".format(self.sdr.getName())) self.write_log_message('SDR device "{0}" has failed, selecting new device'.format(self.sdr.getName()))
else: else:
break break

View File

@ -91,7 +91,7 @@ class AssetsController(Controller):
class OwrxAssetsController(AssetsController): class OwrxAssetsController(AssetsController):
def openFile(self, file): def openFile(self, file):
return pkg_resources.resource_stream('htdocs', file) return pkg_resources.resource_stream("htdocs", file)
class AprsSymbolsController(AssetsController): class AprsSymbolsController(AssetsController):

View File

@ -21,7 +21,7 @@ class DspManager(csdr.output):
self.localProps = ( self.localProps = (
self.sdrSource.getProps() self.sdrSource.getProps()
.collect( .collect(
"audio_compression", "audio_compression",
"fft_compression", "fft_compression",
"digimodes_fft_size", "digimodes_fft_size",
@ -35,7 +35,7 @@ class DspManager(csdr.output):
"temporary_directory", "temporary_directory",
"center_freq", "center_freq",
) )
.defaults(PropertyManager.getSharedInstance()) .defaults(PropertyManager.getSharedInstance())
) )
self.dsp = csdr.dsp(self) self.dsp = csdr.dsp(self)

View File

@ -223,9 +223,11 @@ class FeatureDetector(object):
def _has_soapy_driver(self, driver): def _has_soapy_driver(self, driver):
process = subprocess.Popen(["SoapySDRUtil", "--info"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) process = subprocess.Popen(["SoapySDRUtil", "--info"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
driverRegex = re.compile("^Module found: .*lib(.*)Support.so") driverRegex = re.compile("^Module found: .*lib(.*)Support.so")
def matchLine(line): def matchLine(line):
matches = driverRegex.match(line.decode()) matches = driverRegex.match(line.decode())
return matches is not None and matches.group(1) == driver return matches is not None and matches.group(1) == driver
lines = [matchLine(line) for line in process.stdout] lines = [matchLine(line) for line in process.stdout]
return reduce(or_, lines, False) return reduce(or_, lines, False)

View File

@ -226,6 +226,7 @@ class SdrSource(ABC):
if self.spectrumThread is None: if self.spectrumThread is None:
# local import due to circular depencency # local import due to circular depencency
from owrx.fft import SpectrumThread from owrx.fft import SpectrumThread
self.spectrumThread = SpectrumThread(self) self.spectrumThread = SpectrumThread(self)
self.spectrumThread.start() self.spectrumThread.start()

View File

@ -5,9 +5,7 @@ from .soapy import SoapyConnectorSource
class AirspySource(SoapyConnectorSource): class AirspySource(SoapyConnectorSource):
def __init__(self, id, props, port): def __init__(self, id, props, port):
super().__init__(id, props, port) super().__init__(id, props, port)
self.getCommandMapper().setMappings({ self.getCommandMapper().setMappings({"bias_tee": Flag("-t biastee=true")})
"bias_tee": Flag("-t biastee=true")
})
def getDriver(self): def getDriver(self):
return "airspy" return "airspy"

View File

@ -13,17 +13,19 @@ class ConnectorSource(SdrSource):
super().__init__(id, props, port) super().__init__(id, props, port)
self.controlSocket = None self.controlSocket = None
self.controlPort = getAvailablePort() self.controlPort = getAvailablePort()
self.getCommandMapper().setMappings({ self.getCommandMapper().setMappings(
"samp_rate": Option("-s"), {
"tuner_freq": Option("-f"), "samp_rate": Option("-s"),
"port": Option("-p"), "tuner_freq": Option("-f"),
"controlPort": Option("-c"), "port": Option("-p"),
"device": Option("-d"), "controlPort": Option("-c"),
"iqswap": Flag("-i"), "device": Option("-d"),
"rtltcp_compat": Flag("-r"), "iqswap": Flag("-i"),
"ppm": Option("-p"), "rtltcp_compat": Flag("-r"),
"rf_gain": Option("-g") "ppm": Option("-p"),
}) "rf_gain": Option("-g"),
}
)
def getEventNames(self): def getEventNames(self):
return super().getEventNames() + [ return super().getEventNames() + [
@ -40,9 +42,9 @@ class ConnectorSource(SdrSource):
if self.monitor is None: if self.monitor is None:
return return
if ( if (
(prop == "center_freq" or prop == "lfo_offset") (prop == "center_freq" or prop == "lfo_offset")
and "lfo_offset" in self.rtlProps and "lfo_offset" in self.rtlProps
and self.rtlProps["lfo_offset"] is not None and self.rtlProps["lfo_offset"] is not None
): ):
freq = self.rtlProps["center_freq"] + self.rtlProps["lfo_offset"] freq = self.rtlProps["center_freq"] + self.rtlProps["lfo_offset"]
self.sendControlMessage("center_freq", freq) self.sendControlMessage("center_freq", freq)

View File

@ -8,7 +8,11 @@ logger = logging.getLogger(__name__)
class DirectSource(SdrSource, metaclass=ABCMeta): class DirectSource(SdrSource, metaclass=ABCMeta):
def onPropertyChange(self, name, value): def onPropertyChange(self, name, value):
logger.debug("restarting sdr source due to property change: {0} changed to {1}".format(name, value)) logger.debug(
"restarting sdr source due to property change: {0} changed to {1}".format(
name, value
)
)
self.stop() self.stop()
self.sleepOnRestart() self.sleepOnRestart()
self.start() self.start()

View File

@ -5,15 +5,12 @@ from .direct import DirectSource
class FifiSdrSource(DirectSource): class FifiSdrSource(DirectSource):
def __init__(self, id, props, port): def __init__(self, id, props, port):
super().__init__(id, props, port) super().__init__(id, props, port)
self.getCommandMapper().setBase("arecord").setMappings({ self.getCommandMapper().setBase("arecord").setMappings(
"device": Option("-D"), {"device": Option("-D"), "samp_rate": Option("-r")}
"samp_rate": Option("-r") ).setStatic("-f S16_LE -c2 -")
}).setStatic("-f S16_LE -c2 -")
def getEventNames(self): def getEventNames(self):
return super().getEventNames() + [ return super().getEventNames() + ["device"]
"device"
]
def getFormatConversion(self): def getFormatConversion(self):
return "csdr convert_s16_f | csdr gain_ff 30" return "csdr convert_s16_f | csdr gain_ff 30"

View File

@ -5,13 +5,15 @@ from owrx.command import Flag, Option
class HackrfSource(DirectSource): class HackrfSource(DirectSource):
def __init__(self, id, props, port): def __init__(self, id, props, port):
super().__init__(id, props, port) super().__init__(id, props, port)
self.getCommandMapper().setBase("hackrf_transfer").setMappings({ self.getCommandMapper().setBase("hackrf_transfer").setMappings(
"samp_rate": Option("-s"), {
"tuner_freq": Option("-f"), "samp_rate": Option("-s"),
"rf_gain": Option("-g"), "tuner_freq": Option("-f"),
"lna_gain": Option("-l"), "rf_gain": Option("-g"),
"rf_amp": Option("-a") "lna_gain": Option("-l"),
}).setStatic("-r-") "rf_amp": Option("-a"),
}
).setStatic("-r-")
def getEventNames(self): def getEventNames(self):
return super().getEventNames() + [ return super().getEventNames() + [

View File

@ -33,7 +33,7 @@ class Resampler(DirectSource):
"csdr fir_decimate_cc {decimation} {ddc_transition_bw} HAMMING".format( "csdr fir_decimate_cc {decimation} {ddc_transition_bw} HAMMING".format(
decimation=self.decimation, ddc_transition_bw=self.transition_bw decimation=self.decimation, ddc_transition_bw=self.transition_bw
), ),
self.getNmuxCommand() self.getNmuxCommand(),
] ]
def activateProfile(self, profile_id=None): def activateProfile(self, profile_id=None):

View File

@ -7,14 +7,13 @@ from .connector import ConnectorSource
class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta): class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta):
def __init__(self, id, props, port): def __init__(self, id, props, port):
super().__init__(id, props, port) super().__init__(id, props, port)
self.getCommandMapper().setBase("soapy_connector").setMappings({ self.getCommandMapper().setBase("soapy_connector").setMappings({"antenna": Option("-a")})
"antenna": Option("-a")
})
""" """
must be implemented by child classes to be able to build a driver-based device selector by default. must be implemented by child classes to be able to build a driver-based device selector by default.
return value must be the corresponding soapy driver identifier. return value must be the corresponding soapy driver identifier.
""" """
@abstractmethod @abstractmethod
def getDriver(self): def getDriver(self):
pass pass
@ -25,7 +24,6 @@ class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta):
] ]
def parseDeviceString(self, dstr): def parseDeviceString(self, dstr):
def decodeComponent(c): def decodeComponent(c):
kv = c.split("=", 1) kv = c.split("=", 1)
if len(kv) < 2: if len(kv) < 2:
@ -36,7 +34,6 @@ class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta):
return [decodeComponent(c) for c in dstr.split(",")] return [decodeComponent(c) for c in dstr.split(",")]
def encodeDeviceString(self, dobj): def encodeDeviceString(self, dobj):
def encodeComponent(c): def encodeComponent(c):
if isinstance(c, str): if isinstance(c, str):
return c return c
@ -49,6 +46,7 @@ class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta):
this method always attempts to inject a driver= part into the soapysdr query, depending on what connector was used. this method always attempts to inject a driver= part into the soapysdr query, depending on what connector was used.
this prevents the soapy_connector from using the wrong device in scenarios where there's no same-type sdrs. this prevents the soapy_connector from using the wrong device in scenarios where there's no same-type sdrs.
""" """
def getCommandValues(self): def getCommandValues(self):
values = super().getCommandValues() values = super().getCommandValues()
if "device" in values and values["device"] is not None: if "device" in values and values["device"] is not None:

View File

@ -6,9 +6,7 @@ setup(
name="OpenWebRX", name="OpenWebRX",
version=str(strictversion), version=str(strictversion),
packages=find_namespace_packages(include=["owrx", "csdr", "htdocs"]), packages=find_namespace_packages(include=["owrx", "csdr", "htdocs"]),
package_data={ package_data={"htdocs": [f[len("htdocs/") :] for f in glob("htdocs/**/*", recursive=True)]},
"htdocs": [f[len("htdocs/"):] for f in glob("htdocs/**/*", recursive=True)]
},
entry_points={"console_scripts": ["openwebrx=owrx.__main__:main"]}, 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",