remotivelabs-cli 0.2.3__py3-none-any.whl → 0.3.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.

Potentially problematic release.


This version of remotivelabs-cli might be problematic. Click here for more details.

Files changed (55) hide show
  1. cli/broker/__init__.py +36 -0
  2. cli/broker/discovery.py +43 -0
  3. cli/broker/export.py +6 -36
  4. cli/broker/files.py +12 -12
  5. cli/broker/lib/broker.py +132 -106
  6. cli/broker/lib/client.py +224 -0
  7. cli/broker/lib/helper.py +277 -0
  8. cli/broker/lib/signalcreator.py +196 -0
  9. cli/broker/license_flows.py +11 -13
  10. cli/broker/playback.py +10 -10
  11. cli/broker/record.py +4 -4
  12. cli/broker/scripting.py +6 -9
  13. cli/broker/signals.py +17 -19
  14. cli/cloud/__init__.py +17 -0
  15. cli/cloud/auth/cmd.py +74 -33
  16. cli/cloud/auth/login.py +42 -54
  17. cli/cloud/auth_tokens.py +40 -247
  18. cli/cloud/brokers.py +5 -9
  19. cli/cloud/configs.py +4 -17
  20. cli/cloud/licenses/__init__.py +0 -0
  21. cli/cloud/licenses/cmd.py +14 -0
  22. cli/cloud/organisations.py +12 -17
  23. cli/cloud/projects.py +3 -3
  24. cli/cloud/recordings.py +35 -61
  25. cli/cloud/recordings_playback.py +22 -22
  26. cli/cloud/resumable_upload.py +6 -6
  27. cli/cloud/service_account_tokens.py +4 -3
  28. cli/cloud/storage/cmd.py +2 -3
  29. cli/cloud/storage/copy.py +2 -1
  30. cli/connect/connect.py +4 -4
  31. cli/connect/protopie/protopie.py +22 -30
  32. cli/remotive.py +16 -26
  33. cli/settings/__init__.py +1 -2
  34. cli/settings/config_file.py +2 -0
  35. cli/settings/core.py +146 -146
  36. cli/settings/migration/migrate_config_file.py +13 -6
  37. cli/settings/migration/migration_tools.py +6 -4
  38. cli/settings/state_file.py +12 -4
  39. cli/tools/can/can.py +4 -7
  40. cli/topology/__init__.py +3 -0
  41. cli/topology/cmd.py +60 -83
  42. cli/topology/start_trial.py +105 -0
  43. cli/typer/typer_utils.py +3 -6
  44. cli/utils/console.py +61 -0
  45. cli/utils/rest_helper.py +33 -31
  46. cli/utils/versions.py +7 -19
  47. {remotivelabs_cli-0.2.3.dist-info → remotivelabs_cli-0.3.1.dist-info}/METADATA +3 -2
  48. remotivelabs_cli-0.3.1.dist-info/RECORD +74 -0
  49. cli/broker/brokers.py +0 -93
  50. cli/cloud/cloud_cli.py +0 -29
  51. cli/errors.py +0 -44
  52. remotivelabs_cli-0.2.3.dist-info/RECORD +0 -67
  53. {remotivelabs_cli-0.2.3.dist-info → remotivelabs_cli-0.3.1.dist-info}/LICENSE +0 -0
  54. {remotivelabs_cli-0.2.3.dist-info → remotivelabs_cli-0.3.1.dist-info}/WHEEL +0 -0
  55. {remotivelabs_cli-0.2.3.dist-info → remotivelabs_cli-0.3.1.dist-info}/entry_points.txt +0 -0
@@ -5,27 +5,22 @@ import json
5
5
  import os
6
6
  import sys
7
7
  import time
8
- import traceback
9
8
  from pathlib import Path
10
9
  from typing import Any, Dict, List, Tuple, Union
11
10
 
12
11
  import grpc
13
12
  import socketio
