Skip to content

Commit

Permalink
Fix sonarqube, formatting, dates
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Feb 9, 2025
1 parent 045fdb7 commit 9fdad3c
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 113 deletions.
10 changes: 5 additions & 5 deletions openc3-cosmos-script-runner-api/scripts/run_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 OpenC3, Inc.
# Copyright 2025 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
Expand Down Expand Up @@ -72,7 +72,7 @@ def run_script_log(id, message, color="BLACK", message_log=True):
RunningScript.message_log().write(line_to_write + "\n", True)
running_script_anycable_publish(
f"running-script-channel:{id}",
{"type": "output", "line": line_to_write, "color": color}
{"type": "output", "line": line_to_write, "color": color},
)


Expand Down Expand Up @@ -127,7 +127,7 @@ def run_script_log(id, message, color="BLACK", message_log=True):
"type": "start",
"filename": path,
"active_scripts": len(running),
}
},
)

# Subscribe to the ActionCable generated topic which is namedspaced with channel_prefix
Expand Down Expand Up @@ -236,7 +236,7 @@ def run_script_log(id, message, color="BLACK", message_log=True):
"type": "script",
"method": "backtrace",
"args": running_script.current_backtrace,
}
},
)
case "debug":
run_script_log(
Expand Down Expand Up @@ -280,7 +280,7 @@ def run_script_log(id, message, color="BLACK", message_log=True):
)
running_script_anycable_publish(
"all-scripts-channel",
{"type": "complete", "active_scripts": active_scripts}
{"type": "complete", "active_scripts": active_scripts},
)
finally:
if running_script:
Expand Down
79 changes: 34 additions & 45 deletions openc3-cosmos-script-runner-api/scripts/running_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 OpenC3, Inc.
# Copyright 2025 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
Expand All @@ -21,7 +21,8 @@
from openc3.utilities.store_queued import StoreQueued
import linecache

SCRIPT_API = 'script-api'
SCRIPT_API = "script-api"


def running_script_publish(channel_name, data):
stream_name = ":".join([SCRIPT_API, channel_name])
Expand All @@ -38,7 +39,7 @@ def running_script_anycable_publish(channel_name, data):
def _openc3_script_sleep(sleep_time=None):
if RunningScript.disconnect:
return True
RunningScript.instance.update_running_script_store('waiting')
RunningScript.instance.update_running_script_store("waiting")

running_script_anycable_publish(
f"running-script-channel:{RunningScript.instance.id}",
Expand All @@ -47,7 +48,7 @@ def _openc3_script_sleep(sleep_time=None):
"filename": RunningScript.instance.current_filename,
"line_no": RunningScript.instance.current_line_number,
"state": "waiting",
}
},
)

if sleep_time is None: # Handle infinite wait
Expand All @@ -66,7 +67,7 @@ def _openc3_script_sleep(sleep_time=None):
"filename": RunningScript.instance.current_filename,
"line_no": RunningScript.instance.current_line_number,
"state": "waiting",
}
},
)

if RunningScript.instance.pause:
Expand Down Expand Up @@ -301,7 +302,7 @@ def __init__(self, id, scope, name, disconnect):
"scope": self.scope,
"text": self.body,
"breakpoints": breakpoints,
}
},
)
if self.PYTHON_SUITE_REGEX.findall(self.body):
# Call load_utility to parse the suite and allow for individual methods to be executed
Expand All @@ -311,7 +312,7 @@ def __init__(self, id, scope, name, disconnect):
SuiteRunner.build_suites(from_globals=globals())

