autoverse-cli 0.28.1__py3-none-any.whl

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.
Files changed (51) hide show
  1. autoverse_cli-0.28.1.dist-info/METADATA +91 -0
  2. autoverse_cli-0.28.1.dist-info/RECORD +51 -0
  3. autoverse_cli-0.28.1.dist-info/WHEEL +5 -0
  4. autoverse_cli-0.28.1.dist-info/entry_points.txt +2 -0
  5. autoverse_cli-0.28.1.dist-info/licenses/LICENSE +33 -0
  6. autoverse_cli-0.28.1.dist-info/top_level.txt +1 -0
  7. avrs/__init__.py +0 -0
  8. avrs/app_version.py +24 -0
  9. avrs/argparse_help.py +30 -0
  10. avrs/avrs.py +183 -0
  11. avrs/can_tool.py +192 -0
  12. avrs/can_tool_util.py +190 -0
  13. avrs/cfg.py +78 -0
  14. avrs/launcher.py +256 -0
  15. avrs/launcher_util.py +203 -0
  16. avrs/race_cloud.py +506 -0
  17. avrs/race_cloud_bridge_can.py +100 -0
  18. avrs/race_cloud_cfg_util.py +310 -0
  19. avrs/race_cloud_fwd_api.py +49 -0
  20. avrs/race_cloud_util.py +384 -0
  21. avrs/requests/change_camera.py +24 -0
  22. avrs/requests/code_booz.py +69 -0
  23. avrs/requests/demo.py +19 -0
  24. avrs/requests/dump_sim_config.py +14 -0
  25. avrs/requests/environment.py +46 -0
  26. avrs/requests/fault_injection.py +186 -0
  27. avrs/requests/get_object_config.py +18 -0
  28. avrs/requests/get_web_viz_meta.py +11 -0
  29. avrs/requests/leaderboard.py +74 -0
  30. avrs/requests/list_sim_objects.py +26 -0
  31. avrs/requests/log_path.py +28 -0
  32. avrs/requests/misc.py +70 -0
  33. avrs/requests/move_to_landmark.py +16 -0
  34. avrs/requests/npc.py +289 -0
  35. avrs/requests/race_control.py +48 -0
  36. avrs/requests/request.py +61 -0
  37. avrs/requests/reset_to_track.py +21 -0
  38. avrs/requests/rest_request.py +45 -0
  39. avrs/requests/restart.py +12 -0
  40. avrs/requests/scenario_control.py +43 -0
  41. avrs/requests/spawn_object.py +44 -0
  42. avrs/requests/teleport.py +40 -0
  43. avrs/requests/toggle_hud.py +11 -0
  44. avrs/requests/vd.py +64 -0
  45. avrs/requests/vehicle_input.py +21 -0
  46. avrs/requests/vehicle_replay.py +454 -0
  47. avrs/shell_completion.py +121 -0
  48. avrs/simconfig.py +75 -0
  49. avrs/simconfig_util.py +170 -0
  50. avrs/tests.py +9 -0
  51. avrs/util.py +13 -0
