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 []
def getBookmarks(self, range):
(lo, hi) = range
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):
if value is not None:
if isinstance(value, str) and " " in value:
template = "{0} \"{1}\""
template = '{0} "{1}"'
else:
template = "{0} {1}"
return template.format(self.option, value)

View File

@ -186,7 +186,7 @@ class OpenWebRxReceiverClient(Client):
# keep trying until we find a suitable SDR
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:
break

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,7 +8,11 @@ logger = logging.getLogger(__name__)
class DirectSource(SdrSource, metaclass=ABCMeta):
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.sleepOnRestart()
self.start()

View File

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

View File

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

View File

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

View File

@ -7,14 +7,13 @@ from .connector import ConnectorSource
class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta):
def __init__(self, id, props, port):
super().__init__(id, props, port)
self.getCommandMapper().setBase("soapy_connector").setMappings({
"antenna": Option("-a")
})
self.getCommandMapper().setBase("soapy_connector").setMappings({"antenna": Option("-a")})
"""
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.
"""
@abstractmethod
def getDriver(self):
pass
@ -25,7 +24,6 @@ class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta):
]
def parseDeviceString(self, dstr):
def decodeComponent(c):
kv = c.split("=", 1)
if len(kv) < 2:
@ -36,7 +34,6 @@ class SoapyConnectorSource(ConnectorSource, metaclass=ABCMeta):
return [decodeComponent(c) for c in dstr.split(",")]
def encodeDeviceString(self, dobj):
def encodeComponent(c):
if isinstance(c, str):
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 prevents the soapy_connector from using the wrong device in scenarios where there's no same-type sdrs.
"""
def getCommandValues(self):
values = super().getCommandValues()
if "device" in values and values["device"] is not None:

View File

@ -6,9 +6,7 @@ setup(
name="OpenWebRX",
version=str(strictversion),
packages=find_namespace_packages(include=["owrx", "csdr", "htdocs"]),
package_data={
"htdocs": [f[len("htdocs/"):] for f in glob("htdocs/**/*", recursive=True)]
},
package_data={"htdocs": [f[len("htdocs/") :] for f in glob("htdocs/**/*", recursive=True)]},
entry_points={"console_scripts": ["openwebrx=owrx.__main__:main"]},
# use the github page for now
url="https://github.com/jketterl/openwebrx",