# Called to update the running script state every time the state or current_line_number changes
def update_running_script_store(self, state = None):
def update_running_script_store(self, state=None):
if state:
self.state = state
self.details["state"] = self.state
Expand Down Expand Up @@ -378,7 +379,7 @@ def do_step(self):
"filename": self.current_filename,
"line_no": self.current_line_number,
"state": self.state,
}
},
)
self.step = True
self.go = True
Expand Down Expand Up @@ -535,15 +536,15 @@ def pre_line_instrumentation(
detail_string = os.path.basename(filename) + ":" + str(line_number)
Logger.detail_string = detail_string

self.update_running_script_store('running')
self.update_running_script_store("running")
running_script_anycable_publish(
f"running-script-channel:{RunningScript.id}",
{
"type": "line",
"filename": self.current_filename,
"line_no": self.current_line_number,
"state": "running",
}
},
)
self.handle_pause(filename, line_number)
self.handle_line_delay()
Expand Down Expand Up @@ -757,7 +758,7 @@ def wait_for_go_or_stop(self, error=None, prompt=None):
"filename": self.current_filename,
"line_no": self.current_line_number,
"state": self.state,
}
},
)
if prompt:
running_script_anycable_publish(
Expand All @@ -768,7 +769,7 @@ def wait_for_go_or_stop(self, error=None, prompt=None):
"prompt_id": prompt["id"],
"args": prompt["args"],
"kwargs": prompt["kwargs"],
}
},
)
if prompt:
self.clear_prompt()
Expand All @@ -794,7 +795,7 @@ def wait_for_go_or_stop_or_retry(self, error=None):
"filename": self.current_filename,
"line_no": self.current_line_number,
"state": self.state,
}
},
)
self.go = False
self.mark_running()
Expand All @@ -813,7 +814,7 @@ def mark_running(self):
"filename": self.current_filename,
"line_no": self.current_line_number,
"state": self.state,
}
},
)

def mark_paused(self):
Expand All @@ -826,7 +827,7 @@ def mark_paused(self):
"filename": self.current_filename,
"line_no": self.current_line_number,
"state": self.state,
}
},
)

def mark_waiting(self):
Expand All @@ -839,7 +840,7 @@ def mark_waiting(self):
"filename": self.current_filename,
"line_no": self.current_line_number,
"state": self.state,
}
},
)

def mark_error(self):
Expand All @@ -852,7 +853,7 @@ def mark_error(self):
"filename": self.current_filename,
"line_no": self.current_line_number,
"state": self.state,
}
},
)

def mark_fatal(self):
Expand All @@ -865,7 +866,7 @@ def mark_fatal(self):
"filename": self.current_filename,
"line_no": self.current_line_number,
"state": self.state,
}
},
)

def mark_stopped(self):
Expand All @@ -878,7 +879,7 @@ def mark_stopped(self):
"filename": self.current_filename,
"line_no": self.current_line_number,
"state": self.state,
}
},
)
if SuiteRunner.suite_results:
SuiteRunner.suite_results.complete()
Expand All @@ -905,7 +906,7 @@ def mark_stopped(self):
parts[0] += f"_{init_split[-1]}"
running_script_anycable_publish(
f"running-script-channel:{self.id}",
{"type": "report", "report": SuiteRunner.suite_results.report()}
{"type": "report", "report": SuiteRunner.suite_results.report()},
)
# Write out the report to a local file
log_dir = os.path.join(RAILS_ROOT, "log")
Expand All @@ -932,7 +933,9 @@ def mark_stopped(self):
# Wait for the file to get moved to S3 because after this the process will likely die
thread.join()

running_script_publish(f"cmd-running-script-channel:{RunningScript.id}", "shutdown")
running_script_publish(
f"cmd-running-script-channel:{RunningScript.id}", "shutdown"
)

def mark_breakpoint(self):
self.state = "breakpoint"
Expand All @@ -944,7 +947,7 @@ def mark_breakpoint(self):
"filename": self.current_filename,
"line_no": self.current_line_number,
"state": self.state,
}
},
)

def run_thread_body(
Expand Down Expand Up @@ -1073,7 +1076,7 @@ def run_text(
"scope": self.scope,
"text": text,
"breakpoints": [],
}
},
)
RunningScript.run_thread = threading.Thread(
target=self.run_thread_body,
Expand Down Expand Up @@ -1192,7 +1195,7 @@ def load_file_into_script(self, filename):
"filename": filename,
"text": self.body,
"breakpoints": breakpoints,
}
},
)

def mark_breakpoints(self, filename):
Expand All @@ -1214,20 +1217,6 @@ def redirect_io(self):
Logger.stdout = True
Logger.level = Logger.INFO

# TODO: This is defined on 206 ... so this is not called
# def output_thread(self):
# RunningScript.cancel_output = False
# RunningScript.output_sleeper = Sleeper()
# while True:
# if RunningScript.cancel_output:
# break
# if (time.time() - self.output_time) > 5.0:
# self.handle_output_io()
# if RunningScript.cancel_output:
# break
# if RunningScript.output_sleeper.sleep(1.0):
# break


