Skip to content

Commit

Permalink
WIP Fix nasa#72 - Upgrade PyQt and implement fixes/cleanup/refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lbleier-GSFC committed Apr 28, 2020
1 parent 8db78cb commit 81a892b
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 230 deletions.
18 changes: 11 additions & 7 deletions GroundSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
#
#!/usr/bin/env python3
#
import sys
import subprocess
import shlex
import subprocess
import sys
from pathlib import Path

from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox

from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox
from MainWindow import Ui_MainWindow
from RoutingService import RoutingService

Expand All @@ -42,6 +44,8 @@ def __init__(self):
super().__init__()
self.setupUi((self))

self.rootDir = Path(sys.argv[0]).resolve().parent

self.RoutingService = None

self.pushButtonStartTlm.clicked.connect(self.startTlmSystem)
Expand Down Expand Up @@ -89,14 +93,14 @@ def startTlmSystem(self):
subscription = f'--sub=GroundSystem.{selectedSpacecraft}.TelemetryPackets'

# Open Telemetry System
system_call = f'python3 Subsystems/tlmGUI/TelemetrySystem.py {subscription}'
system_call = f'python3 {self.rootDir}/Subsystems/tlmGUI/TelemetrySystem.py {subscription}'
args = shlex.split(system_call)
subprocess.Popen(args)

# Start command system
@staticmethod
def startCmdSystem():
subprocess.Popen(['python3', 'Subsystems/cmdGui/CommandSystem.py'])
def startCmdSystem(self):
subprocess.Popen(
['python3', f'{self.rootDir}/Subsystems/cmdGui/CommandSystem.py'])

# Start FDL-FUL gui system
#def startFDLSystem(self):
Expand Down
136 changes: 60 additions & 76 deletions Subsystems/cmdGui/CHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@
import re
import sys

# from struct import *


#
# Determines data type (--string, --byte, --half, --word, --double)
Expand Down Expand Up @@ -97,11 +95,7 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
# Try to open textfile list of header files
try:
with open(filename) as textfile:
<<<<<<< HEAD
for l in textfile:
=======
for line in textfile:
>>>>>>> beef5f4... WIP Fix #72 - Upgrade PyQt and clean/fix/refactor for python3
# Remove whitespace before and after
l = l.strip()
if l and not l.startswith("#"):
Expand All @@ -116,14 +110,14 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
# Send paths back to caller function
return paths
except IOError:
print("Couldn't find default file. Checking command line arguments.")
print("Couldn't find default file. Check command line arguments.")
except:
print("Unexpected error:", sys.exc_info()[0])

print("No header files found. Please make sure to provide the\n"
"default file for loading headers (CHeaderParser-hdr-paths.txt)")

# If we got to here, we couldn't find any header files, return empty list
# If we got here, we couldn't find any header files, return empty list
return []


Expand Down Expand Up @@ -247,15 +241,17 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
for i, cmd in enumerate(unused_cmdDesc, start=1):
print(f"(Command {i} of {len(unused_cmdDesc)}) {cmd}")

# Get user input to see if any commands from this file require parameters
more_param_cmds = input(
f'Do any commands in {cmd_file_name} require parameters? (yes/no): ')

while str.lower(more_param_cmds) not in ['yes', 'y', 'no', 'n']:
print("Your response was not valid. Please enter (yes, y, no, or n).")
while True:
# Get user input to see if any commands from this file require parameters
more_param_cmds = input(
f'Do any commands in {cmd_file_name} require parameters? (yes/no): '
)
if more_param_cmds.lower() not in ['yes', 'y', 'no', 'n']:
print(
"Your response was not valid. Please enter (yes, y, no, or n)."
)
else:
break

# Check for exit condition
if str.lower(more_param_cmds) in ['no', 'n']:
Expand All @@ -269,16 +265,15 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
while True:
# Get user input
command_choice = int(
input(
"Which command would you like to add parameters to (-1 to exit)? "
))
input("Choose from the list above or choose -1 to exit."))

# Check for exit condition
if command_choice == -1:
print("You have chosen to exit early. Exiting now.")
print("Exiting.")
break

# Make sure the choice is within range
<<<<<<< HEAD
while command_choice not in range(len(unused_cmdDesc)):
print(
f"You entered {command_choice}, but that isn't an option.")
Expand All @@ -295,14 +290,17 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
sys.exit()

cmdName = unused_cmdDesc[command_choice]
=======
if command_choice not in range(len(unused_cmdDesc)):
print(
f"You entered {command_choice}, but that isn't an option.")
else:
cmdName = unused_cmdDesc[command_choice]
>>>>>>> acd0b85... WIP Fix #72 - Upgrade PyQt and implement fixes/cleanup/refactoring

# Initialize Parameter variables to empty lists
paramNames = []
paramDesc = []
dataTypesOrig = []
dataTypesNew = []
paramLens = []
stringLens = []
paramNames, paramDesc, dataTypesOrig,\
dataTypesNew, paramLens, stringLens = ([] for _ in range(6))