14
- from remotivelabs.broker.sync import BrokerException, Client, SignalIdentifier, SignalsInFrame
15
- from rich import print as pretty_print
16
- from rich.console import Console
17
13
  from socketio.exceptions import ConnectionError as SocketIoConnectionError
18
14
 
19
15
  from cli.broker.lib.broker import SubscribableSignal
20
- from cli.errors import ErrorPrinter
16
+ from cli.broker.lib.client import BrokerException, Client, SignalIdentifier, SignalsInFrame
21
17
  from cli.settings import settings
18
+ from cli.utils.console import print_generic_error, print_generic_message, print_success, print_unformatted_to_stderr
22
19
 
23
20
  PP_CONNECT_APP_NAME = "RemotiveBridge"
24
21
 
25
22
  io = socketio.Client()
26
23
 
27
- err_console = Console(stderr=True)
28
-
29
24
  _has_received_signal = False
30
25
  is_connected = False
31
26
  config_path: Path
@@ -35,7 +30,7 @@ broker: Any
35
30
 
36
31
  @io.on("connect")
37
32
  def on_connect() -> None:
38
- print("Connected to ProtoPie Connect")
33
+ print_success("Connected to ProtoPie Connect")
39
34
  io.emit("ppBridgeApp", {"name": PP_CONNECT_APP_NAME})
40
35
  io.emit("PLUGIN_STARTED", {"name": PP_CONNECT_APP_NAME})
41
36
 
@@ -72,8 +67,8 @@ def get_signal_name(expression: str, s_name: str) -> str:
72
67
  sig_name = eval(f"s_name.{expression}")
73
68
  return str(sig_name)
74
69
  except Exception as e:
75
- ErrorPrinter.print_generic_error(f"Failed to evaluate your python expression {expression}")
76
- err_console.print(e)
70
+ print_generic_error(f"Failed to evaluate your python expression {expression}")
71
+ print_unformatted_to_stderr(e)
77
72
  # This was the only way I could make this work, exiting on another thread than main
78
73
  os._exit(1)
79
74
  else:
