Skip to content

Commit

Permalink
Move openc3_script_sleep and fix wait() in python
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Dec 24, 2023
1 parent dd13990 commit ff55a0e
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 27 deletions.
7 changes: 4 additions & 3 deletions openc3-cosmos-script-runner-api/scripts/running_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


# sleep in a script - returns true if canceled mid sleep
def openc3_script_sleep(sleep_time=None):
def _openc3_script_sleep(sleep_time=None):
if RunningScript.disconnect:
return True

Expand Down Expand Up @@ -73,11 +73,12 @@ def openc3_script_sleep(sleep_time=None):
return False


openc3.utilities.script_shared.openc3_script_sleep = openc3_script_sleep
import openc3.script.api_shared

setattr(openc3.script.api_shared, "openc3_script_sleep", _openc3_script_sleep)

import os
from io import StringIO
from inspect import getsourcefile
import ast
import json
import uuid
Expand Down
11 changes: 11 additions & 0 deletions openc3/lib/openc3/script/api_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,17 @@ def require_utility(procedure_name)
# Private implementation details
###########################################################################

# This must be here for custom microservices that might block.
# Overriden by running_script.rb for script sleep
def openc3_script_sleep(sleep_time = nil)
if sleep_time
sleep(sleep_time)
else
prompt("Press any key to continue...")
end
return false
end

# Creates a string with the parameters upcased
def _upcase(target_name, packet_name, item_name)
"#{target_name.upcase} #{packet_name.upcase} #{item_name.upcase}"
Expand Down
10 changes: 0 additions & 10 deletions openc3/lib/openc3/script/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,6 @@ def shutdown_script
$script_runner_api_server = nil
end

# This isn't part of the public API because users should use wait()
def openc3_script_sleep(sleep_time = nil)
if sleep_time
sleep(sleep_time)
else
prompt("Press any key to continue...")
end
return false
end

# Internal method used in scripts when encountering a hazardous command
def prompt_for_hazardous(target_name, cmd_name, hazardous_description)
loop do
Expand Down
23 changes: 23 additions & 0 deletions openc3/python/openc3/script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ def disconnect_script():

# TODO: Add public apis equivalent from ruby script.rb


def prompt(
string,
text_color: None,
background_color: None,
font_size: None,
font_family: None,
details: None,
):
print(f"{string}: ")
if details:
print(f"Details: {details}\n")
return input()


def step_mode():
pass


def run_mode():
pass


###########################################################################
# END PUBLIC API
###########################################################################
Expand Down
17 changes: 12 additions & 5 deletions openc3/python/openc3/script/api_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

import sys
import time

from contextlib import contextmanager
import openc3.script
from openc3.utilities.script_shared import openc3_script_sleep
from .telemetry import *
from .exceptions import CheckError
from openc3.utilities.extract import *
from openc3.environment import *
from openc3.utilities.extract import (
extract_fields_from_check_text,
extract_fields_from_tlm_text,
)
from openc3.environment import OPENC3_SCOPE

DEFAULT_TLM_POLLING_RATE = 0.25

Expand Down Expand Up @@ -635,6 +635,13 @@ def get_max_output():
###########################################################################


def openc3_script_sleep(sleep_time=None):
if sleep_time:
time.sleep(float(sleep_time))
else:
input("Press any key to continue...")


def _upcase(target_name, packet_name, item_name):
"""Creates a string with the parameters upcased"""
return f"{target_name.upper()} {packet_name.upper()} {item_name.upper()}"
Expand Down
2 changes: 1 addition & 1 deletion openc3/python/openc3/script/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import time
import openc3.script
from openc3.utilities.script_shared import openc3_script_sleep
from openc3.script.api_shared import openc3_script_sleep
from openc3.environment import OPENC3_SCOPE


Expand Down
8 changes: 0 additions & 8 deletions openc3/python/openc3/utilities/script_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

import time


# Defined here but overriden by running_script.py
def openc3_script_sleep(sleep_time=None):
if sleep_time:
time.sleep(float(sleep_time))


def prompt_for_hazardous(target_name, cmd_name, hazardous_description):
""" """
Expand Down

0 comments on commit ff55a0e

Please sign in to comment.