Commit 2d0230f7 authored by Vasilis Tsiligiannis's avatar Vasilis Tsiligiannis

Fix invalid names of constants and variables

Signed-off-by: Vasilis Tsiligiannis's avatarVasilis Tsiligiannis <[email protected]>
parent f63e58f4
Pipeline #20957173 passed with stage
in 2 minutes and 14 seconds
......@@ -2,7 +2,7 @@ import logging
import socket
logger = logging.getLogger('satnogsclient')
LOGGER = logging.getLogger('satnogsclient')
class Commsocket(object):
......@@ -11,48 +11,48 @@ class Commsocket(object):
Namely: rotctl and rigctl
"""
_BUFFER_SIZE = 2048
_TASKS_BUFFER_SIZE = 10480
_buffer_size = 2048
_tasks_buffer_size = 10480
_connected = False
def __init__(self, ip, port):
self._TCP_IP = ip
self._TCP_PORT = port
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
def __init__(self, ip_address, port):
self._tcp_ip = ip_address
self._tcp_port = port
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
@property
def ip(self):
return self._TCP_IP
def ip_address(self):
return self._tcp_ip
@ip.setter
def ip(self, new_ip):
self._TCP_IP = new_ip
@ip_address.setter
def ip_address(self, new_ip):
self._tcp_ip = new_ip
@property
def port(self):
return self._TCP_PORT
return self._tcp_port
@port.setter
def port(self, new_port):
self._TCP_PORT = new_port
self._tcp_port = new_port
@property
def buffer_size(self):
return self._BUFFER_SIZE
return self._buffer_size
@buffer_size.setter
def buffer_size(self, new_buffer_size):
self._BUFFER_SIZE = new_buffer_size
self._buffer_size = new_buffer_size
@property
def tasks_buffer_size(self):
return self._TASKS_BUFFER_SIZE
return self._tasks_buffer_size
@tasks_buffer_size.setter
def tasks_buffer_size(self, new_buffer_size):
self._TASKS_BUFFER_SIZE = new_buffer_size
self._tasks_buffer_size = new_buffer_size
@property
def is_connected(self):
......@@ -60,44 +60,44 @@ class Commsocket(object):
def connect(self):
try:
logger.debug('Opening TCP socket: %s:%s', self.ip, self.port)
self.s.connect((self.ip, 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, self.port)
LOGGER.error('Cannot connect to socket %s:%s', self.ip_address, self.port)
self._connected = False
return self.is_connected
def send(self, message):
if not self.is_connected:
self.connect()
logger.debug('Sending message: %s', message)
self.s.send(message)
response = self.s.recv(self._TASKS_BUFFER_SIZE)
logger.debug('Received message: %s', response)
LOGGER.debug('Sending message: %s', message)
self.sock.send(message)
response = self.sock.recv(self._tasks_buffer_size)
LOGGER.debug('Received message: %s', response)
return response
def send_not_recv(self, message):
if not self.is_connected:
self.connect()
logger.debug('Sending message: %s', message)
self.s.send(message)
LOGGER.debug('Sending message: %s', message)
self.sock.send(message)
def disconnect(self):
logger.info('Closing socket: %s', self.s)
self.s.close()
LOGGER.info('Closing socket: %s', self.sock)
self.sock.close()
self._connected = False
def receive(self, size):
resp = self.s.recv(size)
resp = self.sock.recv(size)
return resp
def listen(self):
self.s.listen(1)
self.sock.listen(1)
def accept(self):
conn, addr = self.s.accept() # pylint: disable=W0612
conn, addr = self.sock.accept() # pylint: disable=W0612
return conn
def bind(self):
self.s.bind((self._TCP_IP, self._TCP_PORT))
self.sock.bind((self._tcp_ip, self._tcp_port))
......@@ -8,7 +8,7 @@ from satnogsclient import settings
from satnogsclient.observer.worker import WorkerFreq, WorkerTrack
from satnogsclient.upsat import gnuradio_handler
logger = logging.getLogger('default')
LOGGER = logging.getLogger('default')
class Observer(object):
......@@ -33,7 +33,7 @@ class Observer(object):
self.observation_ogg_file = None
self.observation_waterfall_file = None
self.observation_waterfall_png = None
self.observation_receiving_decoded_data = None
self.observation_receiving_decoded_data = None # pylint: disable=C0103
self.observation_decoded_data = None
self.baud = None
self.observation_done_decoded_data = None
......@@ -116,7 +116,7 @@ class Observer(object):
def observe(self):
"""Starts threads for rotcrl and rigctl."""
if settings.SATNOGS_PRE_OBSERVATION_SCRIPT is not None:
logger.info('Executing pre-observation script.')
LOGGER.info('Executing pre-observation script.')
os.system(settings.SATNOGS_PRE_OBSERVATION_SCRIPT)
# if it is APT we want to save with a prefix until the observation
......@@ -126,7 +126,7 @@ class Observer(object):
self.observation_receiving_decoded_data
# start thread for rotctl
logger.info('Start gnuradio thread.')
LOGGER.info('Start gnuradio thread.')
self._gnu_proc = gnuradio_handler.exec_gnuradio(
self.observation_raw_file,
self.observation_waterfall_file,
......@@ -134,18 +134,18 @@ class Observer(object):
self.baud,
self.script_name,
self.observation_decoded_data)
logger.info('Start rotctrl thread.')
LOGGER.info('Start rotctrl thread.')
self.run_rot()
# start thread for rigctl
logger.info('Start rigctrl thread.')
LOGGER.info('Start rigctrl thread.')
self.run_rig()
# Polling gnuradio process status
self.poll_gnu_proc_status()
if "satnogs_generic_iq_receiver.py" not in settings.GNURADIO_SCRIPT_FILENAME:
logger.info('Rename encoded files for uploading.')
LOGGER.info('Rename encoded files for uploading.')
self.rename_ogg_file()
self.rename_data_file()
logger.info('Creating waterfall plot.')
LOGGER.info('Creating waterfall plot.')
self.plot_waterfall()
def run_rot(self):
......@@ -155,8 +155,8 @@ class Observer(object):
time_to_stop=self.observation_end,
proc=self._gnu_proc,
sleep_time=3)
logger.debug('TLE: %s', self.tle)
logger.debug('Observation end: %s', self.observation_end)
LOGGER.debug('TLE: %s', self.tle)
LOGGER.debug('Observation end: %s', self.observation_end)
self.tracker_rot.trackobject(self.location, self.tle)
self.tracker_rot.trackstart()
......@@ -166,16 +166,16 @@ class Observer(object):
frequency=self.frequency,
time_to_stop=self.observation_end,
proc=self._gnu_proc)
logger.debug('Rig Frequency %s', self.frequency)
logger.debug('Observation end: %s', self.observation_end)
LOGGER.debug('Rig Frequency %s', self.frequency)
LOGGER.debug('Observation end: %s', self.observation_end)
self.tracker_freq.trackobject(self.location, self.tle)
self.tracker_freq.trackstart()
def poll_gnu_proc_status(self):
while self._gnu_proc.poll() is None:
sleep(30)
logger.info('Observation Finished')
logger.info('Executing post-observation script.')
LOGGER.info('Observation Finished')
LOGGER.info('Executing post-observation script.')
if self._post_exec_script is not None:
os.system(self._post_exec_script)
......@@ -183,13 +183,13 @@ class Observer(object):
if os.path.isfile(self.observation_raw_file):
os.rename(self.observation_raw_file,
self.observation_ogg_file)
logger.info('Rename encoded file for uploading finished')
LOGGER.info('Rename encoded file for uploading finished')
def rename_data_file(self):
if os.path.isfile(self.observation_receiving_decoded_data):
os.rename(self.observation_receiving_decoded_data,
self.observation_done_decoded_data)
logger.info('Rename data file for uploading finished')
LOGGER.info('Rename data file for uploading finished')
def plot_waterfall(self):
if os.path.isfile(self.observation_waterfall_file):
......@@ -199,11 +199,11 @@ class Observer(object):
(self.observation_waterfall_file,
self.observation_waterfall_png),
shell=True)
logger.info('Waterfall plot finished')
LOGGER.info('Waterfall plot finished')
if plot == 0 and settings.SATNOGS_REMOVE_RAW_FILES:
self.remove_waterfall_file()
else:
logger.error('No waterfall data file found')
LOGGER.error('No waterfall data file found')
def remove_waterfall_file(self):
if os.path.isfile(self.observation_waterfall_file):
......
......@@ -7,7 +7,7 @@ import ephem
import pytz
logger = logging.getLogger('default')
LOGGER = logging.getLogger('default')
def pinpoint(observer_dict, satellite_dict, timestamp=None):
......@@ -24,26 +24,26 @@ def pinpoint(observer_dict, satellite_dict, timestamp=None):
"""
# observer object
if all(x in observer_dict for x in ['lat', 'lon', 'elev']):
logger.debug('Observer data: %s', observer_dict)
LOGGER.debug('Observer data: %s', observer_dict)
observer = ephem.Observer()
observer.lon = str(observer_dict['lon'])
observer.lat = str(observer_dict['lat'])
observer.elevation = float(observer_dict['elev'])
else:
logger.error('Something went wrong: %s', observer_dict)
LOGGER.error('Something went wrong: %s', observer_dict)
return {'ok': False}
# satellite object
if all(x in satellite_dict for x in ['tle0', 'tle1', 'tle2']):
logger.debug('Satellite data: %s', satellite_dict)
LOGGER.debug('Satellite data: %s', satellite_dict)
tle0 = str(satellite_dict['tle0'])
tle1 = str(satellite_dict['tle1'])
tle2 = str(satellite_dict['tle2'])
try:
satellite = ephem.readtle(tle0, tle1, tle2)
except ValueError:
logger.error('Something went wrong: %s', satellite_dict)
logger.error(sys.exc_info()[0])
LOGGER.error('Something went wrong: %s', satellite_dict)
LOGGER.error(sys.exc_info()[0])
return {'ok': False}
else:
return {'ok': False}
......@@ -63,5 +63,5 @@ def pinpoint(observer_dict, satellite_dict, timestamp=None):
'ok': True
}
logger.debug('Calculated data: %s', calculated_data)
LOGGER.debug('Calculated data: %s', calculated_data)
return calculated_data
......@@ -16,7 +16,7 @@ from satnogsclient.observer.orbital import pinpoint
from satnogsclient import settings
logger = logging.getLogger('default')
LOGGER = logging.getLogger('default')
class Worker(object):
......@@ -45,8 +45,8 @@ class Worker(object):
def __init__(self, ip, port, time_to_stop=None, frequency=None, proc=None,
sleep_time=None):
"""Initialize worker class."""
self._IP = ip
self._PORT = port
self._ip = ip
self._port = port
if frequency:
self._frequency = frequency
if time_to_stop:
......@@ -81,7 +81,7 @@ class Worker(object):
Stops by calling trackstop()
"""
self.is_alive = True
logger.info('Tracking initiated')
LOGGER.info('Tracking initiated')
if not all([self.observer_dict, self.satellite_dict]):
raise ValueError('Satellite or observer dictionary not defined.')
......@@ -91,7 +91,7 @@ class Worker(object):
return self.is_alive
def send_to_socket(self, p, sock):
def send_to_socket(self, pin, sock):
# Needs to be implemented in freq/track workers implicitly
raise NotImplementedError
......@@ -101,7 +101,7 @@ class Worker(object):
Uses observer and satellite objects set by trackobject().
Will exit when observation_end timestamp is reached.
"""
sock = Commsocket(self._IP, self._PORT)
sock = Commsocket(self._ip, self._port)
sock.connect()
# track satellite
......@@ -110,9 +110,9 @@ class Worker(object):
# check if we need to exit
self.check_observation_end_reached()
p = pinpoint(self.observer_dict, self.satellite_dict)
if p['ok']:
self.send_to_socket(p, sock)
pin = pinpoint(self.observer_dict, self.satellite_dict)
if pin['ok']:
self.send_to_socket(pin, sock)
time.sleep(self._sleep_time)
sock.disconnect()
......@@ -121,7 +121,7 @@ class Worker(object):
"""
Sets object flag to false and stops the tracking thread.
"""
logger.info('Tracking stopped.')
LOGGER.info('Tracking stopped.')
self.is_alive = False
if self._gnu_proc:
os.killpg(os.getpgid(self._gnu_proc.pid), signal.SIGINT)
......@@ -133,28 +133,28 @@ class Worker(object):
class WorkerTrack(Worker):
def send_to_socket(self, p, sock):
def send_to_socket(self, pin, sock):
# Read az/alt of sat and convert to radians
az = p['az'].conjugate() * 180 / math.pi
alt = p['alt'].conjugate() * 180 / math.pi
self._azimuth = az
azi = pin['az'].conjugate() * 180 / math.pi
alt = pin['alt'].conjugate() * 180 / math.pi
self._azimuth = azi
self._altitude = alt
# read current position of rotator, [0] az and [1] el
position = sock.send("p\n").split('\n')
# if the need to move exceeds threshold, then do it
if (position[0].startswith("RPRT") or
abs(az - float(position[0])) > settings.SATNOGS_ROT_THRESHOLD or
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(az, alt)
logger.debug('Rotctld msg: %s', msg)
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, p, sock):
doppler_calc_freq = self._frequency * (1 - (p['rng_vlct'] / ephem.c))
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))
logger.debug('Initial frequency: %s', self._frequency)
logger.debug('Rigctld msg: %s', msg)
LOGGER.debug('Initial frequency: %s', self._frequency)
LOGGER.debug('Rigctld msg: %s', msg)
sock.send(msg)
......@@ -7,19 +7,19 @@ from apscheduler.schedulers.background import BackgroundScheduler
from satnogsclient import settings
jobstores = {
JOBSTORES = {
'default': SQLAlchemyJobStore(url=settings.SATNOGS_SQLITE_URL)
}
executors = {
EXECUTORS = {
'default': ThreadPoolExecutor(20),
}
job_defaults = {
JOB_DEFAULTS = {
'coalesce': True,
'max_instances': 1,
'misfire_grace_time': 5
}
scheduler = BackgroundScheduler(jobstores=jobstores, executors=executors, job_defaults=job_defaults,
SCHEDULER = BackgroundScheduler(jobstores=JOBSTORES, executors=EXECUTORS, job_defaults=JOB_DEFAULTS,
timezone=utc)
......@@ -6,19 +6,19 @@ from multiprocessing import Process
import subprocess
from dateutil import parser
from satnogsclient.scheduler import scheduler
from satnogsclient.scheduler import SCHEDULER
from satnogsclient import settings
from satnogsclient.observer.observer import Observer
import requests
logger = logging.getLogger('default')
log_path = settings.SATNOGS_OUTPUT_PATH + "/files/"
LOGGER = logging.getLogger('default')
LOG_PATH = settings.SATNOGS_OUTPUT_PATH + "/files/"
def signal_term_handler():
p = subprocess.Popen(['ps', '-ef'], stdout=subprocess.PIPE)
out, err = p.communicate() # pylint: disable=W0612
process = subprocess.Popen(['ps', '-ef'], stdout=subprocess.PIPE)
out, err = process.communicate() # pylint: disable=W0612
for line in out.splitlines():
if 'satnogs-client' in line:
pid = int(line.split(None, 2)[1])
......@@ -74,11 +74,11 @@ def spawn_observer(**kwargs):
'script_name': script_name
}
logger.debug('Observer args: %s', setup_kwargs)
LOGGER.debug('Observer args: %s', setup_kwargs)
setup = observer.setup(**setup_kwargs)
if setup:
logger.info('Spawning observer worker.')
LOGGER.info('Spawning observer worker.')
observer.observe()
else:
raise RuntimeError('Error in observer setup.')
......@@ -86,66 +86,66 @@ def spawn_observer(**kwargs):
def post_data():
"""PUT observation data back to Network API."""
logger.info('Post data started')
LOGGER.info('Post data started')
base_url = urljoin(settings.SATNOGS_NETWORK_API_URL, 'observations/')
headers = {'Authorization': 'Token {0}'.format(settings.SATNOGS_API_TOKEN)}
for f in os.walk(settings.SATNOGS_OUTPUT_PATH).next()[2]:
file_path = os.path.join(*[settings.SATNOGS_OUTPUT_PATH, f])
if (f.startswith('receiving_satnogs') or
f.startswith('receiving_waterfall') or
f.startswith('receiving_data') or
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):
continue
if f.startswith('satnogs'):
if fil.startswith('satnogs'):
observation = {'payload': open(file_path, 'rb')}
elif f.startswith('waterfall'):
elif fil.startswith('waterfall'):
observation = {'waterfall': open(file_path, 'rb')}
elif f.startswith('data'):
elif fil.startswith('data'):
observation = {'demoddata': open(file_path, 'rb')}
else:
logger.debug('Ignore file: %s', f)
LOGGER.debug('Ignore file: %s', fil)
continue
if '_' not in f:
if '_' not in fil:
continue
observation_id = f.split('_')[1]
logger.info(
observation_id = fil.split('_')[1]
LOGGER.info(
'Trying to PUT observation data for id: %s', observation_id)
url = urljoin(base_url, observation_id)
if not url.endswith('/'):
url += '/'
logger.debug('PUT file %s to network API', f)
logger.debug('URL: %s', url)
logger.debug('Headers: %s', headers)
logger.debug('Observation file: %s', observation)
LOGGER.debug('PUT file %s to network API', fil)
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)
if response.status_code == 200:
logger.info('Success: status code 200')
LOGGER.info('Success: status code 200')
if settings.SATNOGS_COMPLETE_OUTPUT_PATH != "":
os.rename(os.path.join(settings.SATNOGS_OUTPUT_PATH, f),
os.path.join(settings.SATNOGS_COMPLETE_OUTPUT_PATH, f))
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, f))
os.remove(os.path.join(settings.SATNOGS_OUTPUT_PATH, fil))
else:
logger.error('Bad status code: %s', response.status_code)
os.rename(os.path.join(settings.SATNOGS_OUTPUT_PATH, f),
os.path.join(settings.SATNOGS_INCOMPLETE_OUTPUT_PATH, f))
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))
def get_jobs():
"""Query SatNOGS Network API to GET jobs."""
logger.info('Get jobs started')
LOGGER.info('Get jobs started')
url = urljoin(settings.SATNOGS_NETWORK_API_URL, 'jobs/')
params = {'ground_station': settings.SATNOGS_STATION_ID}
headers = {'Authorization': 'Token {0}'.format(settings.SATNOGS_API_TOKEN)}
logger.debug('URL: %s', url)
logger.debug('Params: %s', params)
logger.debug('Headers: %s', headers)
logger.info('Trying to GET observation jobs from the network')
LOGGER.debug('URL: %s', url)
LOGGER.debug('Params: %s', params)
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)
......@@ -154,7 +154,7 @@ def get_jobs():
raise Exception(
'Status code: {0} on request: {1}'.format(response.status_code, url))
for job in scheduler.get_jobs():
for job in SCHEDULER.get_jobs():
if job.name in [spawn_observer.__name__]:
job.remove()
......@@ -164,9 +164,9 @@ def get_jobs():
start = parser.parse(obj['start'])
job_id = str(obj['id'])
kwargs = {'obj': obj}
logger.info('Adding new job: %s', job_id)
logger.debug('Observation obj: %s', obj)
scheduler.add_job(spawn_observer,
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),
......@@ -175,30 +175,30 @@ def get_jobs():
def status_listener():
logger.info('Starting scheduler...')
scheduler.start()
scheduler.remove_all_jobs()
LOGGER.info('Starting scheduler...')
SCHEDULER.start()
SCHEDULER.remove_all_jobs()
interval = settings.SATNOGS_NETWORK_API_QUERY_INTERVAL
scheduler.add_job(get_jobs, 'interval', minutes=interval)
SCHEDULER.add_job(get_jobs, 'interval', minutes=interval)
msg = 'Registering `get_jobs` periodic task ({0} min. interval)'.format(
interval)
logger.info(msg)
LOGGER.info(msg)
interval = settings.SATNOGS_NETWORK_API_POST_INTERVAL
msg = 'Registering `post_data` periodic task ({0} min. interval)'.format(
interval)
logger.info(msg)
scheduler.add_job(post_data, 'interval', minutes=interval)
LOGGER.info(msg)
SCHEDULER.add_job(post_data, 'interval', minutes=interval)
os.environ['GNURADIO_SCRIPT_PID'] = '0'
os.environ['SCHEDULER'] = 'ON'
def get_observation_list():
obs_list = scheduler.get_jobs()
obs_list = SCHEDULER.get_jobs()
return obs_list
def get_observation(job_id):
obs = scheduler.get_job(job_id)
obs = SCHEDULER.get_job(job_id)
return obs
......@@ -221,5 +221,5 @@ def rigctld_subprocess():
if settings.RIG_SERIAL_SPEED != "":
rig_args += "-s " + settings.RIG_SERIAL_SPEED + " "
rig_args += "-t " + str(settings.SATNOGS_RIG_PORT)
logger.info('Starting rigctl daemon')
LOGGER.info('Starting rigctl daemon')
os.system("rigctld" + rig_args)
<
......@@ -4,7 +4,7 @@ import os
from satnogsclient import settings as client_settings
logger = logging.getLogger('default')
LOGGER = logging.getLogger('default')
def exec_gnuradio(observation_file, waterfall_file, freq, baud,
......@@ -60,7 +60,7 @@ def exec_gnuradio(observation_file, waterfall_file, freq, baud,
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'] + ' '