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
cli/settings/core.py CHANGED
@@ -3,20 +3,18 @@ from __future__ import annotations
3
3
  import os
4
4
  import stat
5
5
  import sys
6
- from json import JSONDecodeError
7
6
  from pathlib import Path
8
- from typing import Optional, Tuple
7
+ from typing import Optional
9
8
 
10
- from pydantic import ValidationError
11
9
  from rich.console import Console
12
10
 
13
- from cli.errors import ErrorPrinter
14
11
  from cli.settings import config_file as cf
15
12
  from cli.settings import state_file as sf
16
13
  from cli.settings import token_file as tf
17
- from cli.settings.config_file import ConfigFile
14
+ from cli.settings.config_file import Account, ConfigFile
18
15
  from cli.settings.state_file import StateFile
19
16
  from cli.settings.token_file import TokenFile
17
+ from cli.utils.console import print_hint
20
18
 
21
19
  err_console = Console(stderr=True)
22
20
 
@@ -24,27 +22,17 @@ CONFIG_DIR_PATH = Path.home() / ".config" / "remotive"
24
22
  CLI_CONFIG_FILE_NAME = "config.json"
25
23
  CLI_INTERNAL_STATE_FILE_NAME = "app-state.json"
26
24
 
27
- TokenFileMetadata = Tuple[TokenFile, Path]
28
-
29
25
 
30
26
  class InvalidSettingsFilePathError(Exception):
31
27
  """Raised when trying to access an invalid settings file or file path"""
32
28
 
33
29
 
34
- class TokenNotFoundError(Exception):
35
- """Raised when a token cannot be found in settings"""
36
-
37
-
38
30
  class Settings:
39
31
  """
40
32
  Settings handles tokens and other config for the remotive CLI
41
33
 
42
- TODO: return None instead of raising errors when no active account is found
43
- TODO: be consisten in how we update (and write) state to the different files
44
34
  TODO: migrate away from singleton instance
45
- TODO: what about manually downloaded tokens when removing a token?
46
- TODO: what about active token when removing a token?
47
- TODO: list tokens should use better listing logic
35
+ TODO: How do we handle REMOTIVE_CLOUD_ACCESS_TOKEN in combination with active account? What takes precedence?
48
36
  """
49
37
 
50
38
  config_dir: Path
@@ -60,57 +48,78 @@ class Settings:
60
48
  if not self.state_file_path.exists():
61
49
  self._write_state_file(StateFile())
62
50
 
63
- def get_cli_config(self) -> ConfigFile:
51
+ def _get_cli_config(self) -> ConfigFile:
64
52
  return self._read_config_file()
65
53
 
66
- def get_state_file(self) -> StateFile:
54
+ def _get_state_file(self) -> StateFile:
67
55
  return self._read_state_file()
68
56
 
57
+ def should_perform_update_check(self) -> bool:
58
+ """
59
+ Check if we should perform an update check.
60
+ """
61
+ return self._get_state_file().should_perform_update_check()
62
+
69
63
  def set_default_organisation(self, organisation: str) -> None:
70
64
  """
71
65
  Set the default organization for the active account
66
+
67
+ TODO: Raise error, dont sys.exit
72
68
  """
73
- config = self.get_cli_config()
69
+ config = self._get_cli_config()
74
70
  active_account = config.get_active_account()
75
71
  if not active_account:
76
- ErrorPrinter.print_hint("You must have an account activated in order to set default organization")
72
+ print_hint("You must have an account activated in order to set default organization")
77
73
  sys.exit(1)
78
74
  active_account.default_organization = organisation
79
75
  self._write_config_file(config)
80
76
 
81
- def get_active_token(self) -> str:
77
+ def get_active_account(self) -> Account | None:
82
78
  """
83
- Get the current active token secret
79
+ Get the current active account
80
+
81
+ TODO: Add email field to Account
84
82
  """
85
- token_file = self.get_active_token_file()
86
- return token_file.token
83
+ return self._get_cli_config().get_active_account()
87
84
 