openc3.script.RUNNING_SCRIPT = RunningScript

Expand Down Expand Up @@ -1277,7 +1266,7 @@ def start(procedure_name):
"filename": procedure_name,
"text": text,
"breakpoints": breakpoints,
}
},
)
else:
# Retrieve file
Expand All @@ -1295,7 +1284,7 @@ def start(procedure_name):
"filename": procedure_name,
"text": text,
"breakpoints": breakpoints,
}
},
)

# Cache instrumentation into RAM
Expand All @@ -1312,7 +1301,7 @@ def start(procedure_name):
"type": "start",
"filename": procedure_name,
"active_scripts": len(running),
}
},
)
linecache.cache[path] = (
len(text),
Expand Down Expand Up @@ -1371,7 +1360,7 @@ def display_screen(target_name, screen_name, x=None, y=None, scope=OPENC3_SCOPE)
"definition": definition,
"x": x,
"y": y,
}
},
)


Expand All @@ -1385,7 +1374,7 @@ def clear_screen(target_name, screen_name):
"type": "clearscreen",
"target_name": target_name,
"screen_name": screen_name,
}
},
)


Expand All @@ -1412,7 +1401,7 @@ def local_screen(screen_name, definition, x=None, y=None):
"definition": definition,
"x": x,
"y": y,
}
},
)


Expand All @@ -1423,7 +1412,7 @@ def download_file(path, scope=OPENC3_SCOPE):
url = openc3.script._get_download_url(path, scope=scope)
running_script_anycable_publish(
f"running-script-channel:{RunningScript.instance.id}",
{"type": "downloadfile", "filename": os.path.basename(path), "url": url}
{"type": "downloadfile", "filename": os.path.basename(path), "url": url},
)


Expand Down
2 changes: 1 addition & 1 deletion openc3/python/openc3/packets/telemetry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 OpenC3, Inc.
# Copyright 2025 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
Expand Down
18 changes: 13 additions & 5 deletions openc3/python/openc3/script/suite.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 OpenC3, Inc.
# Copyright 2025 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
Expand Down Expand Up @@ -48,31 +48,39 @@ def plans(self):
# Add a group to the suite
def add_group(self, group_class):
if not issubclass(group_class, Group):
raise RuntimeError(f"add_group received with {group_class}({group_class.__class__}) but must subclass Group")
raise RuntimeError(
f"add_group received with {group_class}({group_class.__class__}) but must subclass Group"
)
if not self.scripts().get(group_class, None):
self.scripts()[group_class] = group_class()
self.plans().append(["GROUP", group_class, None])

# Add a script to the suite
def add_script(self, group_class, script):
if not issubclass(group_class, Group):
raise RuntimeError(f"add_script received with {group_class}({group_class.__class__}) but must subclass Group")
raise RuntimeError(
f"add_script received with {group_class}({group_class.__class__}) but must subclass Group"
)
if not self.scripts().get(group_class, None):
self.scripts()[group_class] = group_class()
self.plans().append(["SCRIPT", group_class, script])

# Add a group setup to the suite
def add_group_setup(self, group_class):
if not issubclass(group_class, Group):
raise RuntimeError(f"add_group_setup received with {group_class}({group_class.__class__}) but must subclass Group")
raise RuntimeError(
f"add_group_setup received with {group_class}({group_class.__class__}) but must subclass Group"
)
if not self.scripts().get(group_class, None):
self.scripts()[group_class] = group_class()
self.plans().append(["GROUP_SETUP", group_class, None])

# Add a group teardown to the suite
def add_group_teardown(self, group_class):
if not issubclass(group_class, Group):
raise RuntimeError(f"add_group_teardown received with {group_class}({group_class.__class__}) but must subclass Group")
raise RuntimeError(
f"add_group_teardown received with {group_class}({group_class.__class__}) but must subclass Group"
)
if not self.scripts().get(group_class, None):
self.scripts()[group_class] = group_class()
self.plans().append(["GROUP_TEARDOWN", group_class, None])
Expand Down
Loading

0 comments on commit 9fdad3c

Please sign in to comment.