opensees-cli 0.2.5__tar.gz → 0.3.0__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.
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/PKG-INFO +2 -2
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/README.md +1 -1
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/pyproject.toml +1 -1
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli/__init__.py +1 -1
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli/auth.py +90 -10
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli/files.py +198 -17
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli/main.py +4 -21
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli/run.py +117 -48
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli.egg-info/PKG-INFO +2 -2
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli.egg-info/SOURCES.txt +0 -2
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/tests/test_files_commands.py +8 -3
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/tests/test_main_commands.py +3 -3
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/tests/test_run_commands.py +104 -8
- opensees_cli-0.2.5/src/opensees_cli/admin.py +0 -587
- opensees_cli-0.2.5/tests/test_admin_commands.py +0 -296
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/setup.cfg +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli/__main__.py +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli/api.py +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli/config.py +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli/path_setup.py +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli/version.py +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli.egg-info/dependency_links.txt +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli.egg-info/entry_points.txt +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli.egg-info/requires.txt +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/src/opensees_cli.egg-info/top_level.txt +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/tests/test_api.py +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/tests/test_auth_commands.py +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/tests/test_config.py +0 -0
- {opensees_cli-0.2.5 → opensees_cli-0.3.0}/tests/test_version_commands.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: opensees_cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Run OpenSees simulations in the cloud from the command line.
|
|
5
5
|
Author: Minjie Zhu
|
|
6
6
|
License: Proprietary
|
|
@@ -115,7 +115,7 @@ ops run help
|
|
|
115
115
|
### `run submit` options
|
|
116
116
|
|
|
117
117
|
- `file` (required positional): local path to a `.py` file (uploaded if the path exists under its filename), or a cloud path such as `model.py` or `lab/model.py`
|
|
118
|
-
- `--timeout`, `-t`: max wall time per task in seconds (default `120`).
|
|
118
|
+
- `--timeout`, `-t`: max wall time per task in seconds (default `120`). Monthly usage must cover `timeout ×` number of tasks `×` RAM. Runs above **900s** use Fargate when configured; otherwise the **900s** Lambda limit applies.
|
|
119
119
|
- `--wait`, `-w`: wait and stream output until completion (default: return immediately with the analysis ID on stdout; progress on stderr)
|
|
120
120
|
|
|
121
121
|
Validation enforced by CLI (local uploads):
|
|
@@ -92,7 +92,7 @@ ops run help
|
|
|
92
92
|
### `run submit` options
|
|
93
93
|
|
|
94
94
|
- `file` (required positional): local path to a `.py` file (uploaded if the path exists under its filename), or a cloud path such as `model.py` or `lab/model.py`
|
|
95
|
-
- `--timeout`, `-t`: max wall time per task in seconds (default `120`).
|
|
95
|
+
- `--timeout`, `-t`: max wall time per task in seconds (default `120`). Monthly usage must cover `timeout ×` number of tasks `×` RAM. Runs above **900s** use Fargate when configured; otherwise the **900s** Lambda limit applies.
|
|
96
96
|
- `--wait`, `-w`: wait and stream output until completion (default: return immediately with the analysis ID on stdout; progress on stderr)
|
|
97
97
|
|
|
98
98
|
Validation enforced by CLI (local uploads):
|
|
@@ -268,13 +268,35 @@ def _fmt_bytes_precise(n: float) -> str:
|
|
|
268
268
|
return f"{n:.2f} GB"
|
|
269
269
|
|
|
270
270
|
|
|
271
|
+
def _fmt_usage(n: float) -> str:
|
|
272
|
+
n = float(n or 0)
|
|
273
|
+
if abs(n - round(n)) < 0.05:
|
|
274
|
+
return str(int(round(n)))
|
|
275
|
+
return f"{n:.1f}"
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _usage_parts(q: dict) -> tuple:
|
|
279
|
+
maximum = q.get("max_monthly_usage")
|
|
280
|
+
if maximum is None:
|
|
281
|
+
maximum = q.get("max_monthly_runtime", 0)
|
|
282
|
+
used = q.get("monthly_usage_used")
|
|
283
|
+
if used is None:
|
|
284
|
+
used = q.get("monthly_runtime_used", 0)
|
|
285
|
+
reserved = q.get("monthly_usage_reserved")
|
|
286
|
+
if reserved is None:
|
|
287
|
+
reserved = q.get("monthly_runtime_reserved", 0)
|
|
288
|
+
remaining = q.get("monthly_usage_remaining")
|
|
289
|
+
if remaining is None:
|
|
290
|
+
remaining = q.get("monthly_runtime_remaining")
|
|
291
|
+
if remaining is None:
|
|
292
|
+
remaining = max(0, float(maximum or 0) - float(used or 0) - float(reserved or 0))
|
|
293
|
+
return maximum or 0, used or 0, reserved or 0, remaining
|
|
294
|
+
|
|
295
|
+
|
|
271
296
|
def print_quota(q: dict) -> None:
|
|
272
297
|
"""Print quota info to the console."""
|
|
273
|
-
max_rt = q
|
|
274
|
-
used = q.get("monthly_runtime_used", 0)
|
|
275
|
-
reserved = q.get("monthly_runtime_reserved", 0)
|
|
298
|
+
max_rt, used, reserved, remaining = _usage_parts(q)
|
|
276
299
|
committed = used + reserved
|
|
277
|
-
remaining = q.get("monthly_runtime_remaining", 0)
|
|
278
300
|
pct = (committed / max_rt * 100) if max_rt else 0
|
|
279
301
|
rt_color = "green" if pct < 75 else ("yellow" if pct < 90 else "red")
|
|
280
302
|
|
|
@@ -284,37 +306,75 @@ def print_quota(q: dict) -> None:
|
|
|
284
306
|
st_pct = (st_used / max_st * 100) if max_st else 0
|
|
285
307
|
st_color = "green" if st_pct < 75 else ("yellow" if st_pct < 90 else "red")
|
|
286
308
|
|
|
309
|
+
shared_by = _shared_by_phrase(q.get("shared_by") or [])
|
|
310
|
+
share = _share_phrase(q.get("share") or "")
|
|
311
|
+
if shared_by:
|
|
312
|
+
console.print(f" {shared_by}")
|
|
313
|
+
elif share:
|
|
314
|
+
console.print(f" {share}")
|
|
287
315
|
console.print(f" Concurrent tasks: {q.get('max_concurrent_runs', '-')}")
|
|
288
316
|
console.print(f" Tasks/analysis: {q.get('max_tasks_per_analysis', '-')}")
|
|
289
317
|
console.print(f" Max task timeout: {_fmt_duration(q['max_task_timeout']) if q.get('max_task_timeout') else '-'}")
|
|
318
|
+
console.print(f" Max RAM: {_fmt_bytes((q.get('max_ram_mb') or 1024) * 1024 * 1024)}")
|
|
290
319
|
console.print(f" Max storage/task: {_fmt_bytes(q['max_storage_per_task']) if q.get('max_storage_per_task') else '-'}")
|
|
291
320
|
if reserved > 0:
|
|
292
321
|
console.print(
|
|
293
|
-
f" Monthly
|
|
294
|
-
f" + {
|
|
295
|
-
f" / {
|
|
322
|
+
f" Monthly usage: [{rt_color}]{_fmt_usage(used)} settled"
|
|
323
|
+
f" + {_fmt_usage(reserved)} in-flight[/{rt_color}]"
|
|
324
|
+
f" / {_fmt_usage(max_rt)} ({pct:.0f}% committed)"
|
|
296
325
|
)
|
|
297
326
|
else:
|
|
298
|
-
console.print(f" Monthly
|
|
299
|
-
console.print(f"
|
|
327
|
+
console.print(f" Monthly usage: [{rt_color}]{_fmt_usage(used)}[/{rt_color}] / {_fmt_usage(max_rt)} ({pct:.0f}% used)")
|
|
328
|
+
console.print(f" Usage left: {_fmt_usage(remaining)}")
|
|
300
329
|
if q.get("next_reset_at"):
|
|
301
330
|
console.print(f" Next cycle: {_to_local_date(q['next_reset_at'])}")
|
|
302
331
|
else:
|
|
303
332
|
console.print(" Next cycle: [dim]—[/dim]")
|
|
304
|
-
|
|
333
|
+
members = q.get("storage_members") or []
|
|
334
|
+
if members:
|
|
335
|
+
sharing = ", ".join(
|
|
336
|
+
f"{member.get('email') or 'user'} {_fmt_bytes(member.get('storage_used') or 0)}"
|
|
337
|
+
for member in members
|
|
338
|
+
)
|
|
339
|
+
console.print(f" Sharing users: {sharing}")
|
|
340
|
+
console.print(f" Own storage: {_fmt_bytes(q.get('storage_own') or 0)}")
|
|
341
|
+
console.print(f" Total storage: [{st_color}]{_fmt_bytes(st_used)}[/{st_color}] / {_fmt_bytes(max_st)} ({st_pct:.0f}% used)")
|
|
342
|
+
else:
|
|
343
|
+
console.print(f" Storage: [{st_color}]{_fmt_bytes(st_used)}[/{st_color}] / {_fmt_bytes(max_st)} ({st_pct:.0f}% used)")
|
|
305
344
|
st_left_str = _fmt_bytes(st_remaining)
|
|
306
345
|
if st_left_str == _fmt_bytes(max_st) and st_remaining < max_st:
|
|
307
346
|
st_left_str = _fmt_bytes_precise(st_remaining)
|
|
308
347
|
console.print(f" Storage left: {st_left_str}")
|
|
348
|
+
dropbox = q.get("dropbox") or {}
|
|
349
|
+
if dropbox.get("linked"):
|
|
350
|
+
used_bytes = int(dropbox.get("used") or 0)
|
|
351
|
+
allocated = int(dropbox.get("allocated") or 0)
|
|
352
|
+
if dropbox.get("space_error"):
|
|
353
|
+
console.print(f" Dropbox: [yellow]{dropbox['space_error']}[/yellow]")
|
|
354
|
+
elif allocated:
|
|
355
|
+
console.print(f" Dropbox: {_fmt_bytes(used_bytes)} / {_fmt_bytes(allocated)}")
|
|
356
|
+
else:
|
|
357
|
+
console.print(f" Dropbox: {_fmt_bytes(used_bytes)} used")
|
|
358
|
+
if dropbox.get("folder_error"):
|
|
359
|
+
console.print(f" Files on Dropbox: [yellow]{dropbox['folder_error']}[/yellow]")
|
|
360
|
+
elif "folder_bytes" in dropbox:
|
|
361
|
+
console.print(f" Files on Dropbox: {_fmt_bytes(int(dropbox.get('folder_bytes') or 0))}")
|
|
309
362
|
|
|
310
363
|
|
|
311
364
|
def quota_to_json_obj(q: dict) -> Dict[str, Any]:
|
|
312
365
|
"""Quota fields as a plain dict (shared by ``ops status --json``)."""
|
|
313
366
|
return {
|
|
367
|
+
"share": _share_phrase(q.get("share") or ""),
|
|
368
|
+
"shared_by": _shared_by_phrase(q.get("shared_by") or []),
|
|
314
369
|
"max_concurrent_runs": q.get("max_concurrent_runs"),
|
|
315
370
|
"max_tasks_per_analysis": q.get("max_tasks_per_analysis"),
|
|
316
371
|
"max_task_timeout": q.get("max_task_timeout"),
|
|
372
|
+
"max_ram_mb": q.get("max_ram_mb") if q.get("max_ram_mb") is not None else 1024,
|
|
317
373
|
"max_storage_per_task": q.get("max_storage_per_task"),
|
|
374
|
+
"max_monthly_usage": _usage_parts(q)[0],
|
|
375
|
+
"monthly_usage_used": _usage_parts(q)[1],
|
|
376
|
+
"monthly_usage_reserved": _usage_parts(q)[2],
|
|
377
|
+
"monthly_usage_remaining": _usage_parts(q)[3],
|
|
318
378
|
"max_monthly_runtime": q.get("max_monthly_runtime"),
|
|
319
379
|
"monthly_runtime_used": q.get("monthly_runtime_used"),
|
|
320
380
|
"monthly_runtime_reserved": q.get("monthly_runtime_reserved"),
|
|
@@ -322,7 +382,10 @@ def quota_to_json_obj(q: dict) -> Dict[str, Any]:
|
|
|
322
382
|
"next_reset_at": _to_local_date(q["next_reset_at"]) if q.get("next_reset_at") else None,
|
|
323
383
|
"max_monthly_storage": q.get("max_monthly_storage"),
|
|
324
384
|
"storage_used": q.get("storage_used"),
|
|
385
|
+
"storage_own": q.get("storage_own"),
|
|
386
|
+
"storage_members": q.get("storage_members") or [],
|
|
325
387
|
"storage_remaining": max(0, (q.get("max_monthly_storage") or 0) - (q.get("storage_used") or 0)),
|
|
388
|
+
"dropbox": q.get("dropbox") or {"linked": False},
|
|
326
389
|
}
|
|
327
390
|
|
|
328
391
|
|
|
@@ -331,6 +394,17 @@ def format_quota_json(q: dict) -> str:
|
|
|
331
394
|
return json.dumps(quota_to_json_obj(q), indent=2) + "\n"
|
|
332
395
|
|
|
333
396
|
|
|
397
|
+
def _share_phrase(email: str) -> str:
|
|
398
|
+
"""``Share email's quota`` when this account spends someone else's quota."""
|
|
399
|
+
return f"Share {email}'s quota" if email else ""
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
def _shared_by_phrase(emails) -> str:
|
|
403
|
+
"""``Shared by a, b`` when other accounts spend this primary's quota."""
|
|
404
|
+
names = [str(email) for email in emails if email]
|
|
405
|
+
return "Shared by " + ", ".join(names) if names else ""
|
|
406
|
+
|
|
407
|
+
|
|
334
408
|
def print_me(
|
|
335
409
|
r: Dict[str, Any],
|
|
336
410
|
*,
|
|
@@ -344,6 +418,8 @@ def print_me(
|
|
|
344
418
|
console.print(f" Email: [bold]{r.get('email', '')}[/bold]")
|
|
345
419
|
console.print(f" Admin: {'[yellow]yes[/yellow]' if r.get('is_admin') else 'no'}")
|
|
346
420
|
console.print(f" Enabled: {'[green]yes[/green]' if r.get('is_enabled') else '[red]no[/red]'}")
|
|
421
|
+
console.print(f" Org: {r.get('org') or ''}")
|
|
422
|
+
console.print(f" Primary: {'yes' if r.get('is_primary') else 'no'}")
|
|
347
423
|
signup_raw = r.get("signup_at") or r.get("created_at")
|
|
348
424
|
if signup_raw:
|
|
349
425
|
console.print(f" Signup time: {_to_local(signup_raw)}")
|
|
@@ -368,6 +444,8 @@ def format_status_plain(
|
|
|
368
444
|
f"email: {r.get('email', '')}",
|
|
369
445
|
f"admin: {'yes' if r.get('is_admin') else 'no'}",
|
|
370
446
|
f"enabled: {'yes' if r.get('is_enabled') else 'no'}",
|
|
447
|
+
f"org: {r.get('org') or ''}",
|
|
448
|
+
f"primary: {'yes' if r.get('is_primary') else 'no'}",
|
|
371
449
|
]
|
|
372
450
|
signup_raw = r.get("signup_at") or r.get("created_at")
|
|
373
451
|
lines.append(f"signup_time: {_to_local(signup_raw) if signup_raw else ''}")
|
|
@@ -393,6 +471,8 @@ def format_status_json(
|
|
|
393
471
|
"email": r.get("email") or "",
|
|
394
472
|
"admin": bool(r.get("is_admin")),
|
|
395
473
|
"enabled": bool(r.get("is_enabled")),
|
|
474
|
+
"org": r.get("org") or "",
|
|
475
|
+
"primary": bool(r.get("is_primary")),
|
|
396
476
|
"signup_time": _to_local(signup_raw) if signup_raw else None,
|
|
397
477
|
"last_login": _to_local(r["last_login_at"]) if r.get("last_login_at") else None,
|
|
398
478
|
"last_active": _to_local(r["last_activity_at"]) if r.get("last_activity_at") else None,
|
|
@@ -65,7 +65,7 @@ def list_files(
|
|
|
65
65
|
is_flag=True,
|
|
66
66
|
),
|
|
67
67
|
):
|
|
68
|
-
"""List files. With FOLDER, only show files under that path.
|
|
68
|
+
"""List files. With FOLDER, only show files under that path. An empty list still prints the table."""
|
|
69
69
|
try:
|
|
70
70
|
items = _files_list_items(folder)
|
|
71
71
|
# Older APIs ignore ?folder= — filter locally so the CLI still works.
|
|
@@ -95,9 +95,6 @@ def list_files(
|
|
|
95
95
|
typer.echo(json.dumps(obj, indent=2).rstrip("\n"))
|
|
96
96
|
return
|
|
97
97
|
|
|
98
|
-
if not items:
|
|
99
|
-
return
|
|
100
|
-
|
|
101
98
|
table = Table(show_header=True)
|
|
102
99
|
table.add_column("Path")
|
|
103
100
|
table.add_column("Size", justify="right")
|
|
@@ -143,8 +140,8 @@ def _collect_upload_targets(local_path: Path, folder: Optional[str]) -> List[Tup
|
|
|
143
140
|
return []
|
|
144
141
|
|
|
145
142
|
|
|
146
|
-
def _upload_one(local: Path, remote: str) ->
|
|
147
|
-
"""Upload a single file.
|
|
143
|
+
def _upload_one(local: Path, remote: str) -> bool:
|
|
144
|
+
"""Upload a single file. True when the bytes were written to the cloud library."""
|
|
148
145
|
import httpx
|
|
149
146
|
file_size = local.stat().st_size
|
|
150
147
|
content_type = "text/x-python" if remote.endswith(".py") else "application/octet-stream"
|
|
@@ -155,16 +152,36 @@ def _upload_one(local: Path, remote: str) -> int:
|
|
|
155
152
|
raise
|
|
156
153
|
|
|
157
154
|
file_bytes = local.read_bytes()
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
155
|
+
ticket = r.get("dropbox_upload")
|
|
156
|
+
if ticket:
|
|
157
|
+
import json as _json
|
|
158
|
+
arg = _json.dumps({
|
|
159
|
+
"path": ticket["path"],
|
|
160
|
+
"mode": "overwrite",
|
|
161
|
+
"autorename": False,
|
|
162
|
+
"mute": True,
|
|
163
|
+
})
|
|
164
|
+
resp = httpx.post(
|
|
165
|
+
ticket["url"],
|
|
166
|
+
content=file_bytes,
|
|
167
|
+
headers={
|
|
168
|
+
"Authorization": f"Bearer {ticket['token']}",
|
|
169
|
+
"Dropbox-API-Arg": arg,
|
|
170
|
+
"Content-Type": "application/octet-stream",
|
|
171
|
+
},
|
|
172
|
+
timeout=120.0,
|
|
173
|
+
)
|
|
174
|
+
else:
|
|
175
|
+
resp = httpx.put(
|
|
176
|
+
r["upload_url"],
|
|
177
|
+
content=file_bytes,
|
|
178
|
+
headers={"Content-Type": content_type},
|
|
179
|
+
timeout=60.0,
|
|
180
|
+
follow_redirects=True,
|
|
181
|
+
)
|
|
165
182
|
if not (200 <= resp.status_code < 300):
|
|
166
183
|
raise api.ApiError(f"Upload failed (HTTP {resp.status_code})", resp.status_code)
|
|
167
|
-
return
|
|
184
|
+
return ticket is None
|
|
168
185
|
|
|
169
186
|
|
|
170
187
|
def _resolve_download_targets(files: List[dict], pattern: str) -> List[dict]:
|
|
@@ -199,9 +216,9 @@ def _resolve_download_targets(files: List[dict], pattern: str) -> List[dict]:
|
|
|
199
216
|
@app.command()
|
|
200
217
|
def upload(
|
|
201
218
|
local_paths: List[Path] = typer.Argument(..., help="Local file(s) or folder(s) to upload (globs are expanded by the shell)"),
|
|
202
|
-
folder: Optional[str] = typer.Option(None, "--folder", "-f", help="Remote folder to upload into (
|
|
219
|
+
folder: Optional[str] = typer.Option(None, "--folder", "-f", help="Remote folder to upload into (required unless every file is already under a folder)"),
|
|
203
220
|
):
|
|
204
|
-
"""Upload a file or folder
|
|
221
|
+
"""Upload a file or folder. Every file must land inside a cloud folder."""
|
|
205
222
|
missing = [p for p in local_paths if not p.exists()]
|
|
206
223
|
if missing:
|
|
207
224
|
for p in missing:
|
|
@@ -214,6 +231,11 @@ def upload(
|
|
|
214
231
|
if not targets:
|
|
215
232
|
console.print("[red]Nothing to upload.[/red]")
|
|
216
233
|
raise typer.Exit(1)
|
|
234
|
+
root_files = [remote for _, remote in targets if "/" not in remote]
|
|
235
|
+
if root_files:
|
|
236
|
+
console.print("[red]Upload into a folder.[/red]")
|
|
237
|
+
console.print(" [dim]ops files upload model.py --folder lab[/dim]")
|
|
238
|
+
raise typer.Exit(1)
|
|
217
239
|
|
|
218
240
|
try:
|
|
219
241
|
listed = api.get("/files/list")
|
|
@@ -242,6 +264,7 @@ def upload(
|
|
|
242
264
|
|
|
243
265
|
total_bytes = sum(f.stat().st_size for f, _ in targets)
|
|
244
266
|
multi = len(targets) > 1
|
|
267
|
+
wrote_cloud = False
|
|
245
268
|
|
|
246
269
|
with Progress(
|
|
247
270
|
"[progress.description]{task.description}",
|
|
@@ -256,7 +279,8 @@ def upload(
|
|
|
256
279
|
fsize = local.stat().st_size
|
|
257
280
|
task = progress.add_task(remote, total=fsize)
|
|
258
281
|
try:
|
|
259
|
-
_upload_one(local, remote)
|
|
282
|
+
if _upload_one(local, remote):
|
|
283
|
+
wrote_cloud = True
|
|
260
284
|
progress.advance(task, fsize)
|
|
261
285
|
if overall is not None:
|
|
262
286
|
progress.advance(overall, fsize)
|
|
@@ -266,6 +290,13 @@ def upload(
|
|
|
266
290
|
raise typer.Exit(1)
|
|
267
291
|
continue
|
|
268
292
|
|
|
293
|
+
if wrote_cloud:
|
|
294
|
+
try:
|
|
295
|
+
api.post("/files/complete", {})
|
|
296
|
+
except api.ApiError as e:
|
|
297
|
+
console.print(f"[red]Uploaded, but storage was not updated: {e.message}[/red]")
|
|
298
|
+
raise typer.Exit(1)
|
|
299
|
+
|
|
269
300
|
if multi:
|
|
270
301
|
console.print(f"[green]Uploaded {len(targets)} files ({_fmt_bytes(total_bytes)})[/green]")
|
|
271
302
|
else:
|
|
@@ -427,3 +458,153 @@ def delete(
|
|
|
427
458
|
console.print(f"[green]Deleted {targets[0]['path']}[/green]")
|
|
428
459
|
else:
|
|
429
460
|
console.print(f"[green]Deleted {deleted}/{total} file(s)[/green]")
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
dropbox_app = typer.Typer(help="Link a Dropbox account. Files and results are saved in Apps/OpenSeesCloud.")
|
|
464
|
+
app.add_typer(dropbox_app, name="dropbox")
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
def _listen_for_dropbox_code(redirect_uri: str, open_url: str, timeout: float = 180.0) -> dict:
|
|
468
|
+
"""Listen on the callback, then open Dropbox so the redirect is not missed."""
|
|
469
|
+
import threading
|
|
470
|
+
import webbrowser
|
|
471
|
+
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
472
|
+
from urllib.parse import parse_qs, urlparse
|
|
473
|
+
|
|
474
|
+
parsed = urlparse(redirect_uri)
|
|
475
|
+
host = parsed.hostname or "127.0.0.1"
|
|
476
|
+
port = parsed.port or 53682
|
|
477
|
+
path = parsed.path or "/callback"
|
|
478
|
+
box: dict = {}
|
|
479
|
+
|
|
480
|
+
class _Handler(BaseHTTPRequestHandler):
|
|
481
|
+
def do_GET(self): # noqa: N802
|
|
482
|
+
incoming = urlparse(self.path)
|
|
483
|
+
if incoming.path != path:
|
|
484
|
+
self.send_error(404)
|
|
485
|
+
return
|
|
486
|
+
box["query"] = parse_qs(incoming.query)
|
|
487
|
+
body = b"<html><body><p>Dropbox linked. You can close this window.</p></body></html>"
|
|
488
|
+
self.send_response(200)
|
|
489
|
+
self.send_header("Content-Type", "text/html")
|
|
490
|
+
self.send_header("Content-Length", str(len(body)))
|
|
491
|
+
self.end_headers()
|
|
492
|
+
self.wfile.write(body)
|
|
493
|
+
|
|
494
|
+
def log_message(self, fmt: str, *args) -> None:
|
|
495
|
+
return
|
|
496
|
+
|
|
497
|
+
try:
|
|
498
|
+
server = HTTPServer((host, port), _Handler)
|
|
499
|
+
except OSError as exc:
|
|
500
|
+
raise api.ApiError(f"Could not listen on {host}:{port} ({exc})") from exc
|
|
501
|
+
thread = threading.Thread(target=server.handle_request, daemon=True)
|
|
502
|
+
thread.start()
|
|
503
|
+
webbrowser.open(open_url)
|
|
504
|
+
thread.join(timeout)
|
|
505
|
+
server.server_close()
|
|
506
|
+
return box.get("query") or {}
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
@dropbox_app.command("link")
|
|
510
|
+
def dropbox_link():
|
|
511
|
+
"""Open Dropbox login and copy the existing library into Apps/OpenSeesCloud."""
|
|
512
|
+
try:
|
|
513
|
+
started = api.post("/files/dropbox/start", {})
|
|
514
|
+
except api.ApiError as e:
|
|
515
|
+
console.print(f"[red]{e.message}[/red]")
|
|
516
|
+
raise typer.Exit(1)
|
|
517
|
+
|
|
518
|
+
console.print("Opening Dropbox. Approve access to the OpenSeesCloud folder.")
|
|
519
|
+
console.print(f"[dim]{started['authorize_url']}[/dim]")
|
|
520
|
+
try:
|
|
521
|
+
query = _listen_for_dropbox_code(started["redirect_uri"], started["authorize_url"])
|
|
522
|
+
except api.ApiError as e:
|
|
523
|
+
console.print(f"[red]{e.message}[/red]")
|
|
524
|
+
raise typer.Exit(1)
|
|
525
|
+
error = (query.get("error_description") or query.get("error") or [""])[0]
|
|
526
|
+
code = (query.get("code") or [""])[0]
|
|
527
|
+
state = (query.get("state") or [""])[0]
|
|
528
|
+
if error or not code:
|
|
529
|
+
console.print(f"[red]Dropbox login did not finish.{(' ' + error) if error else ''}[/red]")
|
|
530
|
+
raise typer.Exit(1)
|
|
531
|
+
if state and state != started.get("state"):
|
|
532
|
+
console.print("[red]Dropbox login did not match this session.[/red]")
|
|
533
|
+
raise typer.Exit(1)
|
|
534
|
+
try:
|
|
535
|
+
done = api.post("/files/dropbox/finish", {"code": code, "state": started["state"]})
|
|
536
|
+
except api.ApiError as e:
|
|
537
|
+
console.print(f"[red]{e.message}[/red]")
|
|
538
|
+
raise typer.Exit(1)
|
|
539
|
+
|
|
540
|
+
if done.get("copy_error"):
|
|
541
|
+
console.print(f"[yellow]Linked. The copy stopped: {done['copy_error']}[/yellow]")
|
|
542
|
+
console.print("[dim]Run ops files dropbox copy to try the remaining files.[/dim]")
|
|
543
|
+
else:
|
|
544
|
+
console.print(f"[green]Linked. Copied {done.get('copied', 0)} file(s) to Dropbox.[/green]")
|
|
545
|
+
|
|
546
|
+
total = int(done.get("total") or 0)
|
|
547
|
+
if total <= 0:
|
|
548
|
+
return
|
|
549
|
+
delete_cloud = typer.confirm("Delete the cloud copies of these existing files?", default=False)
|
|
550
|
+
try:
|
|
551
|
+
api.post("/files/dropbox/cloud", {"keep": not delete_cloud})
|
|
552
|
+
except api.ApiError as e:
|
|
553
|
+
console.print(f"[red]{e.message}[/red]")
|
|
554
|
+
raise typer.Exit(1)
|
|
555
|
+
if delete_cloud:
|
|
556
|
+
console.print("[green]Cloud copies deleted. They no longer count toward storage.[/green]")
|
|
557
|
+
else:
|
|
558
|
+
console.print("[dim]Cloud copies kept. They count toward storage.[/dim]")
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
@dropbox_app.command("copy")
|
|
562
|
+
def dropbox_copy():
|
|
563
|
+
"""Copy the cloud library into Dropbox again. Existing Dropbox files are overwritten."""
|
|
564
|
+
try:
|
|
565
|
+
done = api.post("/files/dropbox/copy", {})
|
|
566
|
+
except api.ApiError as e:
|
|
567
|
+
console.print(f"[red]{e.message}[/red]")
|
|
568
|
+
raise typer.Exit(1)
|
|
569
|
+
console.print(f"[green]Copied {done.get('copied', 0)} file(s) to Dropbox.[/green]")
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
@dropbox_app.command("status")
|
|
573
|
+
def dropbox_status():
|
|
574
|
+
"""Show Dropbox plan space and the bytes stored in Apps/OpenSeesCloud."""
|
|
575
|
+
try:
|
|
576
|
+
info = api.get("/files/dropbox")
|
|
577
|
+
except api.ApiError as e:
|
|
578
|
+
console.print(f"[red]{e.message}[/red]")
|
|
579
|
+
raise typer.Exit(1)
|
|
580
|
+
if not info.get("linked"):
|
|
581
|
+
console.print("Dropbox is not linked.")
|
|
582
|
+
console.print("[dim]ops files dropbox link[/dim]")
|
|
583
|
+
return
|
|
584
|
+
if info.get("space_error"):
|
|
585
|
+
console.print(f"[yellow]{info['space_error']}[/yellow]")
|
|
586
|
+
else:
|
|
587
|
+
used = int(info.get("used") or 0)
|
|
588
|
+
allocated = int(info.get("allocated") or 0)
|
|
589
|
+
if allocated:
|
|
590
|
+
console.print(f"Dropbox: {_fmt_bytes(used)} / {_fmt_bytes(allocated)}")
|
|
591
|
+
else:
|
|
592
|
+
console.print(f"Dropbox: {_fmt_bytes(used)} used")
|
|
593
|
+
if info.get("folder_error"):
|
|
594
|
+
console.print(f"[yellow]{info['folder_error']}[/yellow]")
|
|
595
|
+
elif "folder_bytes" in info:
|
|
596
|
+
console.print(f"Files on Dropbox: {_fmt_bytes(int(info.get('folder_bytes') or 0))}")
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
@dropbox_app.command("unlink")
|
|
600
|
+
def dropbox_unlink():
|
|
601
|
+
"""Disconnect Dropbox. Files already in Dropbox stay there."""
|
|
602
|
+
if not typer.confirm("Disconnect Dropbox? Files already there stay in Dropbox.", default=False):
|
|
603
|
+
console.print("[dim]Cancelled.[/dim]")
|
|
604
|
+
raise typer.Exit(0)
|
|
605
|
+
try:
|
|
606
|
+
api.post("/files/dropbox/unlink", {})
|
|
607
|
+
except api.ApiError as e:
|
|
608
|
+
console.print(f"[red]{e.message}[/red]")
|
|
609
|
+
raise typer.Exit(1)
|
|
610
|
+
console.print("[green]Dropbox disconnected. New files and results stay in the cloud.[/green]")
|
|
@@ -12,7 +12,6 @@ from opensees_cli.auth import (
|
|
|
12
12
|
print_me,
|
|
13
13
|
print_quota,
|
|
14
14
|
)
|
|
15
|
-
from opensees_cli.admin import app as admin_app
|
|
16
15
|
from opensees_cli.run import app as run_app
|
|
17
16
|
from opensees_cli.files import app as files_app
|
|
18
17
|
from opensees_cli.version import app as version_app
|
|
@@ -68,7 +67,7 @@ def _open_sees_py_version_str() -> str:
|
|
|
68
67
|
|
|
69
68
|
app = typer.Typer(
|
|
70
69
|
name="ops",
|
|
71
|
-
help="Run OpenSees simulations in the cloud.",
|
|
70
|
+
help=f"Run OpenSees simulations in the cloud. CLI {__version__}.",
|
|
72
71
|
add_completion=False,
|
|
73
72
|
invoke_without_command=True,
|
|
74
73
|
context_settings={"help_option_names": ["-h", "--help"]},
|
|
@@ -78,12 +77,6 @@ app.add_typer(auth_app, name="auth")
|
|
|
78
77
|
app.add_typer(run_app, name="run")
|
|
79
78
|
app.add_typer(files_app, name="files")
|
|
80
79
|
app.add_typer(version_app, name="version")
|
|
81
|
-
# Admin typer: hidden from help unless logged-in admin; non-admins get "no such command" in admin callback.
|
|
82
|
-
app.add_typer(
|
|
83
|
-
admin_app,
|
|
84
|
-
name="admin",
|
|
85
|
-
hidden=not (api.has_stored_credentials() and config.is_admin()),
|
|
86
|
-
)
|
|
87
80
|
|
|
88
81
|
|
|
89
82
|
def _add_help_command(typer_app: typer.Typer) -> None:
|
|
@@ -102,7 +95,6 @@ _add_help_command(auth_app)
|
|
|
102
95
|
_add_help_command(run_app)
|
|
103
96
|
_add_help_command(files_app)
|
|
104
97
|
_add_help_command(version_app)
|
|
105
|
-
_add_help_command(admin_app)
|
|
106
98
|
|
|
107
99
|
|
|
108
100
|
def _print_help() -> None:
|
|
@@ -118,7 +110,7 @@ def _print_help() -> None:
|
|
|
118
110
|
console.print(" [bold]ops status[/bold] Account details and quota (--json / -j for JSON output)")
|
|
119
111
|
console.print()
|
|
120
112
|
console.print("[bold]ops run[/bold]\n")
|
|
121
|
-
console.print(" [bold]submit[/bold] <file> Submit an analysis (
|
|
113
|
+
console.print(" [bold]submit[/bold] <file> Submit an analysis (local file needs --folder)")
|
|
122
114
|
console.print(" [bold]follow[/bold] <id> Stream live output from a running task")
|
|
123
115
|
console.print(" [bold]list[/bold] List recent analyses")
|
|
124
116
|
console.print(" [bold]status[/bold] <id> [range] Analysis summary or per-task status")
|
|
@@ -126,27 +118,18 @@ def _print_help() -> None:
|
|
|
126
118
|
console.print(" [bold]stats[/bold] <id> [range] Task execution stats (runtime, RAM)")
|
|
127
119
|
console.print(" [bold]data[/bold] <id> [range] List or download task data files")
|
|
128
120
|
console.print(" [bold]cancel[/bold] <id> Cancel an analysis or task")
|
|
129
|
-
console.print(" [bold]clear[/bold] [id]
|
|
121
|
+
console.print(" [bold]clear[/bold] [id] Remove the saved output log (by ID or time range)")
|
|
130
122
|
console.print()
|
|
131
123
|
console.print("[bold]ops files[/bold]\n")
|
|
132
124
|
console.print(" [bold]list[/bold] List uploaded files (--json / -j)")
|
|
133
125
|
console.print(" [bold]upload[/bold] <path> Upload a file or folder")
|
|
134
126
|
console.print(" [bold]download[/bold] <path> Download file(s) or folder; quote globs: '*.csv'")
|
|
135
127
|
console.print(" [bold]delete[/bold] <path> Delete a file or folder")
|
|
128
|
+
console.print(" [bold]dropbox[/bold] Link Dropbox, show space, or disconnect")
|
|
136
129
|
console.print()
|
|
137
130
|
console.print("[bold]ops auth[/bold]\n")
|
|
138
131
|
console.print(" [bold]change-password[/bold] Change your password")
|
|
139
132
|
console.print(" [bold]logout[/bold] Log out")
|
|
140
|
-
if config.is_admin():
|
|
141
|
-
console.print()
|
|
142
|
-
console.print("[bold]ops admin[/bold]\n")
|
|
143
|
-
console.print(" [bold]list-users[/bold] List all users")
|
|
144
|
-
console.print(" [bold]user-info[/bold] Account details; run / files inspect that user")
|
|
145
|
-
console.print(" [bold]set-quota[/bold] Update a user's quota")
|
|
146
|
-
console.print(" [bold]enable-user[/bold] Re-enable a user")
|
|
147
|
-
console.print(" [bold]disable-user[/bold] Disable a user")
|
|
148
|
-
console.print(" [bold]delete-user[/bold] Delete a user")
|
|
149
|
-
console.print(" [bold]workers[/bold] Live Lambda + Fargate workers (--json / -j)")
|
|
150
133
|
else:
|
|
151
134
|
console.print(" Not logged in.\n")
|
|
152
135
|
console.print("[bold]Get started:[/bold]\n")
|