88
- def get_active_token_file(self) -> TokenFile:
85
+ def get_active_token_file(self) -> TokenFile | None:
89
86
  """
90
- Get the current active token file
87
+ Get the token file for the current active account
91
88
  """
92
- active_account = self.get_cli_config().get_active_account()
93
- if not active_account:
94
- raise TokenNotFoundError("No active account found")
89
+ active_account = self.get_active_account()
90
+ return self._read_token_file(active_account.credentials_file) if active_account else None
95
91
 
96
- token_file_name = active_account.credentials_file
97
- return self._read_token_file(self.config_dir / token_file_name)
92
+ def get_active_token(self) -> str | None:
93
+ """
94
+ Get the token secret for the current active account
95
+ """
96
+ token_file = self.get_active_token_file()
97
+ return token_file.token if token_file else None
98
98
 
99
- def activate_token(self, token_file: TokenFile) -> None:
99
+ def activate_token(self, token_file: TokenFile) -> TokenFile:
100
100
  """
101
101
  Activate a token by name or path
102
102
 
103
103
  The token secret will be set as the current active secret.
104
+
105
+ Returns the activated token file
104
106
  """
105
- config = self.get_cli_config()
107
+ config = self._get_cli_config()
106
108
  config.activate_account(token_file.account.email)
107
109
  self._write_config_file(config)
110
+ return token_file
111
+
112
+ def is_active_account(self, email: str) -> bool:
113
+ """
114
+ Returns True if the given email is the active account
115
+ """
116
+ return self._get_cli_config().active == email
108
117
 
109
- def clear_active_token(self) -> None:
118
+ def clear_active_account(self) -> None:
110
119
  """
111
120
  Clear the current active token
112
121
  """
113
- config = self.get_cli_config()
122
+ config = self._get_cli_config()
114
123
  config.active = None
115
124
  self._write_config_file(config)
116
125
 
@@ -120,78 +129,56 @@ class Settings:
120
129
 
121
130
  If multiple tokens are found, the first one is returned.
122
131
  """
123
- tokens = [t for t in self.list_personal_tokens() if t.account is not None and t.account.email == email]
124
- if len(tokens) > 0:
125
- return tokens[0]
126
- tokens = [t for t in self.list_service_account_tokens() if t.account is not None and t.account.email == email]
127
- if len(tokens) > 0:
128
- return tokens[0]
129
- return None
132
+ accounts = self._get_cli_config().accounts.get(email)
133
+ return self._read_token_file(accounts.credentials_file) if accounts else None
130
134
 
131
- def get_token_file(self, name: str) -> TokenFile:
135
+ def get_token_file(self, name: str) -> TokenFile | None:
132
136
  """
133
137
  Get a token file by name or path
134
138
  """
135
139
  # 1. Try relative path
136
140
  if (self.config_dir / name).exists():
137
- return self._read_token_file(self.config_dir / name)
141
+ return self._read_token_file(name)
138
142
 
139
- # 2. Try absolute path
140
- if Path(name).exists():
141
- return self._read_token_file(Path(name))
142
-
143
- # 3. Try name
144
- return self._get_token_by_name(name)[0]
143
+ # 2. Try name
144
+ return self._get_token_by_name(name)
145
145
 
146
146
  def remove_token_file(self, name: str) -> None:
147
147
  """
148
148
  Remove a token file by name or path
149
-
150
- TODO: what about manually downloaded tokens?
151
149
  """
152
- if Path(name).exists():
153
- if self.config_dir not in Path(name).parents:
154
- raise InvalidSettingsFilePathError(f"cannot remove a token file not located in settings dir {self.config_dir}")
155
- return Path(name).unlink()
150
+ token_file = self.get_token_file(name)
151
+ if not token_file:
152
+ return
153
+
154
+ # If the token is active, clear it first
155
+ email = token_file.account.email
156
+ if self.is_active_account(email):
157
+ self.clear_active_account()
156
158
 
157
- # TODO: what about the active token?
158
- path = self._get_token_by_name(name)[1]
159
- return path.unlink()
159
+ # Remove the token file
160
+ path = self.config_dir / self._get_cli_config().accounts[email].credentials_file
161
+ path.unlink()
162
+
163
+ # Remove the account from the config file
164
+ config = self._get_cli_config()
165
+ config.remove_account(email)
166
+ self._write_config_file(config)
160
167
 
161
168
  def add_personal_token(self, token: str, activate: bool = False, overwrite_if_exists: bool = False) -> TokenFile:
162
169
  """