# This empty list will hold possibly multiple lists of line numbers
# each list representing where inside the App Header file the
Expand All @@ -316,8 +314,10 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
# create a copy of file_lines for parsing structures
file_lines = list(master_hdr)

# inside_struct will keep track of where the next for loop is while its scanning the file
# if it is between '{' and '}', it will assume it's inside of a struct
# inside_struct will keep track of where the next
# for loop is while it's scanning the file
# if it is between '{' and '}', it will assume
# it's inside of a struct
inside_struct = False

# line_num will keep track of what line we are looking at in the header file
Expand Down Expand Up @@ -368,45 +368,36 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
print(file_lines[line_num].strip())
print("--------------------------------------------")

# Give the user the option to exit too.
print("Choose from the list above or choose -1 to exit.")

# Get choice of structure from user.
struct_choice = int(
input("Which of the above structures would you like to use? "))

# Check for exit condition
if struct_choice == -1:
print("You have chosen to exit early. Exiting now.")
sys.exit()

# Make sure the choice is valid
while struct_choice not in range(len(list_cmd_structs)):
print("You entered", struct_choice,
", but that isn't an option.")
print("Choose from the list above or choose -1 to exit.")

# Get user input
while True:
# Give the user the option to exit too.
struct_choice = int(
input(
"Which of the above structures would you like to use? "
))
input("Choose from the list above or choose -1 to exit."))

# Check for exit condition
if struct_choice == -1:
print("You have chosen to exit early. Exiting now.")
print("Exiting.")
sys.exit()

# Make sure the choice is valid
if struct_choice not in range(len(list_cmd_structs)):
print(
f"You entered {struct_choice}, but that isn't an option."
)
else:
break

# After exiting the while loop, user's structure choice should be a valid assignment
# Take the appropriate list of lines from the list of command structures
cmd_struct_lines = list(list_cmd_structs[struct_choice])

# Initialize variable to get into loop
param_line = 0

# The following loop will iterate each time another parameter is added to a command
# After exiting the loop, the parameter variables should be updated with a list of
# parameters for the user's chosen command
# The following loop will iterate each time another
# parameter is added to a command
# After exiting the loop, the parameter variables
# should be updated with a list of parameters for
# the user's chosen command
while param_line in range(len(cmd_struct_lines)):

# Display the command structure with indexed before each line
Expand Down Expand Up @@ -456,13 +447,13 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
# If no type could match, ask user for data type
if not dataTypeNew:
dataTypeNew = input(
f'Data type for {paramNames[-1]} not found. Please enter new data type by hand: '
)
(f'Data type for {paramNames[-1]} not found. '
'Please enter new data type by hand: '))

dataTypesNew.append(dataTypeNew)
dataTypesNew.append(dataTypeNew.strip())

# finds length if --string data type
if dataTypeNew == '--string':
if 'string' in dataTypeNew:

# Split parameter name into list, separating by '[' or ']'
# if paramNames[-1] == 'array[10]' then
Expand All @@ -482,38 +473,31 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
print("Array size:", array_size)

# Set flag initially to false in order to get into while loop
array_size_within_limit = False
# array_size_within_limit = False

# Check conditions before loop to see if loop is even necessary
if array_size.isdigit() and 0 <= int(array_size) <= 128:
# If we got to this point, we have valid data already
# We won't need to go into while loop.
array_size_within_limit = True
# array_size_within_limit = array_size.isdigit() and int(
# array_size) in range(129)

# This while loop will make sure that the user input is both
# - a valid integer
# - between 0 and 128 (inclusively)
while (not array_size.isdigit()) or (
not array_size_within_limit):
while not array_size.isdigit() or int(
array_size) not in range(129):
# User input is not an integer
if not array_size.isdigit():
print("Could not translate", array_name_size[1])
else:
print(
"Array size out of bounds. It must be between 0 and 128."
)
try:
# Try to translate user input to an integer
array_size = int(
input(
f"Please enter the defined value for {array_name_size[1]} (0 - 128): "
))
input((f"Please enter the defined value for "
f"{array_name_size[1]} (0 - 128): ")))
except ValueError:
print("Could not translate",
str(array_name_size[1]), "into integer")
# If we got an integer, we continue to testing if integer is within range
else:
array_size_within_limit = array_size in range(129)
if not array_size_within_limit:
print(
"Array size out of bounds. It must be between 0 and 128."
)
pass

# Add string length argument to parameter list
stringLens.append(array_size)
Expand Down Expand Up @@ -549,7 +533,7 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
del unused_cmdDesc[command_choice]

# If we later want the list of structs to be updated, to remove
# previously selected structs, uncommend this line
# previously selected structs, uncomment this line
#del list_cmd_structs[struct_choice]

# saves parameter information in pickle file for command
Expand Down
Loading

0 comments on commit 81a892b

Please sign in to comment.