-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1850 from OpenC3/tbl_mgr_api
Create table APIs
- Loading branch information
Showing
9 changed files
with
194 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# encoding: ascii-8bit | ||
|
||
# Copyright 2025 OpenC3, Inc. | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can modify and/or redistribute it | ||
# under the terms of the GNU Affero General Public License | ||
# as published by the Free Software Foundation; version 3 with | ||
# attribution addendums as found in the LICENSE.txt | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
|
||
# This file may also be used under the terms of a commercial license | ||
# if purchased from OpenC3, Inc. | ||
|
||
module OpenC3 | ||
module Script | ||
private | ||
|
||
def table_create_binary(definition, scope: $openc3_scope) | ||
post_data = {} | ||
post_data['definition'] = definition | ||
response = $api_server.request('post', '/openc3-api/tables/generate', json: true, data: post_data, scope: scope) | ||
return _handle_response(response, 'Failed to create binary') | ||
end | ||
|
||
def table_create_report(filename, definition, table_name: nil, scope: $openc3_scope) | ||
post_data = {} | ||
post_data['binary'] = filename | ||
post_data['definition'] = definition | ||
post_data['table_name'] = table_name if table_name | ||
response = $api_server.request('post', '/openc3-api/tables/report', json: true, data: post_data, scope: scope) | ||
return _handle_response(response, 'Failed to create report') | ||
end | ||
|
||
# Helper method to handle the response | ||
def _handle_response(response, error_message) | ||
return nil if response.nil? | ||
if response.status >= 400 | ||
result = JSON.parse(response.body, :allow_nan => true, :create_additions => true) | ||
raise "#{error_message} due to #{result['message']}" | ||
end | ||
return JSON.parse(response.body, :allow_nan => true, :create_additions => true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright 2025 OpenC3, Inc. | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can modify and/or redistribute it | ||
# under the terms of the GNU Affero General Public License | ||
# as published by the Free Software Foundation; version 3 with | ||
# attribution addendums as found in the LICENSE.txt | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# This file may also be used under the terms of a commercial license | ||
# if purchased from OpenC3, Inc. | ||
|
||
import json | ||
import openc3.script | ||
from openc3.environment import OPENC3_SCOPE | ||
|
||
def table_create_binary(definition: str, scope: str = OPENC3_SCOPE): | ||
data = {} | ||
data['definition'] = definition | ||
response = openc3.script.API_SERVER.request("post", "/openc3-api/tables/generate", data=data, json=True, scope=scope) | ||
return _handle_response(response, 'Failed to create binary') | ||
|
||
def table_create_report(filename: str, definition: str, table_name: str = None, scope: str = OPENC3_SCOPE): | ||
data = {} | ||
data['binary'] = filename | ||
data['definition'] = definition | ||
if table_name: | ||
data['table_name'] = table_name | ||
response = openc3.script.API_SERVER.request("post", "/openc3-api/tables/report", data=data, json=True, scope=scope) | ||
return _handle_response(response, 'Failed to create binary') | ||
|
||
# Helper method to handle the response | ||
def _handle_response(response, error_message): | ||
if response is None: | ||
return None | ||
if response.status_code >= 400: | ||
result = json.loads(response.text) | ||
raise RuntimeError(f"{error_message} due to {result['message']}") | ||
# Not sure why the response body is empty (on delete) but check for that | ||
if response.text is None or len(response.text) == 0: | ||
return None | ||
else: | ||
return json.loads(response.text) |