163
170
  Add a personal token
164
171
  """
165
- file = tf.loads(token)
166
- if file.type != "authorized_user":
172
+ token_file = tf.loads(token)
173
+ if token_file.type != "authorized_user":
167
174
  raise ValueError("Token type MUST be authorized_user")
168
175
 
169
- file_name = file.get_token_file_name()
170
- path = self.config_dir / file_name
171
- if path.exists() and not overwrite_if_exists:
172
- raise FileExistsError(f"Token file already exists: {path}")
173
-
174
- self._write_token_file(path, file)
175
- cli_config = self.get_cli_config()
176
- cli_config.init_account(email=file.account.email, token_file=file)
177
- self._write_config_file(cli_config)
176
+ token_file = self.add_token_as_account(token_file, overwrite_if_exists)
178
177
 
179
178
  if activate:
180
- self.activate_token(file)
179
+ self.activate_token(token_file)
181
180
 
182
- return file
183
-
184
- def list_personal_tokens(self) -> list[TokenFile]:
185
- """
186
- List all personal tokens
187
- """
188
- return [f[0] for f in self._list_personal_tokens()]
189
-
190
- def list_personal_token_files(self) -> list[Path]:
191
- """
192
- List paths to all personal token files
193
- """
194
- return [f[1] for f in self._list_personal_tokens()]
181
+ return token_file
195
182
 
196
183
  def add_service_account_token(self, token: str, overwrite_if_exists: bool = False) -> TokenFile:
197
184
  """
@@ -201,29 +188,74 @@ class Settings:
201
188
  if token_file.type != "service_account":
202
189
  raise ValueError("Token type MUST be service_account")
203
190
 
204
- file = token_file.get_token_file_name()
205
- path = self.config_dir / file
191
+ return self.add_token_as_account(token_file, overwrite_if_exists)
192
+
193
+ def add_token_as_account(self, token_file: TokenFile, overwrite_if_exists: bool = False) -> TokenFile:
194
+ """
195
+ Add an account to the config file
196
+ """
197
+ file_name = token_file.get_token_file_name()
198
+ path = self.config_dir / file_name
206
199
  if path.exists() and not overwrite_if_exists:
207
200
  raise FileExistsError(f"Token file already exists: {path}")
208
201
 
209
202
  self._write_token_file(path, token_file)
210
- cli_config = self.get_cli_config()
203
+ cli_config = self._get_cli_config()
211
204
  cli_config.init_account(email=token_file.account.email, token_file=token_file)
212
205
  self._write_config_file(cli_config)
213
206
 
214
207
  return token_file
215
208
 
216
- def list_service_account_tokens(self) -> list[TokenFile]:
209
+ def list_accounts(self) -> dict[str, Account]:
210
+ """
211
+ List all accounts
212
+ """
213
+ return self._get_cli_config().accounts
214
+
215
+ def list_personal_accounts(self) -> dict[str, Account]:
216
+ """
217
+ List all personal accounts
218
+
219
+ TODO: add account type to Account
217
220
  """
218
- List all service account tokens
221
+ accounts = self.list_accounts()
222
+ return {
223
+ email: account
224
+ for email, account in accounts.items()
225
+ if self._read_token_file(account.credentials_file).type == "authorized_user"
226
+ }
227
+
228
+ def list_service_accounts(self) -> dict[str, Account]:
229
+ """
230
+ List all personal accounts
231
+
232
+ TODO: add account type to Account
233
+ """
234
+ accounts = self.list_accounts()
235
+ return {
236
+ email: account
237
+ for email, account in accounts.items()
238
+ if self._read_token_file(account.credentials_file).type == "service_account"
239
+ }
240
+
241
+ def list_token_files(self) -> list[TokenFile]:
242
+ """
243
+ List all token files
219
244
  """
