ActionStreamer 0.1.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- actionstreamer-0.1.11/ActionStreamer/CommonFunctions/CommonFunctions.py +212 -0
- actionstreamer-0.1.11/ActionStreamer/CommonFunctions/Wifi/Wifi.py +93 -0
- actionstreamer-0.1.11/ActionStreamer/CommonFunctions/Wifi/__init__.py +4 -0
- actionstreamer-0.1.11/ActionStreamer/CommonFunctions/__init__.py +4 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/API/API.py +93 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/API/__init__.py +4 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/Config/Config.py +78 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/Config/__init__.py +4 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/Device/Device.py +57 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/Device/__init__.py +4 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/Event/Event.py +142 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/Event/__init__.py +4 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/File/File.py +92 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/File/__init__.py +4 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/Health/Health.py +72 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/Health/__init__.py +4 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/LogMessage/LogMessage.py +35 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/Patch/Patch.py +14 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/Patch/__init__.py +4 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/VideoClip/VideoClip.py +78 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/VideoClip/__init__.py +4 -0
- actionstreamer-0.1.11/ActionStreamer/WebService/__init__.py +11 -0
- actionstreamer-0.1.11/ActionStreamer/__init__.py +4 -0
- actionstreamer-0.1.11/PKG-INFO +17 -0
- actionstreamer-0.1.11/README.md +3 -0
- actionstreamer-0.1.11/pyproject.toml +14 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import hashlib
|
|
3
|
+
import hmac
|
|
4
|
+
import uuid
|
|
5
|
+
import time
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
|
|
8
|
+
import pytz
|
|
9
|
+
import requests
|
|
10
|
+
class StandardResult:
|
|
11
|
+
|
|
12
|
+
def __init__(self, code, description):
|
|
13
|
+
self.Code = code
|
|
14
|
+
self.Description = description
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class switch(object):
|
|
18
|
+
|
|
19
|
+
def __init__(self, value):
|
|
20
|
+
self.value = value
|
|
21
|
+
self.fall = False
|
|
22
|
+
|
|
23
|
+
def __iter__(self):
|
|
24
|
+
"""Return the match method once, then stop"""
|
|
25
|
+
yield self.match
|
|
26
|
+
raise StopIteration
|
|
27
|
+
|
|
28
|
+
def match(self, *args):
|
|
29
|
+
"""Indicate whether or not to enter a case suite"""
|
|
30
|
+
if self.fall or not args:
|
|
31
|
+
return True
|
|
32
|
+
elif self.value in args:
|
|
33
|
+
self.fall = True
|
|
34
|
+
return True
|
|
35
|
+
else:
|
|
36
|
+
return False
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_exception_info():
|
|
40
|
+
exception_type, exception_object, exception_traceback = sys.exc_info()
|
|
41
|
+
if exception_traceback is not None:
|
|
42
|
+
filename = exception_traceback.tb_frame.f_code.co_filename
|
|
43
|
+
line_number = exception_traceback.tb_lineno
|
|
44
|
+
return filename, line_number
|
|
45
|
+
return None, None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def get_line_number():
|
|
49
|
+
exception_type, exception_object, exception_traceback = sys.exc_info()
|
|
50
|
+
if exception_traceback is not None:
|
|
51
|
+
return exception_traceback.tb_lineno
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def log_to_console(message, agent_name=''):
|
|
56
|
+
# Get the current UTC time
|
|
57
|
+
utc_now = datetime.now(pytz.utc)
|
|
58
|
+
|
|
59
|
+
# Format the UTC time
|
|
60
|
+
utc_time_formatted = utc_now.strftime("%Y-%m-%d %H:%M:%S UTC")
|
|
61
|
+
|
|
62
|
+
# Prepend the formatted UTC time to the string
|
|
63
|
+
if (agent_name):
|
|
64
|
+
result_string = f"[{utc_time_formatted}]: [{agent_name}]: {message}"
|
|
65
|
+
else:
|
|
66
|
+
result_string = f"[{utc_time_formatted}]: {message}"
|
|
67
|
+
|
|
68
|
+
# Print the result to standard output
|
|
69
|
+
print(result_string)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def send_signed_request(ws_config, method, url, path, headers={"Content-Type": "application/json"}, parameters=None, body=None):
|
|
73
|
+
|
|
74
|
+
try:
|
|
75
|
+
|
|
76
|
+
if headers is None:
|
|
77
|
+
headers = {}
|
|
78
|
+
elif isinstance(headers,str):
|
|
79
|
+
headers = dict(header.strip().split(':', 1) for header in headers.split('\n'))
|
|
80
|
+
|
|
81
|
+
nonce = str(uuid.uuid4())
|
|
82
|
+
timestamp = str(int(time.time()))
|
|
83
|
+
|
|
84
|
+
headers['X-Nonce'] = nonce
|
|
85
|
+
headers['X-Timestamp'] = timestamp
|
|
86
|
+
headers['Authorization'] = 'HMAC-SHA256 ' + ws_config.access_key
|
|
87
|
+
headers['X-AccessKey'] = ws_config.access_key
|
|
88
|
+
|
|
89
|
+
# Generate HMAC signature
|
|
90
|
+
signature = get_hmac_signature(ws_config.secret_key, method, path, headers, parameters, body)
|
|
91
|
+
|
|
92
|
+
# Include signature in headers
|
|
93
|
+
headers['X-Signature'] = signature
|
|
94
|
+
|
|
95
|
+
verify = True
|
|
96
|
+
if ws_config.ignore_ssl:
|
|
97
|
+
verify = False
|
|
98
|
+
else:
|
|
99
|
+
verify = True
|
|
100
|
+
|
|
101
|
+
response = requests.post(url, headers=headers, data=body, verify=verify, timeout=ws_config.timeout)
|
|
102
|
+
status_code = response.status_code
|
|
103
|
+
response_string = response.content.decode('utf-8')
|
|
104
|
+
|
|
105
|
+
if status_code == 200:
|
|
106
|
+
bRetry = False
|
|
107
|
+
else:
|
|
108
|
+
time.sleep(3)
|
|
109
|
+
|
|
110
|
+
except Exception as ex:
|
|
111
|
+
filename, line_number = get_exception_info()
|
|
112
|
+
if filename is not None and line_number is not None:
|
|
113
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
114
|
+
print(ex)
|
|
115
|
+
status_code = -1
|
|
116
|
+
response_string = "Error in send_signed_request"
|
|
117
|
+
|
|
118
|
+
return status_code, response_string
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def get_hmac_signature(secret_key, method, path, headers, parameters, body=None):
|
|
122
|
+
|
|
123
|
+
try:
|
|
124
|
+
if 'Content-Type' in headers:
|
|
125
|
+
del headers['Content-Type']
|
|
126
|
+
|
|
127
|
+
headerString = dictionary_to_string(headers)
|
|
128
|
+
parameterString = dictionary_to_string(parameters)
|
|
129
|
+
|
|
130
|
+
# Path should be in the format /v1/event
|
|
131
|
+
if not path.startswith('/'):
|
|
132
|
+
path = '/' + path
|
|
133
|
+
|
|
134
|
+
if path.endswith('/') and len(path) > 1:
|
|
135
|
+
path = path[:-1]
|
|
136
|
+
|
|
137
|
+
string_to_sign = '\n'.join([method, path, headerString, parameterString, body if body else ''])
|
|
138
|
+
|
|
139
|
+
string_to_sign = string_to_sign.strip()
|
|
140
|
+
log_to_console("stringToSign: " + string_to_sign)
|
|
141
|
+
|
|
142
|
+
# Generate the HMAC SHA256 signature
|
|
143
|
+
hmac_signature = hmac.new(secret_key.encode('utf-8'), string_to_sign.encode('utf-8'), hashlib.sha256)
|
|
144
|
+
|
|
145
|
+
# Convert the HMAC signature to hexadecimal
|
|
146
|
+
return hmac_signature.hexdigest(), string_to_sign
|
|
147
|
+
|
|
148
|
+
except Exception as ex:
|
|
149
|
+
filename, line_number = get_exception_info()
|
|
150
|
+
if filename is not None and line_number is not None:
|
|
151
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
152
|
+
print(ex)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def dictionary_to_string(dictionary):
|
|
156
|
+
|
|
157
|
+
result = ''
|
|
158
|
+
|
|
159
|
+
try:
|
|
160
|
+
sorted_keys = sorted(dictionary.keys())
|
|
161
|
+
|
|
162
|
+
for key in sorted_keys:
|
|
163
|
+
result += f"{key}: {dictionary[key]}\n"
|
|
164
|
+
|
|
165
|
+
except Exception as ex:
|
|
166
|
+
filename, line_number = get_exception_info()
|
|
167
|
+
#if filename is not None and line_number is not None:
|
|
168
|
+
#print(f"Exception occurred at line {line_number} in {filename}")
|
|
169
|
+
#print(ex)
|
|
170
|
+
|
|
171
|
+
return result
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def upload_file_to_s3(file_path, signed_url):
|
|
175
|
+
|
|
176
|
+
retry = True
|
|
177
|
+
result = 0
|
|
178
|
+
|
|
179
|
+
while retry:
|
|
180
|
+
|
|
181
|
+
try:
|
|
182
|
+
with open(file_path, 'rb') as file:
|
|
183
|
+
response = requests.put(signed_url, data=file)
|
|
184
|
+
|
|
185
|
+
if response.status_code == 200:
|
|
186
|
+
retry = False
|
|
187
|
+
result = 0
|
|
188
|
+
else:
|
|
189
|
+
print(f"Error uploading file to S3. Status code: {response.status_code}")
|
|
190
|
+
result = -1
|
|
191
|
+
|
|
192
|
+
except Exception as ex:
|
|
193
|
+
print("Exception occurred while uploading file to S3:", str(ex))
|
|
194
|
+
result = -2
|
|
195
|
+
|
|
196
|
+
return result
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def get_sha256_hash_for_file(file_path):
|
|
200
|
+
# Initialize the hash object (SHA-256 is used in this example)
|
|
201
|
+
hash_object = hashlib.sha256()
|
|
202
|
+
|
|
203
|
+
# Open the file in binary mode to read its contents
|
|
204
|
+
with open(file_path, "rb") as file:
|
|
205
|
+
# Read the file in chunks to avoid loading the entire file into memory
|
|
206
|
+
for chunk in iter(lambda: file.read(4096), b""):
|
|
207
|
+
hash_object.update(chunk)
|
|
208
|
+
|
|
209
|
+
# Get the hexadecimal representation of the hash
|
|
210
|
+
file_hash = hash_object.hexdigest()
|
|
211
|
+
|
|
212
|
+
return file_hash
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import subprocess
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def add_wifi_connection(ssid, password, connection_name, priority=1):
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
subprocess.run(['sudo', 'nmcli', 'connection', 'add', 'type', 'wifi', 'ifname', 'wlan0', 'con-name', connection_name, 'ssid', ssid, 'connection.autoconnect-priority', str(priority)], check=True)
|
|
9
|
+
subprocess.run(['sudo', 'nmcli', 'connection', 'modify', connection_name, 'wifi-sec.key-mgmt', 'wpa-psk'], check=True)
|
|
10
|
+
subprocess.run(['sudo', 'nmcli', 'connection', 'modify', connection_name, 'wifi-sec.psk', password], check=True)
|
|
11
|
+
|
|
12
|
+
# Activate the connection
|
|
13
|
+
subprocess.run(['sudo', 'nmcli', 'connection', 'up', connection_name], check=True)
|
|
14
|
+
#print(f"Added and activated new connection: {connection_name}")
|
|
15
|
+
|
|
16
|
+
except subprocess.CalledProcessError as ex:
|
|
17
|
+
print(f"Failed to add connection: {connection_name}. Error: {ex}")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def remove_wifi_connection(ssid):
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
subprocess.run(['sudo', 'nmcli', 'connection', 'delete', ssid], check=True)
|
|
24
|
+
print(f"Removed existing connection: {ssid}")
|
|
25
|
+
except subprocess.CalledProcessError as ex:
|
|
26
|
+
print(f"Failed to remove connection: {ssid}. It might not exist.")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def set_wifi_priority(ssid, priority):
|
|
30
|
+
|
|
31
|
+
# Example usage:
|
|
32
|
+
# set_wifi_priority("YourSSID", 100)
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
# Get the UUID of the connection
|
|
36
|
+
result = subprocess.run(
|
|
37
|
+
['nmcli', '-g', 'uuid', 'connection', 'show', ssid],
|
|
38
|
+
capture_output=True, text=True, check=True
|
|
39
|
+
)
|
|
40
|
+
uuid = result.stdout.strip()
|
|
41
|
+
|
|
42
|
+
if not uuid:
|
|
43
|
+
raise ValueError(f"Connection {ssid} not found.")
|
|
44
|
+
|
|
45
|
+
# Set the autoconnect priority
|
|
46
|
+
subprocess.run(
|
|
47
|
+
['nmcli', 'connection', 'modify', uuid, 'connection.autoconnect-priority', str(priority)],
|
|
48
|
+
check=True
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# Restart Network Manager to apply the changes
|
|
52
|
+
subprocess.run(['sudo', 'systemctl', 'restart', 'NetworkManager'], check=True)
|
|
53
|
+
|
|
54
|
+
print(f"Priority for {ssid} set to {priority}.")
|
|
55
|
+
|
|
56
|
+
except subprocess.CalledProcessError as ex:
|
|
57
|
+
print(f"An error occurred while running nmcli: {ex}")
|
|
58
|
+
|
|
59
|
+
except ValueError as ex:
|
|
60
|
+
print(ex)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def back_up_connections(backup_file_path):
|
|
64
|
+
# Backup all connection data to a JSON file
|
|
65
|
+
try:
|
|
66
|
+
result = subprocess.run(['sudo', 'nmcli', '--json', 'connection', 'export'], capture_output=True, text=True, check=True)
|
|
67
|
+
connections_data = json.loads(result.stdout)
|
|
68
|
+
|
|
69
|
+
with open(backup_file_path, 'w') as f:
|
|
70
|
+
json.dump(connections_data, f, indent=4)
|
|
71
|
+
|
|
72
|
+
print(f"Connections backed up to {backup_file_path}.")
|
|
73
|
+
|
|
74
|
+
except subprocess.CalledProcessError as ex:
|
|
75
|
+
print(f"Failed to backup connections. Error: {ex}")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def restore_connections(backup_file_path):
|
|
79
|
+
# Restore all connections from a JSON backup file
|
|
80
|
+
try:
|
|
81
|
+
with open(backup_file_path, 'r') as f:
|
|
82
|
+
connections_data = json.load(f)
|
|
83
|
+
|
|
84
|
+
subprocess.run(['sudo', 'nmcli', 'connection', 'delete', 'id', 'all'], check=True)
|
|
85
|
+
|
|
86
|
+
for connection in connections_data:
|
|
87
|
+
subprocess.run(['sudo', 'nmcli', 'connection', 'import', 'json', json.dumps(connection)], check=True)
|
|
88
|
+
|
|
89
|
+
print(f"Connections restored from {backup_file_path}.")
|
|
90
|
+
|
|
91
|
+
except (subprocess.CalledProcessError, json.JSONDecodeError) as ex:
|
|
92
|
+
print(f"Failed to restore connections. Error: {ex}")
|
|
93
|
+
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
from .CommonFunctions import StandardResult, switch, get_exception_info, get_line_number, log_to_console, send_signed_request, get_hmac_signature, dictionary_to_string, upload_file_to_s3, get_sha256_hash_for_file
|
|
2
|
+
from . import Wifi
|
|
3
|
+
|
|
4
|
+
__all__ = ['StandardResult', 'switch', 'get_exception_info', 'get_line_number', 'log_to_console', 'send_signed_request', 'get_hmac_signature', 'dictionary_to_string', 'upload_file_to_s3', 'get_sha256_hash_for_file', 'Wifi']
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import json
|
|
3
|
+
from json import JSONEncoder
|
|
4
|
+
|
|
5
|
+
import ActionStreamer
|
|
6
|
+
from ActionStreamer import CommonFunctions
|
|
7
|
+
|
|
8
|
+
class WebServiceConfig:
|
|
9
|
+
|
|
10
|
+
"""
|
|
11
|
+
Configuration for connecting to the web service.
|
|
12
|
+
|
|
13
|
+
Attributes:
|
|
14
|
+
access_key (str): The access key for authentication.
|
|
15
|
+
secret_key (str): The secret key for authentication.
|
|
16
|
+
base_url (str): The base URL of the web service.
|
|
17
|
+
timeout (int): The timeout for requests in seconds.
|
|
18
|
+
ignore_ssl (bool): Whether to ignore SSL verification.
|
|
19
|
+
"""
|
|
20
|
+
def __init__(self, access_key: str, secret_key: str, base_url: str, timeout: int = 30, ignore_ssl: bool = False):
|
|
21
|
+
"""
|
|
22
|
+
Initialize the WebServiceConfig.
|
|
23
|
+
|
|
24
|
+
:param access_key: The access key for authentication.
|
|
25
|
+
:param secret_key: The secret key for authentication.
|
|
26
|
+
:param base_url: The base URL of the web service.
|
|
27
|
+
:param timeout: The timeout for requests in seconds (default is 30).
|
|
28
|
+
:param ignore_ssl: Whether to ignore SSL verification (default is False).
|
|
29
|
+
"""
|
|
30
|
+
self.access_key = access_key
|
|
31
|
+
self.secret_key = secret_key
|
|
32
|
+
self.base_url = base_url
|
|
33
|
+
self.timeout = timeout
|
|
34
|
+
self.ignore_ssl = ignore_ssl
|
|
35
|
+
|
|
36
|
+
class LogConfig:
|
|
37
|
+
|
|
38
|
+
def __init__(self, ws_config, device_name, agent_type, agent_version, agent_index, process_id):
|
|
39
|
+
self.ws_config = ws_config
|
|
40
|
+
self.device_name = device_name
|
|
41
|
+
self.agent_type = agent_type
|
|
42
|
+
self.agent_version = agent_version
|
|
43
|
+
self.agent_index = agent_index
|
|
44
|
+
self.process_id = process_id
|
|
45
|
+
|
|
46
|
+
class PatchOperation:
|
|
47
|
+
|
|
48
|
+
def __init__(self, field_name, value):
|
|
49
|
+
self.field_name = field_name
|
|
50
|
+
self.value = value
|
|
51
|
+
|
|
52
|
+
class WebServiceResult:
|
|
53
|
+
|
|
54
|
+
def __init__(self, code, description, http_response_code, http_response_string, json_data):
|
|
55
|
+
self.Code = code
|
|
56
|
+
self.Description = description
|
|
57
|
+
self.HttpResponseCode = http_response_code
|
|
58
|
+
self.HttpResponseString = http_response_string
|
|
59
|
+
self.JsonData = json_data
|
|
60
|
+
|
|
61
|
+
class DateTimeEncoder(JSONEncoder):
|
|
62
|
+
|
|
63
|
+
# Override the default method
|
|
64
|
+
def default(self, obj):
|
|
65
|
+
if isinstance(obj, (datetime.date, datetime.datetime)):
|
|
66
|
+
return obj.isoformat()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def register_agent(ws_config, device_name, agent_type, agent_version, agent_index, process_id):
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
jsonPostData = {"deviceName":device_name, "agentType":agent_type, "agentVersion":agent_version, "agentIndex":agent_index, "processID":process_id}
|
|
73
|
+
|
|
74
|
+
method = "POST"
|
|
75
|
+
path = 'v1/agent'
|
|
76
|
+
url = ws_config.base_url + path
|
|
77
|
+
headers = {"Content-Type": "application/json"}
|
|
78
|
+
parameters = ''
|
|
79
|
+
body = json.dumps(jsonPostData)
|
|
80
|
+
|
|
81
|
+
response_code, response_string = CommonFunctions.send_signed_request(ws_config, method, url, path, headers, parameters, body)
|
|
82
|
+
|
|
83
|
+
except Exception as ex:
|
|
84
|
+
|
|
85
|
+
filename, line_number = CommonFunctions.get_exception_info()
|
|
86
|
+
if filename is not None and line_number is not None:
|
|
87
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
88
|
+
print(ex)
|
|
89
|
+
|
|
90
|
+
response_code = -1
|
|
91
|
+
response_string = "Exception in RegisterAgent"
|
|
92
|
+
|
|
93
|
+
return response_code, response_string
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import platform
|
|
3
|
+
|
|
4
|
+
def is_windows():
|
|
5
|
+
return platform.system() == 'Windows'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_config_folder_path(app_name):
|
|
9
|
+
|
|
10
|
+
if is_windows():
|
|
11
|
+
username = os.getlogin()
|
|
12
|
+
config_dir = os.path.join('C:\\Users', username, 'AppData', 'Roaming', app_name, "config")
|
|
13
|
+
# If the Python debugger is running, the path will be in something like:
|
|
14
|
+
# C:\Users\Username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\Roaming
|
|
15
|
+
|
|
16
|
+
else:
|
|
17
|
+
config_dir = os.path.expanduser(os.path.join("~", ".config", app_name))
|
|
18
|
+
|
|
19
|
+
# Create the directory if it doesn't exist
|
|
20
|
+
if not os.path.exists(config_dir):
|
|
21
|
+
os.makedirs(config_dir)
|
|
22
|
+
|
|
23
|
+
return config_dir
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def get_appdata_folder_path(app_name):
|
|
27
|
+
|
|
28
|
+
if is_windows():
|
|
29
|
+
username = os.getlogin()
|
|
30
|
+
appdata_folder_path = os.path.join('C:\\Users', username, 'AppData', 'Roaming', app_name)
|
|
31
|
+
# If the Python debugger is running, the path will be in something like:
|
|
32
|
+
# C:\Users\Username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\Roaming
|
|
33
|
+
else:
|
|
34
|
+
appdata_folder_path = os.path.expanduser(os.path.join("~", ".appdata", app_name))
|
|
35
|
+
|
|
36
|
+
# Create the directory if it doesn't exist
|
|
37
|
+
if not os.path.exists(appdata_folder_path):
|
|
38
|
+
os.makedirs(appdata_folder_path)
|
|
39
|
+
|
|
40
|
+
return appdata_folder_path
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def get_config_value(config_folder_path, name):
|
|
44
|
+
|
|
45
|
+
if not os.path.exists(config_folder_path):
|
|
46
|
+
os.makedirs(config_folder_path)
|
|
47
|
+
|
|
48
|
+
file_path = os.path.join(config_folder_path, name + '.txt')
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
with open(file_path, 'r') as file:
|
|
52
|
+
contents = file.read()
|
|
53
|
+
return contents
|
|
54
|
+
except FileNotFoundError:
|
|
55
|
+
print(f"File '{name}' not found in the specified folder '{config_folder_path}'")
|
|
56
|
+
return None
|
|
57
|
+
except Exception as ex:
|
|
58
|
+
print(f"Error occurred while reading '{name}': {ex}")
|
|
59
|
+
return None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def set_config_value(config_folder_path, name, value):
|
|
63
|
+
|
|
64
|
+
if not os.path.exists(config_folder_path):
|
|
65
|
+
os.makedirs(config_folder_path)
|
|
66
|
+
|
|
67
|
+
# Create the directory if it doesn't exist
|
|
68
|
+
if not os.path.exists(config_folder_path):
|
|
69
|
+
os.makedirs(config_folder_path)
|
|
70
|
+
|
|
71
|
+
file_path = os.path.join(config_folder_path, name + '.txt')
|
|
72
|
+
|
|
73
|
+
try:
|
|
74
|
+
with open(file_path, 'w') as file:
|
|
75
|
+
file.write(value)
|
|
76
|
+
print(f"Successfully set the value in '{name}'")
|
|
77
|
+
except Exception as ex:
|
|
78
|
+
print(f"Error occurred while setting value in '{name}': {ex}")
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import getopt
|
|
2
|
+
import socket
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def process_cpuinfo():
|
|
7
|
+
|
|
8
|
+
device_name = "0000000000000000"
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
optlist, args = getopt.getopt(sys.argv[1:], 'm:')
|
|
12
|
+
|
|
13
|
+
except getopt.GetoptError as err:
|
|
14
|
+
# Print help information and exit:
|
|
15
|
+
print(str(err)) # This will print something like "option -a not recognized"
|
|
16
|
+
return device_name
|
|
17
|
+
|
|
18
|
+
for option, argument in optlist:
|
|
19
|
+
if option == "-m":
|
|
20
|
+
device_name = argument
|
|
21
|
+
|
|
22
|
+
return device_name
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_serial_number():
|
|
26
|
+
|
|
27
|
+
# Extract serial from cpuinfo file
|
|
28
|
+
cpu_serial = "0000000000000000"
|
|
29
|
+
cpu_serial = process_cpuinfo()
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
file = open('/proc/cpuinfo','r')
|
|
33
|
+
|
|
34
|
+
for line in file:
|
|
35
|
+
if line[0:6] == 'Serial':
|
|
36
|
+
cpu_serial = line[10:26]
|
|
37
|
+
|
|
38
|
+
file.close()
|
|
39
|
+
|
|
40
|
+
except:
|
|
41
|
+
cpu_serial = "ERROR000000000"
|
|
42
|
+
|
|
43
|
+
return cpu_serial
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def get_ip_address():
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
# Get the local hostname
|
|
50
|
+
hostname = socket.gethostname()
|
|
51
|
+
# Get the IP address associated with the hostname
|
|
52
|
+
ip_address = socket.gethostbyname(hostname)
|
|
53
|
+
except socket.error:
|
|
54
|
+
# If an error occurs, return a default IP address
|
|
55
|
+
ip_address = "0.0.0.0"
|
|
56
|
+
|
|
57
|
+
return ip_address
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import ActionStreamer
|
|
4
|
+
from ActionStreamer import CommonFunctions
|
|
5
|
+
from WebService.API import WebServiceResult
|
|
6
|
+
|
|
7
|
+
def dequeue_event(ws_config, device_name, agent_type):
|
|
8
|
+
|
|
9
|
+
ws_result = WebServiceResult(0, '', '', '', None)
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
method = "POST"
|
|
13
|
+
path = 'v1/event/dequeue'
|
|
14
|
+
url = ws_config.base_url + path
|
|
15
|
+
headers = {"Content-Type": "application/json"}
|
|
16
|
+
parameters = ''
|
|
17
|
+
|
|
18
|
+
json_post_data = {
|
|
19
|
+
"deviceName": device_name,
|
|
20
|
+
"agentType": agent_type
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
body = json.dumps(json_post_data)
|
|
24
|
+
|
|
25
|
+
response_code, response_string = CommonFunctions.send_signed_request(ws_config, method, url, path, headers, parameters, body)
|
|
26
|
+
|
|
27
|
+
ws_result.HttpResponseCode = response_code
|
|
28
|
+
ws_result.HttpResponseString = response_string
|
|
29
|
+
ws_result.JsonData = json.loads(response_string)
|
|
30
|
+
|
|
31
|
+
except Exception as ex:
|
|
32
|
+
ws_result.Code = -1
|
|
33
|
+
filename, line_number = CommonFunctions.get_exception_info()
|
|
34
|
+
if filename is not None and line_number is not None:
|
|
35
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
36
|
+
print(ex)
|
|
37
|
+
|
|
38
|
+
return ws_result
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def create_event(ws_config, device_name, agent_type, event_type, event_parameters, priority=1, max_attempts=0, expiration_date=None):
|
|
42
|
+
|
|
43
|
+
ws_result = WebServiceResult(0, '', '', '', None)
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
method = "POST"
|
|
47
|
+
path = 'v1/event'
|
|
48
|
+
url = ws_config.base_url + path
|
|
49
|
+
headers = {"Content-Type": "application/json"}
|
|
50
|
+
parameters = ''
|
|
51
|
+
|
|
52
|
+
json_post_data = {
|
|
53
|
+
"deviceName": device_name,
|
|
54
|
+
"agentType": agent_type,
|
|
55
|
+
"eventType": event_type,
|
|
56
|
+
"eventParameters": event_parameters,
|
|
57
|
+
"priority": priority,
|
|
58
|
+
"maxAttempts": max_attempts,
|
|
59
|
+
"expirationDate": expiration_date
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
body = json.dumps(json_post_data)
|
|
63
|
+
|
|
64
|
+
response_code, response_string = CommonFunctions.send_signed_request(ws_config, method, url, path, headers, parameters, body)
|
|
65
|
+
|
|
66
|
+
ws_result.HttpResponseCode = response_code
|
|
67
|
+
ws_result.HttpResponseString = response_string
|
|
68
|
+
ws_result.JsonData = json.loads(response_string)
|
|
69
|
+
|
|
70
|
+
except Exception as ex:
|
|
71
|
+
ws_result.Code = -1
|
|
72
|
+
filename, line_number = CommonFunctions.get_exception_info()
|
|
73
|
+
if filename is not None and line_number is not None:
|
|
74
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
75
|
+
print(ex)
|
|
76
|
+
|
|
77
|
+
return ws_result
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def get_event_details(ws_config, event_id):
|
|
81
|
+
|
|
82
|
+
ws_result = WebServiceResult(0, '', '', '', None)
|
|
83
|
+
|
|
84
|
+
try:
|
|
85
|
+
method = "GET"
|
|
86
|
+
path = 'v1/event/' + event_id
|
|
87
|
+
url = ws_config.base_url + path
|
|
88
|
+
parameters = ''
|
|
89
|
+
headers = {}
|
|
90
|
+
body = ''
|
|
91
|
+
|
|
92
|
+
response_code, response_string = CommonFunctions.send_signed_request(ws_config, method, url, path, headers, parameters, body)
|
|
93
|
+
|
|
94
|
+
ws_result.HttpResponseCode = response_code
|
|
95
|
+
ws_result.HttpResponseString = response_string
|
|
96
|
+
ws_result.JsonData = json.loads(response_string)
|
|
97
|
+
|
|
98
|
+
except Exception as ex:
|
|
99
|
+
ws_result.Code = -1
|
|
100
|
+
filename, line_number = CommonFunctions.get_exception_info()
|
|
101
|
+
if filename is not None and line_number is not None:
|
|
102
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
103
|
+
print(ex)
|
|
104
|
+
|
|
105
|
+
return ws_result
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def update_event(ws_config, event_id, event_status, result, tag_string='', tag_number=0, attempt_number=1):
|
|
109
|
+
|
|
110
|
+
ws_result = WebServiceResult(0, '', '', '', None)
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
method = "PUT"
|
|
114
|
+
path = 'v1/event' + event_id
|
|
115
|
+
url = ws_config.base_url + path
|
|
116
|
+
headers = {"Content-Type": "application/json"}
|
|
117
|
+
parameters = ''
|
|
118
|
+
|
|
119
|
+
json_post_data = {
|
|
120
|
+
"eventStatus": event_status,
|
|
121
|
+
"attemptNumber": attempt_number,
|
|
122
|
+
"result": result,
|
|
123
|
+
"tagString": tag_string,
|
|
124
|
+
"tagNumber": tag_number
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
body = json.dumps(json_post_data)
|
|
128
|
+
|
|
129
|
+
response_code, response_string = CommonFunctions.send_signed_request(ws_config, method, url, path, headers, parameters, body)
|
|
130
|
+
|
|
131
|
+
ws_result.HttpResponseCode = response_code
|
|
132
|
+
ws_result.HttpResponseString = response_string
|
|
133
|
+
ws_result.JsonData = json.loads(response_string)
|
|
134
|
+
|
|
135
|
+
except Exception as ex:
|
|
136
|
+
ws_result.Code = -1
|
|
137
|
+
filename, line_number = CommonFunctions.get_exception_info()
|
|
138
|
+
if filename is not None and line_number is not None:
|
|
139
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
140
|
+
print(ex)
|
|
141
|
+
|
|
142
|
+
return ws_result
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import ActionStreamer
|
|
4
|
+
from ActionStreamer import CommonFunctions
|
|
5
|
+
from ActionStreamer import API
|
|
6
|
+
import WebService.API
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def create_file(ws_config: ActionStreamer.API.WebServiceConfig, device_name: str, filename: str, file_size: int, sha256_hash: str) -> tuple[int, str, str, int]:
|
|
10
|
+
|
|
11
|
+
"""
|
|
12
|
+
Create a file.
|
|
13
|
+
|
|
14
|
+
Parameters:
|
|
15
|
+
ws_config (API.WebServiceConfig): The web service configuration.
|
|
16
|
+
device_name (string): The device name.
|
|
17
|
+
filename (string): The filename (no path information, just the name).
|
|
18
|
+
file_size (int): The file size in bytes.
|
|
19
|
+
sha256_hash (string): The SHA256 hash for the file.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
response_code: The API HTTP response code.
|
|
23
|
+
response_string: The API HTTP response body
|
|
24
|
+
signed_url: The URL to upload the file to.
|
|
25
|
+
file_id: The ID for the newly generated file.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
json_post_data = {"deviceName":device_name, "filename":filename, "fileSize":file_size, "sHA256Hash":sha256_hash}
|
|
30
|
+
|
|
31
|
+
method = "POST"
|
|
32
|
+
path = 'v1/file'
|
|
33
|
+
url = ws_config.base_url + path
|
|
34
|
+
headers = {"Content-Type": "application/json"}
|
|
35
|
+
parameters = ''
|
|
36
|
+
body = json.dumps(json_post_data)
|
|
37
|
+
|
|
38
|
+
response_code, response_string = CommonFunctions.send_signed_request(ws_config, method, url, path, headers, parameters, body)
|
|
39
|
+
|
|
40
|
+
signed_url = ''
|
|
41
|
+
file_id = 0
|
|
42
|
+
|
|
43
|
+
if (response_code == 200):
|
|
44
|
+
|
|
45
|
+
# This response should include signedURL, fileID
|
|
46
|
+
response_data = json.loads(response_string)
|
|
47
|
+
|
|
48
|
+
signed_url = response_data['signedURL']
|
|
49
|
+
file_id = response_data['fileID']
|
|
50
|
+
|
|
51
|
+
except Exception as ex:
|
|
52
|
+
|
|
53
|
+
filename, line_number = CommonFunctions.get_exception_info()
|
|
54
|
+
|
|
55
|
+
if filename is not None and line_number is not None:
|
|
56
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
57
|
+
print(ex)
|
|
58
|
+
|
|
59
|
+
response_code = -1
|
|
60
|
+
response_string = "Exception in create_file"
|
|
61
|
+
signed_url = ""
|
|
62
|
+
file_id = 0
|
|
63
|
+
|
|
64
|
+
return response_code, response_string, signed_url, file_id
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def update_file_upload_success(ws_config, device_name, file_id):
|
|
68
|
+
|
|
69
|
+
try:
|
|
70
|
+
json_post_data = {'deviceSerial':device_name}
|
|
71
|
+
|
|
72
|
+
method = "POST"
|
|
73
|
+
path = 'v1/file/success/' + str(file_id)
|
|
74
|
+
url = ws_config.base_url + path
|
|
75
|
+
headers = {"Content-Type": "application/json"}
|
|
76
|
+
parameters = ''
|
|
77
|
+
body = json.dumps(json_post_data)
|
|
78
|
+
|
|
79
|
+
response_code, response_string = CommonFunctions.send_signed_request(ws_config, method, url, path, headers, parameters, body)
|
|
80
|
+
|
|
81
|
+
except Exception as ex:
|
|
82
|
+
|
|
83
|
+
filename, line_number = CommonFunctions.get_exception_info()
|
|
84
|
+
if filename is not None and line_number is not None:
|
|
85
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
86
|
+
print(ex)
|
|
87
|
+
|
|
88
|
+
response_code = -1
|
|
89
|
+
response_string = "Exception in update_file_upload_success"
|
|
90
|
+
|
|
91
|
+
return response_code, response_string
|
|
92
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from WebService.API import WebServiceResult
|
|
4
|
+
from ActionStreamer import CommonFunctions
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def create_health(ws_config, device_name, health_json):
|
|
8
|
+
|
|
9
|
+
ws_result = WebServiceResult(0, '', '', '', None)
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
method = "POST"
|
|
13
|
+
path = 'v1/devicehealth'
|
|
14
|
+
url = ws_config.base_url + path
|
|
15
|
+
headers = {"Content-Type": "application/json"}
|
|
16
|
+
parameters = ''
|
|
17
|
+
|
|
18
|
+
json_post_data = {
|
|
19
|
+
"deviceName": device_name,
|
|
20
|
+
"healthJSON": health_json
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
body = json.dumps(json_post_data)
|
|
24
|
+
|
|
25
|
+
response_code, response_string = CommonFunctions.send_signed_request(ws_config, method, url, path, headers, parameters, body)
|
|
26
|
+
|
|
27
|
+
ws_result.HttpResponseCode = response_code
|
|
28
|
+
ws_result.HttpResponseString = response_string
|
|
29
|
+
ws_result.JsonData = json.loads(response_string)
|
|
30
|
+
|
|
31
|
+
except Exception as ex:
|
|
32
|
+
ws_result.Code = -1
|
|
33
|
+
filename, line_number = CommonFunctions.get_exception_info()
|
|
34
|
+
if filename is not None and line_number is not None:
|
|
35
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
36
|
+
print(ex)
|
|
37
|
+
|
|
38
|
+
return ws_result
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def update_health(ws_config, device_name, health_json):
|
|
42
|
+
|
|
43
|
+
ws_result = WebServiceResult(0, '', '', '', None)
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
method = "PUT"
|
|
47
|
+
path = 'v1/devicehealth'
|
|
48
|
+
url = ws_config.base_url + path
|
|
49
|
+
headers = {"Content-Type": "application/json"}
|
|
50
|
+
parameters = ''
|
|
51
|
+
|
|
52
|
+
json_post_data = {
|
|
53
|
+
"deviceName": device_name,
|
|
54
|
+
"healthJSON": health_json
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
body = json.dumps(json_post_data)
|
|
58
|
+
|
|
59
|
+
response_code, response_string = CommonFunctions.send_signed_request(ws_config, method, url, path, headers, parameters, body)
|
|
60
|
+
|
|
61
|
+
ws_result.HttpResponseCode = response_code
|
|
62
|
+
ws_result.HttpResponseString = response_string
|
|
63
|
+
ws_result.JsonData = json.loads(response_string)
|
|
64
|
+
|
|
65
|
+
except Exception as ex:
|
|
66
|
+
ws_result.Code = -1
|
|
67
|
+
filename, line_number = CommonFunctions.get_exception_info()
|
|
68
|
+
if filename is not None and line_number is not None:
|
|
69
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
70
|
+
print(ex)
|
|
71
|
+
|
|
72
|
+
return ws_result
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import CommonFunctions
|
|
2
|
+
import datetime
|
|
3
|
+
import json
|
|
4
|
+
from ActionStreamer import DateTimeEncoder
|
|
5
|
+
|
|
6
|
+
def CreateLogMessage(logConfig, strMessage, bLogToConsole=True):
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
if (bLogToConsole):
|
|
10
|
+
CommonFunctions.Log(strMessage, logConfig.agentName)
|
|
11
|
+
|
|
12
|
+
utc_now = datetime.datetime.now(datetime.timezone.utc)
|
|
13
|
+
jsonPostData = {"deviceSerial":logConfig.deviceSerial, "agentType":logConfig.agentType, "agentVersion":logConfig.agentVersion, "agentIndex":logConfig.agentIndex, "processID":logConfig.processID, "message":strMessage, "logDate": utc_now}
|
|
14
|
+
|
|
15
|
+
method = "POST"
|
|
16
|
+
path = 'v1/logmessage'
|
|
17
|
+
url = logConfig.wsConfig.base_url + path
|
|
18
|
+
headers = {"Content-Type": "application/json"}
|
|
19
|
+
parameters = ''
|
|
20
|
+
#body = json.dumps(jsonPostData)
|
|
21
|
+
body = json.dumps(jsonPostData, indent=4, cls=DateTimeEncoder)
|
|
22
|
+
|
|
23
|
+
intResponseCode, strResponse = CommonFunctions.send_signed_request(logConfig.wsConfig, method, url, path, headers, parameters, body)
|
|
24
|
+
|
|
25
|
+
except Exception as ex:
|
|
26
|
+
|
|
27
|
+
filename, line_number = CommonFunctions.get_exception_info()
|
|
28
|
+
if filename is not None and line_number is not None:
|
|
29
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
30
|
+
print(ex)
|
|
31
|
+
|
|
32
|
+
intResponseCode = -1
|
|
33
|
+
strResponse = "Exception in CreateLogMessage"
|
|
34
|
+
|
|
35
|
+
return intResponseCode, strResponse
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from WebService.API import PatchOperation
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def add_patch_operation(operations, field_name, value):
|
|
7
|
+
operations.append(PatchOperation(field_name, value))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def generate_patch_json(operations):
|
|
11
|
+
# Convert all values to strings
|
|
12
|
+
operations_str = [{k: str(v) for k, v in vars(op).items()} for op in operations]
|
|
13
|
+
json_data = json.dumps(operations_str)
|
|
14
|
+
return json_data
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from ActionStreamer import CommonFunctions
|
|
4
|
+
import WebService.API
|
|
5
|
+
import WebService.Config
|
|
6
|
+
import WebService.Patch
|
|
7
|
+
from Patch import *
|
|
8
|
+
|
|
9
|
+
class VideoClip:
|
|
10
|
+
|
|
11
|
+
def __init__(self, file_id=0, ts_file_id=0, video_clip_parameters='', local_file_path='', height=0, width=0, frames_per_second=0, audio_status=0, start_time=0, start_time_ms=0, end_time=0, end_time_ms=0, clip_length_in_seconds=0):
|
|
12
|
+
self.file_id = file_id
|
|
13
|
+
self.ts_file_id = ts_file_id
|
|
14
|
+
self.video_clip_parameters = video_clip_parameters
|
|
15
|
+
self.local_file_path = local_file_path
|
|
16
|
+
self.height = height
|
|
17
|
+
self.width = width
|
|
18
|
+
self.frames_per_second = frames_per_second
|
|
19
|
+
self.audio_status = audio_status
|
|
20
|
+
self.start_time = start_time
|
|
21
|
+
self.start_time_ms = start_time_ms
|
|
22
|
+
self.end_time = end_time
|
|
23
|
+
self.EndTimeMS = end_time_ms
|
|
24
|
+
self.ClipLengthInSeconds = clip_length_in_seconds
|
|
25
|
+
|
|
26
|
+
def create_video_clip(ws_config, device_name, video_clip):
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
method = "POST"
|
|
30
|
+
path = 'v1/videoclip/' + device_name
|
|
31
|
+
url = ws_config.base_url + path
|
|
32
|
+
headers = {"Content-Type": "application/json"}
|
|
33
|
+
parameters = ''
|
|
34
|
+
body = json.dumps(video_clip.__dict__)
|
|
35
|
+
|
|
36
|
+
ActionStreamer.Patch
|
|
37
|
+
|
|
38
|
+
response_code, response_string = CommonFunctions.send_signed_request(ws_config, method, url, path, headers, parameters, body)
|
|
39
|
+
|
|
40
|
+
except Exception as ex:
|
|
41
|
+
|
|
42
|
+
filename, line_number = CommonFunctions.get_exception_info()
|
|
43
|
+
if filename is not None and line_number is not None:
|
|
44
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
45
|
+
print(ex)
|
|
46
|
+
|
|
47
|
+
response_code = -1
|
|
48
|
+
response_string = "Exception in CreateVideoClip"
|
|
49
|
+
|
|
50
|
+
return response_code, response_string
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def update_file_id(ws_config, video_clip_id, file_id):
|
|
54
|
+
|
|
55
|
+
try:
|
|
56
|
+
operations_list = []
|
|
57
|
+
add_patch_operation(operations_list, "FileID", file_id)
|
|
58
|
+
|
|
59
|
+
method = "PATCH"
|
|
60
|
+
path = 'v1/videoclip/' + video_clip_id
|
|
61
|
+
url = ws_config.base_url + path
|
|
62
|
+
headers = {"Content-Type": "application/json"}
|
|
63
|
+
parameters = ''
|
|
64
|
+
body = generate_patch_json(operations_list)
|
|
65
|
+
|
|
66
|
+
response_code, response_code = CommonFunctions.send_signed_request(ws_config, method, url, path, headers, parameters, body)
|
|
67
|
+
|
|
68
|
+
except Exception as ex:
|
|
69
|
+
|
|
70
|
+
filename, line_number = CommonFunctions.get_exception_info()
|
|
71
|
+
if filename is not None and line_number is not None:
|
|
72
|
+
print(f"Exception occurred at line {line_number} in {filename}")
|
|
73
|
+
print(ex)
|
|
74
|
+
|
|
75
|
+
response_code = -1
|
|
76
|
+
response_code = "Exception in UpdateVideoClipFileID"
|
|
77
|
+
|
|
78
|
+
return response_code, response_code
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from .API import *
|
|
2
|
+
from .Config import *
|
|
3
|
+
from .Device import *
|
|
4
|
+
from .Event import *
|
|
5
|
+
from .File import *
|
|
6
|
+
from .Health import *
|
|
7
|
+
from .Patch import *
|
|
8
|
+
from .VideoClip import *
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
__all__ = API.__all__ + Config.__all__ + Device.__all__ + Event.__all__ + File.__all__ + Health.__all__ + Patch.__all__ + VideoClip.__all__
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ActionStreamer
|
|
3
|
+
Version: 0.1.11
|
|
4
|
+
Summary: A library for the ActionStreamer API.
|
|
5
|
+
Author: ActionStreamer
|
|
6
|
+
Author-email: joe@actionstreamer.com
|
|
7
|
+
Requires-Python: >=3.10,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# ActionStreamerWS
|
|
15
|
+
|
|
16
|
+
A library for the ActionStreamer API.
|
|
17
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "ActionStreamer"
|
|
3
|
+
version = "0.1.11"
|
|
4
|
+
description = "A library for the ActionStreamer API."
|
|
5
|
+
authors = ["ActionStreamer <joe@actionstreamer.com>"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
|
|
8
|
+
[tool.poetry.dependencies]
|
|
9
|
+
python = "^3.10"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["poetry-core"]
|
|
14
|
+
build-backend = "poetry.core.masonry.api"
|