Skip to content

Commit

Permalink
Fix nasa#46 Recommended lgtm python issues
Browse files Browse the repository at this point in the history
Problems shown in this issue were fixed in nasa#72 as part of
updates/refactoring. Other lgtm issues addressed here.
Problems in auto-generated .py files not addressed.
Auto-generated .py files renamed with Ui_ prefix.
The lgtm.yml file must be updated to exclude these
See nasa/cFS#92
  • Loading branch information
lbleier-GSFC committed May 27, 2020
1 parent 5c14375 commit 257f929
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 32 deletions.
1 change: 0 additions & 1 deletion GroundSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def startCmdSystem():
def startFDLSystem(self):
selectedSpacecraft = self.getSelectedSpacecraftName()
if selectedSpacecraft == 'All':
subscription = ''
self.DisplayErrorMessage(
'Cannot open FDL manager.\nNo spacecraft selected.')
else:
Expand Down
10 changes: 4 additions & 6 deletions Subsystems/cmdGui/CHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,11 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
l = l.strip()
if l and not l.startswith("#"):
paths.append(l)
print(f"Using header files found in {filename}")
# Send paths back to caller function
return paths
print(f"Using header files found in {filename}")
# Send paths back to caller function
return paths
except IOError:
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)")
Expand Down Expand Up @@ -449,7 +447,7 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
input((f"Please enter the defined value for "
f"{array_name_size[1]} (0 - 128): ")))
except ValueError:
pass
pass # Ignore non-integer and try again

# Add string length argument to parameter list
stringLens.append(array_size)
Expand Down
6 changes: 3 additions & 3 deletions Subsystems/cmdGui/CommandSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from PyQt5.QtWidgets import QApplication, QDialog

from CommandSystemDialog import Ui_CommandSystemDialog
from Ui_CommandSystemDialog import Ui_CommandSystemDialog

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

Expand Down Expand Up @@ -161,7 +161,7 @@ def ProcessQuickButton(self, idx):
#
# Mark the remaining values as invalid
#
for j in range(i, 22):
for _ in range(i, 22):
cmdPageAppid.append(0)
cmdPageIsValid.append(False)

Expand Down Expand Up @@ -204,7 +204,7 @@ def ProcessQuickButton(self, idx):
quickIdx = subsys.index(cmdPageDesc[k])
quickButton.setText(quickCmd[quickIdx])
except ValueError:
pass
pass # Ignore quick button
quickIndices.append(quickIdx)
else:
subsysBrowser.setText("(unused)")
Expand Down
8 changes: 4 additions & 4 deletions Subsystems/cmdGui/Parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from PyQt5.QtWidgets import QApplication, QDialog

from HTMLDocsParser import HTMLDocsParser
from ParameterDialog import Ui_Dialog
from Ui_ParameterDialog import Ui_Dialog

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

Expand Down Expand Up @@ -82,7 +82,7 @@ def ProcessSendButton(self):
#
subsysTitle, cmdDesc, pageEndian, pageAddress, cmdCode, params = (
'' for _ in range(6))
idx, pagePktId, pagePort = (0 for _ in range(3))
pagePktId, pagePort = 0, 0
param_file = 'struct_c_f_e___e_s___start_app_cmd__t.html'

#
Expand All @@ -99,7 +99,7 @@ def ProcessSendButton(self):
elif opt in ("-d", "--descrip"):
cmdDesc = arg # command name, eg No-Op
elif opt in ("-i", "--idx"):
idx = int(arg) # comand index in command definition file
_ = int(arg) # comand index in command definition file
elif opt in ("-h", "--host"):
pageAddress = arg # send to address
elif opt in ("-p", "--port"):
Expand Down Expand Up @@ -141,7 +141,7 @@ def ProcessSendButton(self):
paramName.setText(paramNames[i])
descrip.setText(paramDesc[i])
except IndexError:
pass
pass # Ignore nonexistent array items