220
- return [f[0] for f in self._list_service_account_tokens()]
245
+ accounts = self._get_cli_config().accounts.values()
246
+ return [self._read_token_file(account.credentials_file) for account in accounts]
221
247
 
222
- def list_service_account_token_files(self) -> list[Path]:
248
+ def list_personal_token_files(self) -> list[TokenFile]:
223
249
  """
224
- List paths to all service account token files
250
+ List all personal token files
225
251
  """
226
- return [f[1] for f in self._list_service_account_tokens()]
252
+ return [token_file for token_file in self.list_token_files() if token_file.type == "authorized_user"]
253
+
254
+ def list_service_account_token_files(self) -> list[TokenFile]:
255
+ """
256
+ List all service account token files
257
+ """
258
+ return [token_file for token_file in self.list_token_files() if token_file.type == "service_account"]
227
259
 
228
260
  def set_last_update_check_time(self, timestamp: str) -> None:
229
261
  """
@@ -233,78 +265,46 @@ class Settings:
233
265
  state.last_update_check_time = timestamp
234
266
  self._write_state_file(state)
235
267
 
236
- def _list_personal_tokens(self) -> list[TokenFileMetadata]:
237
- return self._list_token_files(prefix=tf.PERSONAL_TOKEN_FILE_PREFIX)
238
-
239
- def _list_service_account_tokens(self) -> list[TokenFileMetadata]:
240
- return self._list_token_files(prefix=tf.SERVICE_ACCOUNT_TOKEN_FILE_PREFIX)
241
-
242
- def _get_token_by_name(self, name: str) -> TokenFileMetadata:
243
- token_files = self._list_token_files()
244
- matches = [token_file for token_file in token_files if token_file[0].name == name]
245
- if len(matches) != 1:
246
- raise TokenNotFoundError(f"Ambiguous token file name {name}, found {len(matches)} files")
247
- return matches[0]
248
-
249
- def _list_token_files(self, prefix: str = "") -> list[TokenFileMetadata]:
268
+ def _get_token_by_name(self, name: str) -> TokenFile | None:
250
269
  """