avrs/launcher_util.py ADDED
@@ -0,0 +1,203 @@
1
+ import os
2
+ import json
3
+ import http.client
4
+ import boto3
5
+ import sys
6
+ import shutil
7
+
8
+ def validate_license_file(file_path):
9
+ """
10
+ Given file path, load and validate license info. Returns tuple of bool
11
+ indicating success, string for status, and dict of license info from file
12
+ """
13
+ status = ''
14
+ license = {}
15
+
16
+ # Ensure it's a file
17
+ if not os.path.isfile(file_path):
18
+ status = 'no license file at {}'.format(file_path)
19
+ return (False, status, license)
20
+
21
+ # Parse it and check format
22
+ with open(file_path, 'r', encoding='utf-8') as f:
23
+ license = json.load(f)
24
+
25
+ if 'id' not in license:
26
+ status = 'malformed license file. missing id field'
27
+ return (False, status, license)
28
+ if 'public_key' not in license:
29
+ status = 'malformed license file. missing public key field'
30
+ return (False, status, license)
31
+ if 'shipping_signature' not in license:
32
+ status = 'malformed license file. missing shipping signature'
33
+ return (False, status, license)
34
+ return (True, status, license)
35
+
36
+
37
+ def try_get_launcher_download_keys(cfg):
38
+ """
39
+ Uses license info stored in config to requrest download keys from API.
40
+ These keys can be used to authenticate downloads from bucket
41
+ """
42
+ status = ''
43
+ out_cfg = cfg
44
+
45
+ api_url = 'uu6fmbvrhk.execute-api.us-east-1.amazonaws.com'
46
+ connection = http.client.HTTPSConnection(api_url)
47
+ headers = {'Content-type': 'application/json'}
48
+ body = json.dumps({
49
+ 'id': cfg['license']['data']['id'],
50
+ 'licenseSignature': cfg['license']['data']['shipping_signature']
51
+ }).encode('utf-8')
52
+ connection.request('POST', '/test', body, headers)
53
+ response = connection.getresponse()
54
+
55
+ api_ok = False
56
+ api_status = ""
57
+
58
+ if response.status == 200:
59
+ res_full = json.loads(response.read().decode('utf-8'))
60
+ status += "primary api response: {}".format(res_full)
61
+ dlinfo = json.loads(res_full['body'])
62
+ code = res_full['statusCode']
63
+ if code == 200:
64
+ api_ok = True
65
+ for k, v in dlinfo.items():
66
+ out_cfg[k] = v
67
+
68
+ if not api_ok:
69
+ #try other api
70
+ alt_api_url = 'uu6fmbvrhk.execute-api.us-east-1.amazonaws.com'
71
+ connection = http.client.HTTPSConnection(alt_api_url)
72
+ connection.request('POST', '/test/alt', body, headers)
73
+ response = connection.getresponse()
74
+ if response.status == 200:
75
+ res_full = json.loads(response.read().decode('utf-8'))
76
+ status += "alt api response: {}".format(res_full)
77
+ dlinfo = json.loads(res_full.get('body', "{}"))
78
+ code = res_full['statusCode']
79
+ if code == 200:
80
+ api_ok = True
81
+ for k, v in dlinfo.items():
82
+ out_cfg[k] = v
83
+ else:
84
+ status += "primary and alt returned non 200"
85
+ else:
86
+ status += "primary and alt returned non 200"
87
+
88
+ return (api_ok, status, out_cfg)
89
+
90
+ def has_launcher_download_keys(cfg):
91
+ """
92
+ Checks for required config values for download keys
93
+ """
94
+ status = ''
95
+ if 'dlkey_id' not in cfg or 'dlkey' not in cfg:
96
+ status += 'Config has no Download Keys'
97
+ return (False, status)
98
+ return (True, status)
99
+
100
+ def get_launcher_license_status_string(cfg):
101
+ """
102
+ Builds a string representation of where the CLI stands
103
+ as far as being configured as a launcher able to download simulator builds
104
+ """
105
+ status = ''
106
+ if 'license' not in cfg:
107
+ status += 'no license has been registered\n'
108
+ else:
109
+ status += 'license registered as {}\n'.format(cfg['license']['filename'])
110
+
111
+ if 'dlkey_id' not in cfg:
112
+ status += 'no download key ID found\n'
113
+ else:
114
+ status += 'download key id obtained\n'
115
+
116
+ if 'dlkey' not in cfg:
117
+ status += 'no download key found\n'
118
+ else:
119
+ status += 'download key obtained\n'
120
+ return status
121
+
122
+ def get_launcher_build_info(cfg, variant):
123
+ """
124
+ Contacts API to discover the current latest build version and returns full build info
125
+ """
126
+
127
+ api_url = 'zn5boqqk60.execute-api.us-east-1.amazonaws.com'
128
+ connection = http.client.HTTPSConnection(api_url)
129
+ headers = {'Content-type': 'application/json'}
130
+ body = {
131
+ "packageName": variant
132
+ }
133
+ connection.request('POST', '/test', json.dumps(body).encode("utf-8"), headers)
134
+ response = connection.getresponse()
135
+
136
+ if response.status != 200:
137
+ return (False, "get build info api returned {}".format(response.status), "", "", {})
138
+
139
+ res_full = json.loads(response.read().decode('utf-8'))
140
+ raw_body = res_full.get('body', "{}")
141
+ info = json.loads(raw_body) if isinstance(raw_body, str) else raw_body
142
+ if not isinstance(info, dict):
143
+ return (False, "get build info api returned unexpected format", "", "", {})
144
+
145
+ code = res_full.get('statusCode')
146
+ if code != 200:
147
+ return (False, "get build info api returned {}".format(code), "", "", info)
148
+
149
+ latest_version = info.get('prod', '')
150
+ if latest_version == '':
151
+ return (False, "get build info api response missing prod", "", "", info)
152
+
153
+ staged_version = info.get('staging', latest_version)
154
+ return (True, "ok", latest_version, staged_version, info)
155
+
156
+ def download_simulator_archive(cfg, source_path, target_path):
157
+ """
158
+ Downloads the latest version of the simulator from the builds bucket
159
+ """
160
+ s3_client = boto3.client(
161
+ 's3',
162
+ aws_access_key_id=cfg['dlkey_id'],
163
+ aws_secret_access_key=cfg['dlkey'])
164
+ s3_download_with_progress(s3_client, 'autoverse-builds', source_path, target_path)
165
+
166
+ def get_sim_saved_dir(sim_install_path):
167
+ return os.path.join(sim_install_path, 'Linux', 'Autoverse', 'Saved')
168
+
169
+ def is_installed_sim(file_path):
170
+ """
171
+ Check if the given path appears to be the root of
172
+ a simulator installation
173
+ """
174
+ if not os.path.exists(file_path):
175
+ return False
176
+
177
+ if not os.path.isdir(os.path.join(file_path, 'Linux', 'Autoverse')):
178
+ return False
179
+
180
+ if not os.path.isfile(os.path.join(file_path, 'Linux', 'Autoverse', 'Saved', 'simconfig.json')):
181
+ return False
182
+
183
+ return True
184
+
185
+ def s3_download_with_progress(s3_client, s3_bucket, s3_object_key, local_file_path):
186
+
187
+ meta_data = s3_client.head_object(Bucket=s3_bucket, Key=s3_object_key)
188
+ total_length = int(meta_data.get('ContentLength', 0))
189
+ downloaded = 0
190
+
191
+ def progress(chunk):
192
+ nonlocal downloaded
193
+ downloaded += chunk
194
+ if total_length > 0:
195
+ done = int(50 * downloaded / total_length)
196
+ else:
197
+ done = 0
198
+ sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50-done)) )
199
+ sys.stdout.flush()
200
+
201
+ with open(local_file_path, 'wb') as f:
202
+ s3_client.download_fileobj(s3_bucket, s3_object_key, f, Callback=progress)
203
+ print('\n')