#
# Displays the dialog
Expand Down
2 changes: 1 addition & 1 deletion Subsystems/cmdGui/UdpCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

from PyQt5.QtWidgets import QApplication, QDialog

from GenericCommandDialog import Ui_GenericCommandDialog
from Ui_GenericCommandDialog import Ui_GenericCommandDialog

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

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 3 additions & 7 deletions Subsystems/tlmGUI/EventMessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import QApplication, QDialog

from EventMessageDialog import Ui_EventMessageDialog
from Ui_EventMessageDialog import Ui_EventMessageDialog

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

Expand Down Expand Up @@ -168,9 +168,7 @@ def usage():
# Set defaults for the arguments
#
pageTitle = "Event Messages"
udpPort = 10000
appId = 999
tlmDefFile = "not-needed.txt"
endian = "L"
subscription = ""

Expand All @@ -190,11 +188,11 @@ def usage():
usage()
sys.exit()
if opt in ("-p", "--port"):
udpPort = arg
_ = arg
elif opt in ("-t", "--title"):
pageTitle = arg
elif opt in ("-f", "--file"):
tlmDefFile = arg
_ = arg
elif opt in ("-a", "--appid"):
appId = arg
elif opt in ("-e", "--endian"):
Expand All @@ -207,8 +205,6 @@ def usage():

print('Event Messages Page started. Subscribed to', subscription)

py_endian = '<' if endian == 'L' else '>'

#
# Init the QT application and the Event Message class
#
Expand Down
10 changes: 5 additions & 5 deletions Subsystems/tlmGUI/GenericTelemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import QApplication, QDialog

from GenericTelemetryDialog import Ui_GenericTelemetryDialog
from Ui_GenericTelemetryDialog import Ui_GenericTelemetryDialog

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

Expand Down Expand Up @@ -124,7 +124,7 @@ def __init__(self, subscr):
def run(self):
while self.runs:
# Read envelope with address
address, datagram = self.subscriber.recv_multipart()
_, datagram = self.subscriber.recv_multipart()
# Send signal with received packet to front-end/GUI
self.gtSignalTlmDatagram.emit(datagram)

Expand All @@ -147,7 +147,7 @@ def usage():
# Set defaults for the arguments
#
pageTitle = "Telemetry Page"
udpPort = 10000
# udpPort = 10000
appId = 999
tlmDefFile = f"{ROOTDIR}/telemetry_def.txt"
endian = "L"
Expand All @@ -169,7 +169,7 @@ def usage():
usage()
sys.exit()
elif opt in ("-p", "--port"):
udpPort = arg
_ = arg
elif opt in ("-t", "--title"):
pageTitle = arg
elif opt in ("-f", "--file"):
Expand Down Expand Up @@ -225,7 +225,7 @@ def usage():
#
# Mark the remaining values as invalid
#
for j in range(i, 40):
for _ in range(i, 40):
tlmItemIsValid.append(False)

#
Expand Down
4 changes: 2 additions & 2 deletions Subsystems/tlmGUI/TelemetrySystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import QApplication, QDialog

from TelemetrySystemDialog import Ui_TelemetrySystemDialog
from Ui_TelemetrySystemDialog import Ui_TelemetrySystemDialog

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

Expand Down Expand Up @@ -219,7 +219,7 @@ def run(self):
#
# Mark the remaining values ad invalid
#
for j in range(i, 21):
for _ in range(i, 21):
tlmPageAppid.append(0)
tlmPageIsValid.append(False)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 6 additions & 3 deletions TlmMQRecv.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ def main():
subscriber.setsockopt(zmq.SUBSCRIBE, b"GroundSystem")

while True:
# Read envelope with address
address, contents = subscriber.recv_multipart()
print(f"[{address}] {contents}")
try:
# Read envelope with address
address, contents = subscriber.recv_multipart()
print(f"[{address}] {contents}")
except KeyboardInterrupt:
break

# We never get here but clean up anyhow
subscriber.close()
Expand Down

0 comments on commit 257f929

Please sign in to comment.