251
- list all tokens with the correct prefix in the config dir, but omit files that are not token files
252
-
253
- TODO: improve is_valid_json and is_valid_token_file using token_file parsing instead
270
+ Token name is only available as a property of TokenFile, so we must iterate over all tokens to find the right one
254
271
  """
272
+ token_files = self.list_token_files()
273
+ matches = [token_file for token_file in token_files if token_file.name == name]
274
+ if len(matches) != 1:
275
+ return None
276
+ return matches[0]
255
277
 
256
- def is_valid_json(path: Path) -> bool:
257
- try:
258
- self._read_token_file(path)
259
- return True
260
- except (JSONDecodeError, ValidationError):
261
- # TODO - this should be printed but printing it here causes it to be displayed to many times
262
- # err_console.print(f"File is not valid json, skipping. {path}")
263
- return False
264
-
265
- def is_valid_token_file(path: Path) -> bool:
266
- is_token_file = path.name.startswith(tf.SERVICE_ACCOUNT_TOKEN_FILE_PREFIX) or path.name.startswith(
267
- tf.PERSONAL_TOKEN_FILE_PREFIX
268
- )
269
- has_correct_prefix = path.is_file() and path.name.startswith(prefix)
270
- is_cli_config = path == self.config_file_path
271
- is_present_in_cli_config_accounts = any(
272
- path.name == account.credentials_file for account in self.get_cli_config().accounts.values()
273
- )
274
- return is_token_file and is_valid_json(path) and has_correct_prefix and not is_cli_config and is_present_in_cli_config_accounts
275
-
276
- paths = [path for path in self.config_dir.iterdir() if is_valid_token_file(path)]
277
- return [(self._read_token_file(token_file), token_file) for token_file in paths]
278
-
279
- def _read_token_file(self, path: Path) -> TokenFile:
278
+ def _read_token_file(self, file_name: str) -> TokenFile:
279
+ path = self.config_dir / file_name
280
280
  data = self._read_file(path)
281
281
  return tf.loads(data)
282
282
 
283
+ def _write_token_file(self, path: Path, token: TokenFile) -> Path:
284
+ data = tf.dumps(token)
285
+ return self._write_file(path, data)
286
+
283
287
  def _read_config_file(self) -> ConfigFile:
284
288
  data = self._read_file(self.config_file_path)
285
289
  return cf.loads(data)
286
290
 
291
+ def _write_config_file(self, config: ConfigFile) -> Path:
292
+ data = cf.dumps(config)
293
+ return self._write_file(self.config_file_path, data)
294
+
287
295
  def _read_state_file(self) -> StateFile:
288
296
  data = self._read_file(self.state_file_path)
289
297
  return sf.loads(data)
290
298
 
299
+ def _write_state_file(self, state: StateFile) -> Path:
300
+ data = sf.dumps(state)
301
+ return self._write_file(self.state_file_path, data)
302
+
291
303
  def _read_file(self, path: Path) -> str:
292
304
  if not path.exists():
293
305
  raise FileNotFoundError(f"File could not be found: {path}")
294
306
  return path.read_text(encoding="utf-8")
295
307
 
296
- def _write_token_file(self, path: Path, token: TokenFile) -> Path:
297
- data = tf.dumps(token)
298
- return self._write_file(path, data)
299
-
300
- def _write_config_file(self, config: ConfigFile) -> Path:
301
- data = cf.dumps(config)
302
- return self._write_file(self.config_file_path, data)
303
-
304
- def _write_state_file(self, state: StateFile) -> Path:
305
- data = sf.dumps(state)
306
- return self._write_file(self.state_file_path, data)
307
-
308
308
  def _write_file(self, path: Path, data: str) -> Path:
309
309
  if self.config_dir not in path.parents:
310
310
  raise InvalidSettingsFilePathError(f"file {path} not in settings dir {self.config_dir}")
@@ -6,7 +6,7 @@ from pathlib import Path
6
6
  from typing import Any, Optional
7
7
 
8
8
  from cli.settings.config_file import ConfigFile, loads
9
- from cli.settings.core import Settings, TokenNotFoundError
9
+ from cli.settings.core import Settings
10
10
  from cli.settings.migration.migration_tools import get_token_file
11
11
 
12
12
 
@@ -21,13 +21,20 @@ def migrate_account_data(config: dict[str, Any], settings: Settings) -> Optional
21
21
  cred_name = account_info.pop("credentials_name", None)
22
22
  if not cred_name:
23
23
  continue
24
+
25
+ # found legacy account, try to migrate it, or drop it...
24
26
  found_old = True
25
- try:
26
- cred_file = get_token_file(cred_name, settings.config_dir).get_token_file_name()
27
- except TokenNotFoundError:
28
- # schedule this account for removal
27
+
28
+ token_file = get_token_file(cred_name, settings.config_dir)
29
+ if not token_file:
30
+ sys.stderr.write(f"Dropping account {account_email!r}: credentials file for {cred_name} not found")
31
+ to_delete.append(account_email)
32
+ continue
33
+
34
+ cred_file = token_file.get_token_file_name()
35
+ if not cred_file:
36
+ sys.stderr.write(f"Dropping account {account_email!r}: credentials file for {cred_name} not found")
29
37
  to_delete.append(account_email)
30
- sys.stderr.write(f"Dropping account {account_email!r}: token file for {cred_name} not found")
31
38
  continue
32
39
 
33
40
  account_info["credentials_file"] = cred_file
@@ -1,8 +1,10 @@
1
+ from __future__ import annotations
2
+
1
3
  from itertools import chain
2
4
  from pathlib import Path
3
5
 
4
- from cli.settings.core import TokenNotFoundError
5
6
  from cli.settings.token_file import TokenFile
7
+ from cli.utils.console import print_generic_message
6
8
 
7
9
 
8
10
  def list_token_files(config_dir: Path) -> list[TokenFile]:
@@ -19,11 +21,11 @@ def list_token_files(config_dir: Path) -> list[TokenFile]:
19
21
  token_file = TokenFile.from_json_str(file.read_text())
20
22
  token_files.append(token_file)
21
23
  except Exception:
22
- print(f"warning: invalid token file {file}. Consider removing it.")
24
+ print_generic_message(f"warning: invalid token file {file}. Consider removing it.")
23
25
  return token_files
24
26
 
25
27
 
26
- def get_token_file(cred_name: str, config_dir: Path) -> TokenFile:
28
+ def get_token_file(cred_name: str, config_dir: Path) -> TokenFile | None:
27
29
  """