@@ -91,7 +86,7 @@ def _connect_to_broker(
91
86
  def on_signals(frame: SignalsInFrame) -> None:
92
87
  global _has_received_signal # noqa: PLW0603
93
88
  if not _has_received_signal:
94
- pretty_print("Bridge-app is properly receiving signals, you are good to go :thumbsup:")
89
+ print_generic_message("Bridge-app is properly receiving signals, you are good to go :thumbsup:")
95
90
  _has_received_signal = True
96
91
 
97
92
  for s in frame:
@@ -114,42 +109,42 @@ def grpc_connect(
114
109
  on_signals: Any, signals_to_subscribe_to: Union[List[SignalIdentifier], None] = None, on_change_only: bool = False
115
110
  ) -> None:
116
111
  try:
117
- pretty_print("Connecting and subscribing to broker...")
112
+ print_generic_message("Connecting and subscribing to broker...")
118
113
  subscription = None
119
114
  client = Client(client_id="cli")
120
115
  client.connect(url=broker, api_key=x_api_key)
121
116
  client.on_signals = on_signals
122
117
 
123
118
  if signals_to_subscribe_to is None:
124
- print("No sigs")
119
+ # TODO: use logs instead of print?
120
+ print_generic_error("No signals to subscribe to")
125
121
  return
126
122
  subscription = client.subscribe(signals_to_subscribe_to=signals_to_subscribe_to, changed_values_only=on_change_only)
127
- pretty_print("Subscription to broker completed")
128
- pretty_print("Waiting for signals...")
123
+ print_generic_message("Subscription to broker completed")
124
+ print_generic_message("Waiting for signals...")
129
125
 
130
126
  while True:
131
127
  time.sleep(1)
132
128
 
133
129
  except grpc.RpcError as e:
134
- err_console.print(":boom: [red]Problems connecting or subscribing[/red]")
130
+ print_generic_error("Problems connecting or subscribing")
135
131
  if isinstance(e, grpc.Call):
136
- print(f"{e.code()} - {e.details()}")
132
+ print_generic_error(f"{e.code()} - {e.details()}")
137
133
  else:
138
- print(e)
134
+ print_generic_error(e)
139
135
 
140
136
  except BrokerException as e:
141
- print(e)
137
+ print_generic_error(e)
142
138
  if subscription is not None:
143
139
  subscription.cancel()
144
140
 
145
141
  except KeyboardInterrupt:
146
- print("Keyboard interrupt received. Closing subscription.")
142
+ print_generic_message("Keyboard interrupt received. Closing subscription.")
147
143
  if subscription is not None:
148
144
  subscription.cancel()
149
145
 
150
146
  except Exception as e:
151
- print(traceback.format_exc())
152
- err_console.print(f":boom: {e}")
147
+ print_generic_error(e)
153
148
 
154
149
 
155
150
  def do_connect( # noqa: PLR0913
@@ -168,7 +163,7 @@ def do_connect( # noqa: PLR0913
168
163
 
169
164
  if broker_url.startswith("https"):
170
165
  if api_key is None:
171
- print("No --api-key, reading token from file")
166
+ print_generic_message("No --api-key, reading token from file")
172
167
  x_api_key = settings.get_active_token_secret()
173
168
  else:
174
169
  x_api_key = api_key
@@ -176,18 +171,15 @@ def do_connect( # noqa: PLR0913
176
171
  x_api_key = api_key
177
172
  try:
178
173
  io.connect(address)
179
- # if config is None:
180
- # raise ValueError("Config is None")
181
174
  config_path = config
182
175
  while is_connected is None:
183
176
  time.sleep(1)
184
- # if expression is not None:
185
177
  _connect_to_broker(signals_to_subscribe_to=signals, config=config, expression=expression, on_change_only=on_change_only)
186
178
  except SocketIoConnectionError as e:
187
- err_console.print(":boom: [bold red]Failed to connect to ProtoPie Connect[/bold red]")
188
- err_console.print(e)
179
+ print_generic_error("Failed to connect to ProtoPie Connect")
180
+ print_unformatted_to_stderr(e)
189
181
  sys.exit(1)
190
182
  except Exception as e:
191
- err_console.print(":boom: [bold red]Unexpected error[/bold red]")
192
- err_console.print(e)
183
+ print_generic_error("Unexpected error")
184
+ print_unformatted_to_stderr(e)
193
185
  sys.exit(1)
cli/remotive.py CHANGED
@@ -3,16 +3,13 @@ from __future__ import annotations
3
3
  import os
4
4
 
5
5
  import typer
6
- from rich import print as rich_print
7
- from rich.console import Console
8
6
  from trogon import Trogon
9
7
  from typer.main import get_group
10
8
 
11
- from cli.broker.brokers import app as broker_app
12
- from cli.cloud.cloud_cli import app as cloud_app
9
+ from cli.broker import app as broker_app
10
+ from cli.cloud import app as cloud_app
13
11
  from cli.connect.connect import app as connect_app
14
- from cli.settings import settings
15
- from cli.settings.core import Settings
12
+ from cli.settings import Settings, settings
16
13
  from cli.settings.migration.migrate_all_token_files import migrate_any_legacy_tokens
17
14
  from cli.settings.migration.migrate_config_file import migrate_config_file
18
15
  from cli.settings.migration.migrate_legacy_dirs import migrate_legacy_settings_dirs
@@ -20,8 +17,7 @@ from cli.tools.tools import app as tools_app
20
17
  from cli.topology.cmd import app as topology_app
21
18
  from cli.typer import typer_utils
22
19
  from cli.utils import versions
23
-
24
- err_console = Console(stderr=True)
20
+ from cli.utils.console import print_generic_error, print_generic_message
25
21
 
26
22
 
27
23
  def is_featue_flag_enabled(env_var: str) -> bool:
@@ -49,7 +45,7 @@ def version_callback(value: bool) -> None:
49
45
 
50
46
  def test_callback(value: int) -> None:
51
47
  if value:
52
- rich_print(value)
48
+ print_generic_message(str(value))
53
49
  raise typer.Exit()
54
50
 
55
51
 
@@ -73,7 +69,7 @@ def run_migrations(settings: Settings) -> None:
73
69
  migrate_config_file(settings.config_file_path, settings)
74
70
 
75
71
  if has_migrated_tokens:
76
- err_console.print("Migrated old credentials and configuration files, you may need to login again or activate correct credentials")
72
+ print_generic_error("Migrated old credentials and configuration files, you may need to login again or activate correct credentials")
77
73
 
78
74
 
79
75
  def set_default_org_as_env(settings: Settings) -> None:
@@ -82,7 +78,7 @@ def set_default_org_as_env(settings: Settings) -> None:
82
78
  This has to be done early before it is read
83
79
  """
84
80
  if "REMOTIVE_CLOUD_ORGANIZATION" not in os.environ:
85
- active_account = settings.get_cli_config().get_active_account()
81
+ active_account = settings.get_active_account()
86
82
  if active_account and active_account.default_organization:
87
83
  os.environ["REMOTIVE_CLOUD_ORGANIZATION"] = active_account.default_organization
88
84
 
@@ -113,21 +109,15 @@ def tui(ctx: typer.Context) -> None:
113
109
 
114
110
 
115
111
  app.add_typer(broker_app, name="broker", help="Manage a single broker - local or cloud")
116
- app.add_typer(
117
- cloud_app,
118
- name="cloud",
119
- help="Manage resources in RemotiveCloud",
120
- )
112
+ app.add_typer(cloud_app, name="cloud", help="Manage resources in RemotiveCloud")
121
113
  app.add_typer(connect_app, name="connect", help="Integrations with other systems")
122
114
  app.add_typer(tools_app, name="tools")
115
+ app.add_typer(
116
+ topology_app,
117
+ name="topology",
118
+ help="""
119
+ Interact and manage RemotiveTopology resources
123
120
 
124
- if is_featue_flag_enabled("REMOTIVE_TOPOLOGY_ENABLED"):
125
- app.add_typer(
126
- topology_app,
127
- name="topology",
128
- help="""
129
- RemotiveTopology actions
130
-
131
- Read more at https://docs.remotivelabs.com/docs/remotive-topology
132
- """,
133
- )
121
+ Read more at https://docs.remotivelabs.com/docs/remotive-topology
122
+ """,
123
+ )
cli/settings/__init__.py CHANGED
@@ -1,14 +1,13 @@
1
1
  from cli.settings.config_file import Account, ConfigFile
2
2
  from cli.settings.config_file import dumps as dumps_config_file
3
3
  from cli.settings.config_file import loads as loads_config_file
4
- from cli.settings.core import InvalidSettingsFilePathError, Settings, TokenNotFoundError, settings
4
+ from cli.settings.core import InvalidSettingsFilePathError, Settings, settings
5
5
  from cli.settings.token_file import TokenFile
6
6
  from cli.settings.token_file import dumps as dumps_token_file
7
7
  from cli.settings.token_file import loads as loads_token_file
8
8
 
9
9
  __all__ = [
10
10
  "settings",
11
- "TokenNotFoundError",
12
11
  "InvalidSettingsFilePathError",
13
12
  "Settings",
14
13
  "TokenFile",
@@ -10,6 +10,8 @@ from cli.settings.token_file import TokenFile
10
10
  class Account(BaseModel):
11
11
  """
12
12
  Account represents an account in the configuration file.
13
+
14
+ TODO: Add email field to Account
13
15
  """
14
16
 
15
17
  credentials_file: str