Replace os.system with subprocess.

parent 56d5827f
Pipeline #28607283 passed with stage
in 2 minutes and 17 seconds
......@@ -9,10 +9,12 @@ except ImportError:
from datetime import datetime
from time import sleep
import json
import requests
import shlex
import subprocess
import numpy as np
import matplotlib.pyplot as plt
import requests
import satnogsclient.config
from satnogsclient import settings
......@@ -111,14 +113,19 @@ class Observer(object):
"""Starts threads for rotcrl and rigctl."""
if settings.SATNOGS_PRE_OBSERVATION_SCRIPT is not None:
LOGGER.info('Executing pre-observation script.')
pre_script = settings.SATNOGS_PRE_OBSERVATION_SCRIPT
pre_script = pre_script.replace("{{FREQ}}", str(self.frequency))
pre_script = pre_script.replace("{{TLE}}", json.dumps(self.tle))
pre_script = pre_script.replace("{{ID}}", str(self.observation_id))
pre_script = pre_script.replace("{{BAUD}}", str(self.baud))
pre_script = pre_script.replace("{{SCRIPT_NAME}}",
self.script_name)
os.system(pre_script)
replacements = [
("{{FREQ}}", str(self.frequency)),
("{{TLE}}", json.dumps(self.tle)),
("{{ID}}", str(self.observation_id)),
("{{BAUD}}", str(self.baud)),
("{{SCRIPT_NAME}}", self.script_name),
]
pre_script = []
for arg in shlex.split(settings.SATNOGS_PRE_OBSERVATION_SCRIPT):
for key, val in replacements:
arg = arg.replace(key, val)
pre_script.append(arg)
subprocess.call(pre_script)
# if it is APT we want to save with a prefix until the observation
# is complete, then rename.
......@@ -214,15 +221,19 @@ class Observer(object):
LOGGER.info('Observation Finished')
LOGGER.info('Executing post-observation script.')
if settings.SATNOGS_POST_OBSERVATION_SCRIPT is not None:
post_script = settings.SATNOGS_POST_OBSERVATION_SCRIPT
post_script = post_script.replace("{{FREQ}}", str(self.frequency))
post_script = post_script.replace("{{TLE}}", json.dumps(self.tle))
post_script = post_script.replace("{{ID}}",
str(self.observation_id))
post_script = post_script.replace("{{BAUD}}", str(self.baud))
post_script = post_script.replace("{{SCRIPT_NAME}}",
self.script_name)
os.system(post_script)
replacements = [
("{{FREQ}}", str(self.frequency)),
("{{TLE}}", json.dumps(self.tle)),
("{{ID}}", str(self.observation_id)),
("{{BAUD}}", str(self.baud)),
("{{SCRIPT_NAME}}", self.script_name),
]
post_script = []
for arg in shlex.split(settings.SATNOGS_POST_OBSERVATION_SCRIPT):
for key, val in replacements:
arg = arg.replace(key, val)
post_script.append(arg)
subprocess.call(post_script)
def rename_ogg_file(self):
if os.path.isfile(self.observation_raw_file):
......
......@@ -219,17 +219,17 @@ def exec_rigctld():
def rigctld_subprocess():
# Start rigctl daemon
rig_args = " "
rig_args = ["rigctld"]
if settings.RIG_MODEL != "":
rig_args += "-m " + settings.RIG_MODEL + " "
rig_args += ["-m", settings.RIG_MODEL]
if settings.RIG_FILE != "":
rig_args += "-r " + settings.RIG_FILE + " "
rig_args += ["-r", settings.RIG_FILE]
if settings.RIG_PTT_FILE != "":
rig_args += "-p " + settings.RIG_PTT_FILE + " "
rig_args += ["-p", settings.RIG_PTT_FILE]
if settings.RIG_PTT_TYPE != "":
rig_args += "-P " + settings.RIG_PTT_TYPE + " "
rig_args += ["-P", settings.RIG_PTT_TYPE]
if settings.RIG_SERIAL_SPEED != "":
rig_args += "-s " + settings.RIG_SERIAL_SPEED + " "
rig_args += "-t " + str(settings.SATNOGS_RIG_PORT)
rig_args += ["-s", settings.RIG_SERIAL_SPEED]
rig_args += ["-t", str(settings.SATNOGS_RIG_PORT)]
LOGGER.info('Starting rigctl daemon')
os.system("rigctld" + rig_args)
subprocess.call(rig_args)
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