28
30
  Get the token file for a given credentials name.
29
31
 
@@ -32,5 +34,5 @@ def get_token_file(cred_name: str, config_dir: Path) -> TokenFile:
32
34
  token_files = list_token_files(config_dir)
33
35
  matches = [token_file for token_file in token_files if token_file.name == cred_name]
34
36
  if len(matches) != 1:
35
- raise TokenNotFoundError(f"Token file for {cred_name} not found")
37
+ return None
36
38
  return matches[0]
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
- from datetime import datetime
3
+ import os
4
+ from datetime import datetime, timedelta
4
5
  from typing import Any, Optional
5
6
 
6
7
  from pydantic import BaseModel
@@ -10,9 +11,7 @@ from cli.utils.time import parse_datetime
10
11
 
11
12
  class StateFile(BaseModel):
12
13
  """
13
- StateFile represents the state file for the CLI.
14
-
15
- TODO: Should all setters return a new instance of the StateFile?
14
+ Contains CLI state and other application specific data.
16
15
  """
17
16
 
18
17
  version: str = "1.0"
@@ -23,8 +22,17 @@ class StateFile(BaseModel):
23
22
  Check if we should perform an update check.
24
23
 
25
24
  Returns True if the last update check time is older than 2 hours.
25
+
26
+ For Docker environments, returns False and sets a backdated timestamp
27
+ to prevent constant update checks due to ephemeral disks.
26
28
  """
27
29
  if not self.last_update_check_time:
30
+ if os.environ.get("RUNS_IN_DOCKER"):
31
+ # To prevent that we always check update in docker due to ephemeral disks we write an "old" check if the state
32
+ # is missing. If no disk is mounted we will never get the update check but if its mounted properly we will get
33
+ # it on the second attempt. This is good enough
34
+ self.last_update_check_time = (datetime.now() - timedelta(hours=10)).isoformat()
35
+ return False
28
36
  return True # Returning True will trigger a check, which will properly set last_update_check_time
29
37
 
30
38
  seconds = (datetime.now() - parse_datetime(self.last_update_check_time)).seconds
cli/tools/can/can.py CHANGED
@@ -2,12 +2,9 @@ from pathlib import Path
2
2
 
3
3
  import can
4
4
  import typer
5
- from rich.console import Console
6
5
 
7
6
  from cli.typer import typer_utils
8
-
9
- err_console = Console(stderr=True)
10
- console = Console()
7
+ from cli.utils.console import print_generic_error, print_success
11
8
 
12
9
  HELP = """
13
10
  CAN related tools
@@ -49,7 +46,7 @@ def convert(
49
46
  for msg in reader:
50
47
  writer.on_message_received(msg)
51
48
  except Exception as e:
52
- err_console.print(f":boom: [bold red]Failed to convert file[/bold red]: {e}")
49
+ print_generic_error(f"Failed to convert file: {e}")
53
50
 
54
51
 
55
52
  @app.command("validate")
@@ -76,6 +73,6 @@ def validate(
76
73
  for msg in reader:
77
74
  if print_to_terminal:
78
75
  writer.on_message_received(msg)
79
- console.print(f"Successfully verified {in_file}")
76
+ print_success(f"{in_file} verified")
80
77
  except Exception as e:
81
- err_console.print(f":boom: [bold red]Failed to convert file[/bold red]: {e}")
78
+ print_generic_error(f"Failed to convert file: {e}")
@@ -0,0 +1,3 @@
1
+ from cli.topology.cmd import app
2
+
3
+ __all__ = ["app"]