Commit 0ff807c3 authored by Vasilis Tsiligiannis's avatar Vasilis Tsiligiannis

Reformat code with 'yapf' (fixes #308)

Signed-off-by: Vasilis Tsiligiannis's avatarVasilis Tsiligiannis <[email protected]>
parent 06c2bcb4
Pipeline #26526784 passed with stage
in 2 minutes and 43 seconds
......@@ -11,8 +11,9 @@ import time
from validators.url import url
import satnogsclient.config
from satnogsclient.settings import (SATNOGS_API_TOKEN, DEFAULT_LOGGING, SATNOGS_STATION_ID,
SATNOGS_STATION_LAT, SATNOGS_STATION_LON, SATNOGS_STATION_ELEV,
from satnogsclient.settings import (SATNOGS_API_TOKEN, DEFAULT_LOGGING,
SATNOGS_STATION_ID, SATNOGS_STATION_LAT,
SATNOGS_STATION_LON, SATNOGS_STATION_ELEV,
SATNOGS_NETWORK_API_URL)
from satnogsclient.scheduler.tasks import status_listener, exec_rigctld
......@@ -30,7 +31,8 @@ def main():
try:
url(SATNOGS_NETWORK_API_URL)
except ValueError:
raise Exception('Invalid SATNOGS_NETWORK_API_URL: {0}'.format(SATNOGS_NETWORK_API_URL))
raise Exception('Invalid SATNOGS_NETWORK_API_URL: {0}'.format(
SATNOGS_NETWORK_API_URL))
if not SATNOGS_STATION_ID:
raise Exception('SATNOGS_STATION_ID not configured.')
......
import logging
import socket
LOGGER = logging.getLogger('satnogsclient')
......@@ -60,11 +59,13 @@ class Commsocket(object):
def connect(self):
try:
LOGGER.debug('Opening TCP socket: %s:%s', self.ip_address, self.port)
LOGGER.debug('Opening TCP socket: %s:%s', self.ip_address,
self.port)
self.sock.connect((self.ip_address, self.port))
self._connected = True
except socket.error:
LOGGER.error('Cannot connect to socket %s:%s', self.ip_address, self.port)
LOGGER.error('Cannot connect to socket %s:%s', self.ip_address,
self.port)
self._connected = False
return self.is_connected
......@@ -75,7 +76,8 @@ class Commsocket(object):
try:
self.sock.send(message)
except socket.error:
LOGGER.error('Cannot send to socket %s:%s', self.ip_address, self.port)
LOGGER.error('Cannot send to socket %s:%s', self.ip_address,
self.port)
response = self.sock.recv(self._tasks_buffer_size)
LOGGER.debug('Received message: %s', response)
......@@ -107,7 +109,8 @@ class Commsocket(object):
try:
self.sock.bind((self._tcp_ip, self._tcp_port))
except socket.error:
LOGGER.error('Cannot bind socket %s:%s', self.ip_address, self.port)
LOGGER.error('Cannot bind socket %s:%s', self.ip_address,
self.port)
self.sock.close()
self._connected = False
self.bind()
This diff is collapsed.
......@@ -6,7 +6,6 @@ from datetime import datetime
import ephem
import pytz
LOGGER = logging.getLogger('default')
......
......@@ -15,12 +15,10 @@ from satnogsclient.observer.orbital import pinpoint
from satnogsclient import settings
LOGGER = logging.getLogger('default')
class Worker(object):
"""Class to facilitate as a worker for rotctl/rigctl."""
# sleep time of loop (in seconds)
......@@ -42,7 +40,12 @@ class Worker(object):
observer_dict = {}
satellite_dict = {}
def __init__(self, ip, port, time_to_stop=None, frequency=None, proc=None,
def __init__(self,
ip,
port,
time_to_stop=None,
frequency=None,
proc=None,
sleep_time=None):
"""Initialize worker class."""
self._ip = ip
......@@ -132,7 +135,6 @@ class Worker(object):
class WorkerTrack(Worker):
def send_to_socket(self, pin, sock):
# Read az/alt of sat and convert to radians
azi = pin['az'].conjugate() * 180 / math.pi
......@@ -143,15 +145,15 @@ class WorkerTrack(Worker):
position = sock.send("p\n").split('\n')
# if the need to move exceeds threshold, then do it
if (position[0].startswith("RPRT") or
abs(azi - float(position[0])) > settings.SATNOGS_ROT_THRESHOLD or
abs(alt - float(position[1])) > settings.SATNOGS_ROT_THRESHOLD):
abs(azi - float(position[0])) > settings.SATNOGS_ROT_THRESHOLD
or abs(alt - float(position[1])) >
settings.SATNOGS_ROT_THRESHOLD):
msg = 'P {0} {1}\n'.format(azi, alt)
LOGGER.debug('Rotctld msg: %s', msg)
sock.send(msg)
class WorkerFreq(Worker):
def send_to_socket(self, pin, sock):
doppler_calc_freq = self._frequency * (1 - (pin['rng_vlct'] / ephem.c))
msg = 'F {0}\n'.format(int(doppler_calc_freq))
......
......@@ -6,20 +6,16 @@ from apscheduler.schedulers.background import BackgroundScheduler
from satnogsclient import settings
JOBSTORES = {
'default': SQLAlchemyJobStore(url=settings.SATNOGS_SQLITE_URL)
}
JOBSTORES = {'default': SQLAlchemyJobStore(url=settings.SATNOGS_SQLITE_URL)}
EXECUTORS = {
'default': ThreadPoolExecutor(20),
}
JOB_DEFAULTS = {
'coalesce': True,
'max_instances': 1,
'misfire_grace_time': 5
}
JOB_DEFAULTS = {'coalesce': True, 'max_instances': 1, 'misfire_grace_time': 5}
SCHEDULER = BackgroundScheduler(jobstores=JOBSTORES, executors=EXECUTORS, job_defaults=JOB_DEFAULTS,
timezone=utc)
SCHEDULER = BackgroundScheduler(
jobstores=JOBSTORES,
executors=EXECUTORS,
job_defaults=JOB_DEFAULTS,
timezone=utc)
......@@ -30,11 +30,7 @@ signal.signal(signal.SIGINT, signal_term_handler)
def spawn_observer(**kwargs):
obj = kwargs.pop('obj')
tle = {
'tle0': obj['tle0'],
'tle1': obj['tle1'],
'tle2': obj['tle2']
}
tle = {'tle0': obj['tle0'], 'tle1': obj['tle1'], 'tle2': obj['tle2']}
end = parser.parse(obj['end'])
observer = Observer()
......@@ -91,10 +87,10 @@ def post_data():
for fil in os.walk(settings.SATNOGS_OUTPUT_PATH).next()[2]:
file_path = os.path.join(*[settings.SATNOGS_OUTPUT_PATH, fil])
if (fil.startswith('receiving_satnogs') or
fil.startswith('receiving_waterfall') or
fil.startswith('receiving_data') or
os.stat(file_path).st_size == 0):
if (fil.startswith('receiving_satnogs')
or fil.startswith('receiving_waterfall')
or fil.startswith('receiving_data')
or os.stat(file_path).st_size == 0):
continue
if fil.startswith('satnogs'):
observation = {'payload': open(file_path, 'rb')}
......@@ -108,8 +104,8 @@ def post_data():
if '_' not in fil:
continue
observation_id = fil.split('_')[1]
LOGGER.info(
'Trying to PUT observation data for id: %s', observation_id)
LOGGER.info('Trying to PUT observation data for id: %s',
observation_id)
url = urljoin(base_url, observation_id)
if not url.endswith('/'):
url += '/'
......@@ -117,22 +113,26 @@ def post_data():
LOGGER.debug('URL: %s', url)
LOGGER.debug('Headers: %s', headers)
LOGGER.debug('Observation file: %s', observation)
response = requests.put(url, headers=headers,
files=observation,
verify=settings.SATNOGS_VERIFY_SSL,
stream=True,
timeout=45)
response = requests.put(
url,
headers=headers,
files=observation,
verify=settings.SATNOGS_VERIFY_SSL,
stream=True,
timeout=45)
if response.status_code == 200:
LOGGER.info('Success: status code 200')
if settings.SATNOGS_COMPLETE_OUTPUT_PATH != "":
os.rename(os.path.join(settings.SATNOGS_OUTPUT_PATH, fil),
os.path.join(settings.SATNOGS_COMPLETE_OUTPUT_PATH, fil))
os.rename(
os.path.join(settings.SATNOGS_OUTPUT_PATH, fil),
os.path.join(settings.SATNOGS_COMPLETE_OUTPUT_PATH, fil))
else:
os.remove(os.path.join(settings.SATNOGS_OUTPUT_PATH, fil))
elif response.status_code == 404:
LOGGER.error('Bad status code: %s', response.status_code)
os.rename(os.path.join(settings.SATNOGS_OUTPUT_PATH, fil),
os.path.join(settings.SATNOGS_INCOMPLETE_OUTPUT_PATH, fil))
os.rename(
os.path.join(settings.SATNOGS_OUTPUT_PATH, fil),
os.path.join(settings.SATNOGS_INCOMPLETE_OUTPUT_PATH, fil))
else:
LOGGER.error('Bad status code: %s', response.status_code)
......@@ -148,12 +148,15 @@ def get_jobs():
LOGGER.debug('Headers: %s', headers)
LOGGER.info('Trying to GET observation jobs from the network')
response = requests.get(
url, params=params, headers=headers,
verify=settings.SATNOGS_VERIFY_SSL, timeout=45)
url,
params=params,
headers=headers,
verify=settings.SATNOGS_VERIFY_SSL,
timeout=45)
if not response.status_code == 200:
raise Exception(
'Status code: {0} on request: {1}'.format(response.status_code, url))
raise Exception('Status code: {0} on request: {1}'.format(
response.status_code, url))
for job in SCHEDULER.get_jobs():
if job.name in [spawn_observer.__name__]:
......@@ -167,11 +170,12 @@ def get_jobs():
kwargs = {'obj': obj}
LOGGER.info('Adding new job: %s', job_id)
LOGGER.debug('Observation obj: %s', obj)
SCHEDULER.add_job(spawn_observer,
'date',
run_date=start,
id='observer_{0}'.format(job_id),
kwargs=kwargs)
SCHEDULER.add_job(
spawn_observer,
'date',
run_date=start,
id='observer_{0}'.format(job_id),
kwargs=kwargs)
tasks.reverse()
......
......@@ -15,12 +15,18 @@ def _cast_or_none(func, value):
# Ground station information
SATNOGS_API_TOKEN = environ.get('SATNOGS_API_TOKEN', None)
SATNOGS_PRE_OBSERVATION_SCRIPT = environ.get('SATNOGS_PRE_OBSERVATION_SCRIPT', None)
SATNOGS_POST_OBSERVATION_SCRIPT = environ.get('SATNOGS_POST_OBSERVATION_SCRIPT', None)
SATNOGS_STATION_ID = _cast_or_none(int, environ.get('SATNOGS_STATION_ID', None))
SATNOGS_STATION_LAT = _cast_or_none(float, environ.get('SATNOGS_STATION_LAT', None))
SATNOGS_STATION_LON = _cast_or_none(float, environ.get('SATNOGS_STATION_LON', None))
SATNOGS_STATION_ELEV = _cast_or_none(float, environ.get('SATNOGS_STATION_ELEV', None))
SATNOGS_PRE_OBSERVATION_SCRIPT = environ.get('SATNOGS_PRE_OBSERVATION_SCRIPT',
None)
SATNOGS_POST_OBSERVATION_SCRIPT = environ.get(
'SATNOGS_POST_OBSERVATION_SCRIPT', None)
SATNOGS_STATION_ID = _cast_or_none(int, environ.get('SATNOGS_STATION_ID',
None))
SATNOGS_STATION_LAT = _cast_or_none(float,
environ.get('SATNOGS_STATION_LAT', None))
SATNOGS_STATION_LON = _cast_or_none(float,
environ.get('SATNOGS_STATION_LON', None))
SATNOGS_STATION_ELEV = _cast_or_none(float,
environ.get('SATNOGS_STATION_ELEV', None))
# Output paths
SATNOGS_APP_PATH = environ.get('SATNOGS_APP_PATH', '/tmp/.satnogs')
......@@ -29,20 +35,23 @@ SATNOGS_COMPLETE_OUTPUT_PATH = environ.get('SATNOGS_COMPLETE_OUTPUT_PATH', '')
SATNOGS_INCOMPLETE_OUTPUT_PATH = environ.get('SATNOGS_INCOMPLETE_OUTPUT_PATH',
'/tmp/.satnogs/data/incomplete')
for p in [SATNOGS_APP_PATH,
SATNOGS_OUTPUT_PATH,
SATNOGS_COMPLETE_OUTPUT_PATH,
SATNOGS_INCOMPLETE_OUTPUT_PATH]:
for p in [
SATNOGS_APP_PATH, SATNOGS_OUTPUT_PATH, SATNOGS_COMPLETE_OUTPUT_PATH,
SATNOGS_INCOMPLETE_OUTPUT_PATH
]:
if p != "" and not os.path.exists(p):
os.mkdir(p)
SATNOGS_REMOVE_RAW_FILES = bool(strtobool(environ.get('SATNOGS_REMOVE_RAW_FILES', 'True')))
SATNOGS_REMOVE_RAW_FILES = bool(
strtobool(environ.get('SATNOGS_REMOVE_RAW_FILES', 'True')))
SATNOGS_VERIFY_SSL = bool(strtobool(environ.get('SATNOGS_VERIFY_SSL', 'True')))
DEFAULT_SQLITE_PATH = path.join(SATNOGS_APP_PATH, 'jobs.sqlite')
SATNOGS_SQLITE_URL = environ.get('SATNOGS_SQLITE_URL', 'sqlite:///' + DEFAULT_SQLITE_PATH)
SATNOGS_SQLITE_URL = environ.get('SATNOGS_SQLITE_URL',
'sqlite:///' + DEFAULT_SQLITE_PATH)
SATNOGS_NETWORK_API_URL = environ.get('SATNOGS_NETWORK_API_URL', 'https://network.satnogs.org/api/')
SATNOGS_NETWORK_API_URL = environ.get('SATNOGS_NETWORK_API_URL',
'https://network.satnogs.org/api/')
SATNOGS_NETWORK_API_QUERY_INTERVAL = 1 # In minutes
SATNOGS_NETWORK_API_POST_INTERVAL = 2 # In minutes
GNURADIO_UDP_PORT = 16886
......@@ -73,7 +82,8 @@ RIG_SERIAL_SPEED = ""
# Common script parameters
SATNOGS_DOPPLER_CORR_PER_SEC = environ.get('SATNOGS_DOPPLER_CORR_PER_SEC', None)
SATNOGS_DOPPLER_CORR_PER_SEC = environ.get('SATNOGS_DOPPLER_CORR_PER_SEC',
None)
SATNOGS_LO_OFFSET = environ.get('SATNOGS_LO_OFFSET', None)
SATNOGS_PPM_ERROR = environ.get('SATNOGS_PPM_ERROR', None)
SATNOGS_IF_GAIN = environ.get('SATNOGS_IF_GAIN', None)
......@@ -83,7 +93,8 @@ SATNOGS_ANTENNA = environ.get('SATNOGS_ANTENNA', None)
SATNOGS_DEV_ARGS = environ.get('SATNOGS_DEV_ARGS', None)
ENABLE_IQ_DUMP = bool(strtobool(environ.get('ENABLE_IQ_DUMP', 'False')))
IQ_DUMP_FILENAME = environ.get('IQ_DUMP_FILENAME', None)
DISABLE_DECODED_DATA = bool(strtobool(environ.get('DISABLE_DECODED_DATA', 'False')))
DISABLE_DECODED_DATA = bool(
strtobool(environ.get('DISABLE_DECODED_DATA', 'False')))
# Logging configuration
DEFAULT_LOGGING = {
......
......@@ -9,8 +9,10 @@ LOGGER = logging.getLogger('default')
def get_gnuradio_info():
process = subprocess.Popen(['python', '-m', 'satnogs.satnogs_info'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process = subprocess.Popen(
['python', '-m', 'satnogs.satnogs_info'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
gr_satnogs_info, _ = process.communicate() # pylint: disable=W0612
client_metadata = {
'radio': {
......@@ -34,20 +36,23 @@ def get_gnuradio_info():
client_metadata['radio']['version'] = 'invalid'
else:
if 'version' in gr_satnogs_info:
client_metadata['radio']['version'] = gr_satnogs_info['version']
client_metadata['radio']['version'] = gr_satnogs_info[
'version']
else:
client_metadata['radio']['version'] = 'unknown'
return client_metadata
def exec_gnuradio(observation_file, waterfall_file, freq, baud,
script_name, decoded_data):
arguments = {'filename': observation_file,
'waterfall': waterfall_file,
'rx_device': client_settings.SATNOGS_RX_DEVICE,
'center_freq': str(freq),
'script_name': script_name,
'decoded_data': decoded_data}
def exec_gnuradio(observation_file, waterfall_file, freq, baud, script_name,
decoded_data):
arguments = {
'filename': observation_file,
'waterfall': waterfall_file,
'rx_device': client_settings.SATNOGS_RX_DEVICE,
'center_freq': str(freq),
'script_name': script_name,
'decoded_data': decoded_data
}
scriptname = arguments['script_name']
arg_string = ' '
if not scriptname:
......@@ -70,11 +75,10 @@ def exec_gnuradio(observation_file, waterfall_file, freq, baud,
arg_string += '--baudrate=' + str(int(baud)) + ' '
if client_settings.SATNOGS_RX_DEVICE and "--rx-sdr-device" not in arg_string:
arg_string += '--rx-sdr-device=' + client_settings.SATNOGS_RX_DEVICE + ' '
if (client_settings.SATNOGS_DOPPLER_CORR_PER_SEC and
"--doppler-correction-per-sec" not in arg_string):
if (client_settings.SATNOGS_DOPPLER_CORR_PER_SEC
and "--doppler-correction-per-sec" not in arg_string):
arg_string += ('--doppler-correction-per-sec=' +
client_settings.SATNOGS_DOPPLER_CORR_PER_SEC +
' ')
client_settings.SATNOGS_DOPPLER_CORR_PER_SEC + ' ')
if client_settings.SATNOGS_LO_OFFSET and "--lo-offset" not in arg_string:
arg_string += '--lo-offset=' + client_settings.SATNOGS_LO_OFFSET + ' '
if client_settings.SATNOGS_PPM_ERROR and "--ppm" not in arg_string:
......@@ -90,13 +94,14 @@ def exec_gnuradio(observation_file, waterfall_file, freq, baud,
if client_settings.SATNOGS_DEV_ARGS and "--dev-args" not in arg_string:
arg_string += '--dev-args=' + client_settings.SATNOGS_DEV_ARGS + ' '
if client_settings.ENABLE_IQ_DUMP and "--enable-iq-dump" not in arg_string:
arg_string += '--enable-iq-dump=' + str(int(client_settings.ENABLE_IQ_DUMP is True)) + ' '
arg_string += '--enable-iq-dump=' + str(
int(client_settings.ENABLE_IQ_DUMP is True)) + ' '
if client_settings.IQ_DUMP_FILENAME and "--iq-file-path" not in arg_string:
arg_string += '--iq-file-path=' + client_settings.IQ_DUMP_FILENAME + ' '
if not client_settings.DISABLE_DECODED_DATA and "--decoded-data-file-path" not in arg_string:
arg_string += '--decoded-data-file-path=' + arguments['decoded_data'] + ' '
LOGGER.info('Starting GNUradio python script')
proc = subprocess.Popen([scriptname + " " + arg_string], shell=True,
preexec_fn=os.setsid)
proc = subprocess.Popen(
[scriptname + " " + arg_string], shell=True, preexec_fn=os.setsid)
return proc
from setuptools import setup
import versioneer
setup(
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
......
[tox]
envlist = flake8,pylint,robot_lint,py27,robot
envlist = flake8,yapf,pylint,robot_lint,py27,robot
[flake8]
max-line-length = 180
......@@ -10,6 +10,15 @@ deps =
skip_install = True
commands = flake8
[testenv:yapf]
deps =
yapf
skip_install = True
commands = yapf -d -r \
-e satnogsclient/_version.py \
setup.py \
satnogsclient
[testenv:pylint]
deps =
pylint
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment