heliopuddle 0.1.0__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.
- heliopuddle/__init__.py +8 -0
- heliopuddle/cli.py +91 -0
- heliopuddle/cli_entry.py +31 -0
- heliopuddle/cli_file/__init__.py +29 -0
- heliopuddle/cli_file/app.py +14 -0
- heliopuddle/cli_file/commands_read.py +150 -0
- heliopuddle/cli_file/commands_update.py +115 -0
- heliopuddle/cli_file/commands_write.py +200 -0
- heliopuddle/cli_file/format.py +101 -0
- heliopuddle/cli_file/options.py +91 -0
- heliopuddle/cli_file/select.py +59 -0
- heliopuddle/cli_file/session.py +104 -0
- heliopuddle/cli_user.py +429 -0
- heliopuddle/client/__init__.py +63 -0
- heliopuddle/client/_base.py +234 -0
- heliopuddle/client/_content.py +160 -0
- heliopuddle/client/_files.py +278 -0
- heliopuddle/client/_http.py +92 -0
- heliopuddle/client/_renewer.py +147 -0
- heliopuddle/client/_rules.py +129 -0
- heliopuddle/client/_uploads.py +283 -0
- heliopuddle/client/_users.py +79 -0
- heliopuddle/client/auth.py +305 -0
- heliopuddle/client/client.py +127 -0
- heliopuddle/client/errors.py +105 -0
- heliopuddle/client/paging.py +64 -0
- heliopuddle/config/__init__.py +12 -0
- heliopuddle/config/loader.py +278 -0
- heliopuddle/config/models/__init__.py +59 -0
- heliopuddle/config/models/common.py +57 -0
- heliopuddle/config/models/project.py +205 -0
- heliopuddle/config/models/rules.py +221 -0
- heliopuddle/config/models/versioning.py +152 -0
- heliopuddle/durations.py +96 -0
- heliopuddle/globs.py +48 -0
- heliopuddle/pipelines/__init__.py +1 -0
- heliopuddle/preview/__init__.py +225 -0
- heliopuddle/preview/cdf.py +166 -0
- heliopuddle/preview/cells.py +214 -0
- heliopuddle/preview/parquet.py +73 -0
- heliopuddle/preview/streams.py +135 -0
- heliopuddle/preview/text.py +250 -0
- heliopuddle/pytest_plugin.py +36 -0
- heliopuddle/server/__init__.py +1 -0
- heliopuddle/server/api/__init__.py +60 -0
- heliopuddle/server/api/auth/__init__.py +17 -0
- heliopuddle/server/api/auth/_shared.py +26 -0
- heliopuddle/server/api/auth/config.py +24 -0
- heliopuddle/server/api/auth/me.py +23 -0
- heliopuddle/server/api/auth/password.py +43 -0
- heliopuddle/server/api/auth/token.py +97 -0
- heliopuddle/server/api/deps.py +250 -0
- heliopuddle/server/api/errors.py +130 -0
- heliopuddle/server/api/files/__init__.py +41 -0
- heliopuddle/server/api/files/_shared.py +34 -0
- heliopuddle/server/api/files/accept.py +70 -0
- heliopuddle/server/api/files/by_path.py +37 -0
- heliopuddle/server/api/files/check.py +40 -0
- heliopuddle/server/api/files/content.py +61 -0
- heliopuddle/server/api/files/content_date.py +41 -0
- heliopuddle/server/api/files/delete.py +64 -0
- heliopuddle/server/api/files/get.py +28 -0
- heliopuddle/server/api/files/list_files.py +82 -0
- heliopuddle/server/api/files/metadata.py +46 -0
- heliopuddle/server/api/files/preview.py +45 -0
- heliopuddle/server/api/files/register.py +117 -0
- heliopuddle/server/api/files/rules_ignore.py +40 -0
- heliopuddle/server/api/files/series_versions.py +42 -0
- heliopuddle/server/api/health/__init__.py +15 -0
- heliopuddle/server/api/health/check.py +61 -0
- heliopuddle/server/api/health/version.py +16 -0
- heliopuddle/server/api/projects/__init__.py +22 -0
- heliopuddle/server/api/projects/_shared.py +44 -0
- heliopuddle/server/api/projects/get_project.py +20 -0
- heliopuddle/server/api/projects/get_storage_location.py +40 -0
- heliopuddle/server/api/projects/list_projects.py +19 -0
- heliopuddle/server/api/projects/list_storage_locations.py +42 -0
- heliopuddle/server/api/repair.py +75 -0
- heliopuddle/server/api/rules/__init__.py +18 -0
- heliopuddle/server/api/rules/disable.py +25 -0
- heliopuddle/server/api/rules/enable.py +25 -0
- heliopuddle/server/api/rules/get.py +25 -0
- heliopuddle/server/api/rules/list_rules.py +25 -0
- heliopuddle/server/api/rules/trigger.py +25 -0
- heliopuddle/server/api/runs.py +89 -0
- heliopuddle/server/api/search/__init__.py +15 -0
- heliopuddle/server/api/search/project_summary.py +26 -0
- heliopuddle/server/api/search/search_files.py +73 -0
- heliopuddle/server/api/uploads/__init__.py +21 -0
- heliopuddle/server/api/uploads/_shared.py +24 -0
- heliopuddle/server/api/uploads/abort.py +40 -0
- heliopuddle/server/api/uploads/complete.py +61 -0
- heliopuddle/server/api/uploads/content.py +82 -0
- heliopuddle/server/api/uploads/renew.py +34 -0
- heliopuddle/server/api/uploads/reserve.py +103 -0
- heliopuddle/server/api/users/__init__.py +24 -0
- heliopuddle/server/api/users/_shared.py +42 -0
- heliopuddle/server/api/users/create_user.py +32 -0
- heliopuddle/server/api/users/delete_user.py +28 -0
- heliopuddle/server/api/users/get_user.py +20 -0
- heliopuddle/server/api/users/list_users.py +17 -0
- heliopuddle/server/api/users/update_user.py +42 -0
- heliopuddle/server/app.py +127 -0
- heliopuddle/server/auth/__init__.py +0 -0
- heliopuddle/server/auth/bootstrap.py +85 -0
- heliopuddle/server/auth/errors.py +17 -0
- heliopuddle/server/auth/local.py +44 -0
- heliopuddle/server/auth/oidc.py +297 -0
- heliopuddle/server/auth/passwords.py +37 -0
- heliopuddle/server/auth/principal.py +42 -0
- heliopuddle/server/auth/roles.py +120 -0
- heliopuddle/server/auth/secret.py +121 -0
- heliopuddle/server/auth/startup.py +31 -0
- heliopuddle/server/auth/throttle.py +122 -0
- heliopuddle/server/auth/tokens.py +126 -0
- heliopuddle/server/context.py +130 -0
- heliopuddle/server/database/__init__.py +1 -0
- heliopuddle/server/database/engine.py +185 -0
- heliopuddle/server/database/migrate.py +161 -0
- heliopuddle/server/database/migrations/env.py +60 -0
- heliopuddle/server/database/migrations/script.py.mako +28 -0
- heliopuddle/server/database/migrations/versions/0001_initial_schema.py +215 -0
- heliopuddle/server/database/orm.py +276 -0
- heliopuddle/server/models/__init__.py +110 -0
- heliopuddle/server/models/accept.py +127 -0
- heliopuddle/server/models/files/__init__.py +95 -0
- heliopuddle/server/models/files/copies.py +139 -0
- heliopuddle/server/models/files/delete.py +176 -0
- heliopuddle/server/models/files/errors.py +47 -0
- heliopuddle/server/models/files/query.py +281 -0
- heliopuddle/server/models/files/register.py +398 -0
- heliopuddle/server/models/files/update.py +121 -0
- heliopuddle/server/models/index/__init__.py +79 -0
- heliopuddle/server/models/index/accept.py +156 -0
- heliopuddle/server/models/index/copies.py +189 -0
- heliopuddle/server/models/index/progress.py +193 -0
- heliopuddle/server/models/index/removal.py +256 -0
- heliopuddle/server/models/index/targets.py +152 -0
- heliopuddle/server/models/projects.py +116 -0
- heliopuddle/server/models/rule_state.py +43 -0
- heliopuddle/server/models/rules.py +436 -0
- heliopuddle/server/models/search.py +270 -0
- heliopuddle/server/models/series.py +232 -0
- heliopuddle/server/models/snapshots.py +116 -0
- heliopuddle/server/models/transfers.py +433 -0
- heliopuddle/server/models/transitions.py +235 -0
- heliopuddle/server/models/uploads/__init__.py +71 -0
- heliopuddle/server/models/uploads/lifecycle.py +135 -0
- heliopuddle/server/models/uploads/reserve.py +171 -0
- heliopuddle/server/models/uploads/settle.py +308 -0
- heliopuddle/server/models/uploads/types.py +62 -0
- heliopuddle/server/models/users.py +237 -0
- heliopuddle/server/schemas/__init__.py +122 -0
- heliopuddle/server/schemas/auth.py +114 -0
- heliopuddle/server/schemas/files.py +210 -0
- heliopuddle/server/schemas/health.py +23 -0
- heliopuddle/server/schemas/preview.py +74 -0
- heliopuddle/server/schemas/projects.py +42 -0
- heliopuddle/server/schemas/reconcile.py +51 -0
- heliopuddle/server/schemas/rules.py +43 -0
- heliopuddle/server/schemas/runs.py +71 -0
- heliopuddle/server/schemas/search.py +53 -0
- heliopuddle/server/schemas/uploads.py +49 -0
- heliopuddle/server/security_headers.py +47 -0
- heliopuddle/server/services/__init__.py +1 -0
- heliopuddle/server/services/_prefect_child.py +40 -0
- heliopuddle/server/services/accept.py +74 -0
- heliopuddle/server/services/batches.py +55 -0
- heliopuddle/server/services/concurrency.py +106 -0
- heliopuddle/server/services/content.py +79 -0
- heliopuddle/server/services/delete.py +334 -0
- heliopuddle/server/services/deploy.py +499 -0
- heliopuddle/server/services/deploy_adopt.py +174 -0
- heliopuddle/server/services/deploy_prepare.py +230 -0
- heliopuddle/server/services/deploy_runner.py +120 -0
- heliopuddle/server/services/deploy_state.py +87 -0
- heliopuddle/server/services/index.py +360 -0
- heliopuddle/server/services/index_diff.py +339 -0
- heliopuddle/server/services/index_finish.py +161 -0
- heliopuddle/server/services/index_models.py +155 -0
- heliopuddle/server/services/index_names.py +56 -0
- heliopuddle/server/services/index_run.py +311 -0
- heliopuddle/server/services/index_sweep.py +88 -0
- heliopuddle/server/services/index_tasks.py +370 -0
- heliopuddle/server/services/preview.py +111 -0
- heliopuddle/server/services/reconcile.py +223 -0
- heliopuddle/server/services/rule_checkpoint.py +200 -0
- heliopuddle/server/services/rule_control.py +298 -0
- heliopuddle/server/services/rule_lookup.py +56 -0
- heliopuddle/server/services/rule_names.py +28 -0
- heliopuddle/server/services/rule_notify.py +135 -0
- heliopuddle/server/services/rule_prefect.py +200 -0
- heliopuddle/server/services/rule_types.py +86 -0
- heliopuddle/server/services/rules.py +324 -0
- heliopuddle/server/services/run_logging.py +52 -0
- heliopuddle/server/services/runs.py +164 -0
- heliopuddle/server/services/runtime.py +325 -0
- heliopuddle/server/services/stores.py +76 -0
- heliopuddle/server/services/transfer.py +483 -0
- heliopuddle/server/services/transfer_guards.py +176 -0
- heliopuddle/server/services/transfer_io.py +49 -0
- heliopuddle/server/services/transfer_support.py +120 -0
- heliopuddle/server/services/upload/__init__.py +52 -0
- heliopuddle/server/services/upload/complete.py +267 -0
- heliopuddle/server/services/upload/content.py +60 -0
- heliopuddle/server/services/upload/objects.py +118 -0
- heliopuddle/server/services/upload/repair.py +203 -0
- heliopuddle/server/services/upload/results.py +95 -0
- heliopuddle/server/services/upload/settle_new.py +185 -0
- heliopuddle/server/services/upload/settle_overwrite.py +118 -0
- heliopuddle/server/services/verify.py +205 -0
- heliopuddle/server/serving.py +183 -0
- heliopuddle/server/start.py +406 -0
- heliopuddle/server/ui/__init__.py +18 -0
- heliopuddle/server/ui/app.py +130 -0
- heliopuddle/server/ui/auth/__init__.py +39 -0
- heliopuddle/server/ui/auth/login.html +25 -0
- heliopuddle/server/ui/auth/oidc.py +56 -0
- heliopuddle/server/ui/auth/routes.py +276 -0
- heliopuddle/server/ui/auth/session.py +225 -0
- heliopuddle/server/ui/pages/__init__.py +8 -0
- heliopuddle/server/ui/pages/files/__init__.py +45 -0
- heliopuddle/server/ui/pages/files/_inspector.html +96 -0
- heliopuddle/server/ui/pages/files/_preview.html +124 -0
- heliopuddle/server/ui/pages/files/actions.py +61 -0
- heliopuddle/server/ui/pages/files/content.py +91 -0
- heliopuddle/server/ui/pages/files/detail.py +36 -0
- heliopuddle/server/ui/pages/files/file.html +136 -0
- heliopuddle/server/ui/pages/files/files.html +187 -0
- heliopuddle/server/ui/pages/files/filters.py +202 -0
- heliopuddle/server/ui/pages/files/fragment.py +60 -0
- heliopuddle/server/ui/pages/files/inspector.py +40 -0
- heliopuddle/server/ui/pages/files/listing.py +119 -0
- heliopuddle/server/ui/pages/files/lookup.py +35 -0
- heliopuddle/server/ui/pages/files/paging.py +50 -0
- heliopuddle/server/ui/pages/files/preview.py +215 -0
- heliopuddle/server/ui/pages/files/tabs.py +38 -0
- heliopuddle/server/ui/pages/home/__init__.py +5 -0
- heliopuddle/server/ui/pages/home/health.py +19 -0
- heliopuddle/server/ui/pages/home/home.html +69 -0
- heliopuddle/server/ui/pages/home/routes.py +60 -0
- heliopuddle/server/ui/pages/overview/__init__.py +5 -0
- heliopuddle/server/ui/pages/overview/heatmap.py +59 -0
- heliopuddle/server/ui/pages/overview/overview.html +122 -0
- heliopuddle/server/ui/pages/overview/routes.py +62 -0
- heliopuddle/server/ui/pages/rules/__init__.py +17 -0
- heliopuddle/server/ui/pages/rules/_rules_flow.html +28 -0
- heliopuddle/server/ui/pages/rules/actions.py +69 -0
- heliopuddle/server/ui/pages/rules/flow.py +282 -0
- heliopuddle/server/ui/pages/rules/one_off.py +84 -0
- heliopuddle/server/ui/pages/rules/page.py +66 -0
- heliopuddle/server/ui/pages/rules/rules.html +143 -0
- heliopuddle/server/ui/pages/search/__init__.py +5 -0
- heliopuddle/server/ui/pages/search/_suggest.html +20 -0
- heliopuddle/server/ui/pages/search/routes.py +89 -0
- heliopuddle/server/ui/pages/search/search.html +72 -0
- heliopuddle/server/ui/pages/storage/__init__.py +5 -0
- heliopuddle/server/ui/pages/storage/bar.py +35 -0
- heliopuddle/server/ui/pages/storage/routes.py +115 -0
- heliopuddle/server/ui/pages/storage/storage.html +45 -0
- heliopuddle/server/ui/pages/storage/storage_location.html +106 -0
- heliopuddle/server/ui/shared/__init__.py +1 -0
- heliopuddle/server/ui/shared/clients.py +78 -0
- heliopuddle/server/ui/shared/context.py +182 -0
- heliopuddle/server/ui/shared/errors.py +92 -0
- heliopuddle/server/ui/shared/fileinfo.py +61 -0
- heliopuddle/server/ui/shared/format.py +125 -0
- heliopuddle/server/ui/shared/forms.py +140 -0
- heliopuddle/server/ui/shared/links.py +13 -0
- heliopuddle/server/ui/shared/rules_text.py +111 -0
- heliopuddle/server/ui/shared/states.py +61 -0
- heliopuddle/server/ui/shared/summary.py +87 -0
- heliopuddle/server/ui/shared/templating.py +61 -0
- heliopuddle/server/ui/static/fonts/OFL-IBM-Plex-Mono.txt +93 -0
- heliopuddle/server/ui/static/fonts/OFL-IBM-Plex-Sans.txt +93 -0
- heliopuddle/server/ui/static/fonts/OFL-Manrope.txt +93 -0
- heliopuddle/server/ui/static/fonts/ibm-plex-mono-latin-400.woff2 +0 -0
- heliopuddle/server/ui/static/fonts/ibm-plex-mono-latin-500.woff2 +0 -0
- heliopuddle/server/ui/static/fonts/ibm-plex-sans-latin-wght.woff2 +0 -0
- heliopuddle/server/ui/static/fonts/manrope-latin-wght.woff2 +0 -0
- heliopuddle/server/ui/static/hp.css +1050 -0
- heliopuddle/server/ui/static/hp.js +305 -0
- heliopuddle/server/ui/static/icon.svg +1 -0
- heliopuddle/server/ui/templates/_macros.html +77 -0
- heliopuddle/server/ui/templates/base.html +137 -0
- heliopuddle/server/ui/templates/error.html +13 -0
- heliopuddle/settings.py +240 -0
- heliopuddle/storage/__init__.py +18 -0
- heliopuddle/storage/backends.py +391 -0
- heliopuddle/storage/hashing.py +51 -0
- heliopuddle/storage/location.py +497 -0
- heliopuddle/storage/redact.py +58 -0
- heliopuddle/testing/__init__.py +15 -0
- heliopuddle/testing/_changes.py +269 -0
- heliopuddle/testing/_helpers.py +165 -0
- heliopuddle/testing/_state.py +202 -0
- heliopuddle/testing/fake.py +275 -0
- heliopuddle/versioning.py +236 -0
- heliopuddle-0.1.0.dist-info/METADATA +524 -0
- heliopuddle-0.1.0.dist-info/RECORD +303 -0
- heliopuddle-0.1.0.dist-info/WHEEL +4 -0
- heliopuddle-0.1.0.dist-info/entry_points.txt +5 -0
- heliopuddle-0.1.0.dist-info/licenses/LICENSE +201 -0
heliopuddle/__init__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""heliopuddle: a simple multi-location datastore manager built on Prefect."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
__version__ = version("heliopuddle")
|
|
7
|
+
except PackageNotFoundError: # pragma: no cover - only when not installed
|
|
8
|
+
__version__ = "0.0.0"
|
heliopuddle/cli.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Command line: ``heliopuddle server start``, ``db upgrade``, ``user ...`` and ``file ...``.
|
|
2
|
+
|
|
3
|
+
See docs/design/deployment.md. Exit codes: 0 on success, 1 on a runtime
|
|
4
|
+
failure (migration, Prefect, a component stopping), 2 on invalid settings,
|
|
5
|
+
project config or options.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import logging
|
|
11
|
+
from typing import Annotated
|
|
12
|
+
|
|
13
|
+
import typer
|
|
14
|
+
|
|
15
|
+
from heliopuddle.cli_file import file_app
|
|
16
|
+
from heliopuddle.cli_user import user_app
|
|
17
|
+
|
|
18
|
+
app = typer.Typer(no_args_is_help=True, help="heliopuddle: a multi-location datastore manager")
|
|
19
|
+
server_app = typer.Typer(no_args_is_help=True, help="Run heliopuddle processes")
|
|
20
|
+
db_app = typer.Typer(no_args_is_help=True, help="Database commands")
|
|
21
|
+
app.add_typer(server_app, name="server")
|
|
22
|
+
app.add_typer(db_app, name="db")
|
|
23
|
+
app.add_typer(user_app, name="user")
|
|
24
|
+
app.add_typer(file_app, name="file")
|
|
25
|
+
|
|
26
|
+
LOG_FORMAT = "%(asctime)s %(levelname)s %(name)s: %(message)s"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _configure_logging() -> None:
|
|
30
|
+
root = logging.getLogger()
|
|
31
|
+
if not root.handlers:
|
|
32
|
+
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
|
|
33
|
+
logging.getLogger("heliopuddle").setLevel(logging.INFO)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _fail(message: str, code: int) -> typer.Exit:
|
|
37
|
+
typer.echo(f"Error: {message}", err=True)
|
|
38
|
+
return typer.Exit(code)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@server_app.command("start")
|
|
42
|
+
def start(
|
|
43
|
+
host: Annotated[
|
|
44
|
+
str | None, typer.Option(help="Interface to bind (overrides HELIOPUDDLE_HOST)")
|
|
45
|
+
] = None,
|
|
46
|
+
port: Annotated[
|
|
47
|
+
int | None, typer.Option(help="Port to bind (overrides HELIOPUDDLE_PORT)")
|
|
48
|
+
] = None,
|
|
49
|
+
api: Annotated[bool, typer.Option("--api/--no-api", help="Serve the API at /api/v1")] = True,
|
|
50
|
+
ui: Annotated[bool, typer.Option("--ui/--no-ui", help="Serve the UI")] = True,
|
|
51
|
+
services: Annotated[
|
|
52
|
+
bool, typer.Option("--services/--no-services", help="Serve the Prefect deployments")
|
|
53
|
+
] = True,
|
|
54
|
+
migrate: Annotated[
|
|
55
|
+
bool,
|
|
56
|
+
typer.Option(
|
|
57
|
+
"--migrate/--no-migrate",
|
|
58
|
+
help="Run DB migrations first; with --no-migrate the schema must be at head",
|
|
59
|
+
),
|
|
60
|
+
] = True,
|
|
61
|
+
) -> None:
|
|
62
|
+
"""Start the API, UI and services (see docs/design/deployment.md)."""
|
|
63
|
+
from heliopuddle.server.start import StartOptions, StartupError, run
|
|
64
|
+
|
|
65
|
+
_configure_logging()
|
|
66
|
+
options = StartOptions(host=host, port=port, api=api, ui=ui, services=services, migrate=migrate)
|
|
67
|
+
try:
|
|
68
|
+
run(options)
|
|
69
|
+
except StartupError as e:
|
|
70
|
+
raise _fail(str(e), e.exit_code) from None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@db_app.command("upgrade")
|
|
74
|
+
def upgrade() -> None:
|
|
75
|
+
"""Run database migrations only, then exit."""
|
|
76
|
+
from heliopuddle.server.database.migrate import current_revision, upgrade_to_head
|
|
77
|
+
from heliopuddle.server.start import StartupError, describe_db_url, load_settings
|
|
78
|
+
|
|
79
|
+
_configure_logging()
|
|
80
|
+
try:
|
|
81
|
+
settings = load_settings()
|
|
82
|
+
except StartupError as e:
|
|
83
|
+
raise _fail(str(e), e.exit_code) from None
|
|
84
|
+
url = settings.resolved_database_url
|
|
85
|
+
db = describe_db_url(url)
|
|
86
|
+
try:
|
|
87
|
+
upgrade_to_head(url)
|
|
88
|
+
revision = current_revision(url)
|
|
89
|
+
except Exception as e:
|
|
90
|
+
raise _fail(f"Database migration failed for {db}: {type(e).__name__}: {e}", 1) from None
|
|
91
|
+
typer.echo(f"Database {db} is at revision {revision}")
|
heliopuddle/cli_entry.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""The ``heliopuddle`` console script.
|
|
2
|
+
|
|
3
|
+
The command line needs the ``cli`` extra (typer), but the script is installed
|
|
4
|
+
with the core package too (DEP-17). Without the extra, say how to install it
|
|
5
|
+
instead of failing with a traceback.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
INSTALL_HINT = (
|
|
13
|
+
"heliopuddle: the command line needs the cli extra, which is not installed.\n"
|
|
14
|
+
'Install it with: pip install "heliopuddle[cli]"\n'
|
|
15
|
+
'(or "heliopuddle[server]" to also run a server).'
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def main() -> None:
|
|
20
|
+
"""Run the heliopuddle CLI, or exit 1 with an install hint without typer."""
|
|
21
|
+
try:
|
|
22
|
+
import typer # noqa: F401 # pyright: ignore[reportUnusedImport]
|
|
23
|
+
except ModuleNotFoundError as error:
|
|
24
|
+
if error.name != "typer":
|
|
25
|
+
raise
|
|
26
|
+
print(INSTALL_HINT, file=sys.stderr)
|
|
27
|
+
raise SystemExit(1) from None
|
|
28
|
+
|
|
29
|
+
from heliopuddle.cli import app
|
|
30
|
+
|
|
31
|
+
app()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""``heliopuddle file ...``: add, register, list, show, update, download and remove files.
|
|
2
|
+
|
|
3
|
+
Requirement CLI-15.
|
|
4
|
+
|
|
5
|
+
A thin layer over :class:`heliopuddle.client.HelioPuddleClient`, so it works
|
|
6
|
+
from any machine that can reach the API and needs only ``heliopuddle[cli]``.
|
|
7
|
+
|
|
8
|
+
Connection: ``--api-url`` (env ``HELIOPUDDLE_API_URL``) and ``--project``
|
|
9
|
+
(env ``HELIOPUDDLE_PROJECT``, default ``default``). Credentials, as for
|
|
10
|
+
``heliopuddle user``: ``--token`` (env ``HELIOPUDDLE_TOKEN``), or ``--username``
|
|
11
|
+
(env ``HELIOPUDDLE_USERNAME``) with the password from ``--password-stdin``, env
|
|
12
|
+
``HELIOPUDDLE_PASSWORD`` or a hidden prompt. With neither, requests carry only
|
|
13
|
+
``--user`` (env ``HELIOPUDDLE_USER``) in the user header, for servers in
|
|
14
|
+
``header`` auth mode.
|
|
15
|
+
|
|
16
|
+
Files are chosen by id (the positional arguments) or with ``--path GLOB`` /
|
|
17
|
+
``--name GLOB``, which match live files: a digit-only argument is always an
|
|
18
|
+
id, so a file whose path is ``123`` is reached with ``--path 123``.
|
|
19
|
+
|
|
20
|
+
Exit codes: 0 on success, 1 when the API refuses or cannot be reached (or a
|
|
21
|
+
file conflicts), 2 for invalid options.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from heliopuddle.cli_file import commands_read, commands_update, commands_write
|
|
27
|
+
from heliopuddle.cli_file.app import file_app
|
|
28
|
+
|
|
29
|
+
__all__ = ["commands_read", "commands_update", "commands_write", "file_app"]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""The ``file`` typer app; the command modules register themselves on it."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
file_app = typer.Typer(
|
|
8
|
+
no_args_is_help=True,
|
|
9
|
+
help=(
|
|
10
|
+
"Add, register, list, show, update, download and remove files in a project through "
|
|
11
|
+
"the API. "
|
|
12
|
+
"Choose the project with --project (HELIOPUDDLE_PROJECT)."
|
|
13
|
+
),
|
|
14
|
+
)
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""``file list``, ``file show`` and ``file download``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Annotated
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
|
|
11
|
+
from heliopuddle.cli_file.app import file_app
|
|
12
|
+
from heliopuddle.cli_file.format import _copy_cell, _print, _version_label
|
|
13
|
+
from heliopuddle.cli_file.options import (
|
|
14
|
+
ApiUrl,
|
|
15
|
+
AsJson,
|
|
16
|
+
FileId,
|
|
17
|
+
NameGlob,
|
|
18
|
+
PasswordStdin,
|
|
19
|
+
PathGlob,
|
|
20
|
+
Project,
|
|
21
|
+
Token,
|
|
22
|
+
User,
|
|
23
|
+
Username,
|
|
24
|
+
)
|
|
25
|
+
from heliopuddle.cli_file.select import _select_one
|
|
26
|
+
from heliopuddle.cli_file.session import _session
|
|
27
|
+
from heliopuddle.cli_user import DEFAULT_API_URL, _table
|
|
28
|
+
from heliopuddle.client import FileRecord, HelioPuddleClient
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@file_app.command("list")
|
|
32
|
+
def list_(
|
|
33
|
+
pattern: Annotated[
|
|
34
|
+
str | None,
|
|
35
|
+
typer.Argument(help="Path glob: * within a folder, ** any depth, ? one character."),
|
|
36
|
+
] = None,
|
|
37
|
+
latest: Annotated[
|
|
38
|
+
bool, typer.Option("--latest", help="Only the latest version of each series.")
|
|
39
|
+
] = False,
|
|
40
|
+
deleted: Annotated[bool, typer.Option("--deleted", help="Include deleted files.")] = False,
|
|
41
|
+
limit: Annotated[int, typer.Option("--limit", "-n", help="At most this many.", min=1)] = 100,
|
|
42
|
+
as_json: AsJson = False,
|
|
43
|
+
api_url: ApiUrl = DEFAULT_API_URL,
|
|
44
|
+
project: Project = "default",
|
|
45
|
+
token: Token = None,
|
|
46
|
+
username: Username = None,
|
|
47
|
+
password_stdin: PasswordStdin = False,
|
|
48
|
+
user: User = None,
|
|
49
|
+
) -> None:
|
|
50
|
+
"""List files, ordered by path."""
|
|
51
|
+
with _session(api_url, project, token, username, password_stdin, user) as client:
|
|
52
|
+
records: list[FileRecord] = []
|
|
53
|
+
for record in client.find_all(
|
|
54
|
+
path=pattern,
|
|
55
|
+
latest_only=latest,
|
|
56
|
+
include_deleted=deleted,
|
|
57
|
+
order="path",
|
|
58
|
+
page_size=min(limit, 1000),
|
|
59
|
+
):
|
|
60
|
+
records.append(record)
|
|
61
|
+
if len(records) >= limit:
|
|
62
|
+
break
|
|
63
|
+
if as_json:
|
|
64
|
+
_print(records, True, many=True)
|
|
65
|
+
return
|
|
66
|
+
if not records:
|
|
67
|
+
typer.echo("No files.")
|
|
68
|
+
return
|
|
69
|
+
locations = _location_columns(client, records)
|
|
70
|
+
rows = [
|
|
71
|
+
[
|
|
72
|
+
str(r.id),
|
|
73
|
+
*(_copy_cell(r, name) for name in locations),
|
|
74
|
+
str(r.size),
|
|
75
|
+
r.updated_at.strftime("%Y-%m-%d %H:%M"),
|
|
76
|
+
r.path + (" (deleted)" if r.deleted_at else ""),
|
|
77
|
+
]
|
|
78
|
+
for r in records
|
|
79
|
+
]
|
|
80
|
+
headers = ["ID", *(name.upper() for name in locations), "SIZE", "UPDATED", "PATH"]
|
|
81
|
+
typer.echo(_table(rows, headers))
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _location_columns(client: HelioPuddleClient, records: list[FileRecord]) -> list[str]:
|
|
85
|
+
"""Storage locations to show as columns: the active ones in config order, plus
|
|
86
|
+
any inactive one that still holds a listed copy."""
|
|
87
|
+
used = {c.storage_location for r in records for c in r.storage_locations}
|
|
88
|
+
return [sl.name for sl in client.list_storage_locations() if sl.active or sl.name in used]
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@file_app.command("show")
|
|
92
|
+
def show(
|
|
93
|
+
file_id: FileId = None,
|
|
94
|
+
path: PathGlob = None,
|
|
95
|
+
name: NameGlob = None,
|
|
96
|
+
as_json: AsJson = False,
|
|
97
|
+
api_url: ApiUrl = DEFAULT_API_URL,
|
|
98
|
+
project: Project = "default",
|
|
99
|
+
token: Token = None,
|
|
100
|
+
username: Username = None,
|
|
101
|
+
password_stdin: PasswordStdin = False,
|
|
102
|
+
user: User = None,
|
|
103
|
+
) -> None:
|
|
104
|
+
"""Show one file: hash, size, version, metadata and its copies."""
|
|
105
|
+
with _session(api_url, project, token, username, password_stdin, user) as client:
|
|
106
|
+
record = _select_one(client, file_id, path, name)
|
|
107
|
+
if as_json:
|
|
108
|
+
_print([record], True)
|
|
109
|
+
return
|
|
110
|
+
lines = [
|
|
111
|
+
f"id: {record.id}",
|
|
112
|
+
f"path: {record.path}",
|
|
113
|
+
f"md5: {record.hash}",
|
|
114
|
+
f"size: {record.size}",
|
|
115
|
+
f"version: {_version_label(record)}",
|
|
116
|
+
f"latest: {'yes' if record.is_latest else 'no'}",
|
|
117
|
+
f"content date: {record.content_date or '-'}",
|
|
118
|
+
f"created: {record.created_at} by {record.created_by or '-'}",
|
|
119
|
+
f"deleted: {record.deleted_at or 'no'}",
|
|
120
|
+
f"metadata: {json.dumps(record.metadata) if record.metadata else '-'}",
|
|
121
|
+
"copies:",
|
|
122
|
+
*(f" {c.storage_location}: {c.state}" for c in record.storage_locations),
|
|
123
|
+
]
|
|
124
|
+
typer.echo("\n".join(lines))
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@file_app.command("download")
|
|
128
|
+
def download(
|
|
129
|
+
file_id: FileId = None,
|
|
130
|
+
path: PathGlob = None,
|
|
131
|
+
name: NameGlob = None,
|
|
132
|
+
dest: Annotated[
|
|
133
|
+
Path | None,
|
|
134
|
+
typer.Option("--to", "-o", help="Local file or directory; default the file name here."),
|
|
135
|
+
] = None,
|
|
136
|
+
api_url: ApiUrl = DEFAULT_API_URL,
|
|
137
|
+
project: Project = "default",
|
|
138
|
+
token: Token = None,
|
|
139
|
+
username: Username = None,
|
|
140
|
+
password_stdin: PasswordStdin = False,
|
|
141
|
+
user: User = None,
|
|
142
|
+
) -> None:
|
|
143
|
+
"""Download a file and check its md5."""
|
|
144
|
+
with _session(api_url, project, token, username, password_stdin, user) as client:
|
|
145
|
+
record = _select_one(client, file_id, path, name)
|
|
146
|
+
target = dest if dest is not None else Path(record.name)
|
|
147
|
+
if target.is_dir():
|
|
148
|
+
target = target / record.name
|
|
149
|
+
written = client.download(record.id, target)
|
|
150
|
+
typer.echo(str(written))
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""``file update``: change the metadata and content date of live files."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from typing import Annotated, Any
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
|
|
11
|
+
from heliopuddle.cli_file.app import file_app
|
|
12
|
+
from heliopuddle.cli_file.format import _metadata, _print
|
|
13
|
+
from heliopuddle.cli_file.options import (
|
|
14
|
+
ApiUrl,
|
|
15
|
+
AsJson,
|
|
16
|
+
FileIds,
|
|
17
|
+
NameGlob,
|
|
18
|
+
PasswordStdin,
|
|
19
|
+
PathGlob,
|
|
20
|
+
Project,
|
|
21
|
+
Token,
|
|
22
|
+
User,
|
|
23
|
+
Username,
|
|
24
|
+
)
|
|
25
|
+
from heliopuddle.cli_file.select import _select
|
|
26
|
+
from heliopuddle.cli_file.session import _session
|
|
27
|
+
from heliopuddle.cli_user import DEFAULT_API_URL, _fail
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _metadata_patch(
|
|
31
|
+
metadata: str | None, set_: list[str] | None, unset: list[str] | None
|
|
32
|
+
) -> dict[str, Any] | None:
|
|
33
|
+
"""The metadata patch from --metadata, --set KEY=VALUE and --unset KEY (None: no change)."""
|
|
34
|
+
if metadata is None and not set_ and not unset:
|
|
35
|
+
return None
|
|
36
|
+
patch: dict[str, Any] = dict(_metadata(metadata) or {})
|
|
37
|
+
for item in set_ or []:
|
|
38
|
+
key, sep, raw = item.partition("=")
|
|
39
|
+
if not sep or not key:
|
|
40
|
+
_fail(f"--set takes KEY=VALUE, not {item!r}", 2)
|
|
41
|
+
try:
|
|
42
|
+
patch[key] = json.loads(raw)
|
|
43
|
+
except json.JSONDecodeError:
|
|
44
|
+
patch[key] = raw # not JSON: a plain string
|
|
45
|
+
for key in unset or []:
|
|
46
|
+
patch[key] = None
|
|
47
|
+
return patch
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@file_app.command("update")
|
|
51
|
+
def update(
|
|
52
|
+
ids: FileIds = None,
|
|
53
|
+
path: PathGlob = None,
|
|
54
|
+
name: NameGlob = None,
|
|
55
|
+
set_: Annotated[
|
|
56
|
+
list[str] | None,
|
|
57
|
+
typer.Option(
|
|
58
|
+
"--set",
|
|
59
|
+
help="Set a metadata key: KEY=VALUE (VALUE is JSON if it parses, else a string). "
|
|
60
|
+
"Repeatable.",
|
|
61
|
+
),
|
|
62
|
+
] = None,
|
|
63
|
+
unset: Annotated[
|
|
64
|
+
list[str] | None, typer.Option("--unset", help="Remove a metadata key. Repeatable.")
|
|
65
|
+
] = None,
|
|
66
|
+
metadata: Annotated[
|
|
67
|
+
str | None,
|
|
68
|
+
typer.Option("--metadata", "-m", help="JSON object merged into the metadata."),
|
|
69
|
+
] = None,
|
|
70
|
+
replace_metadata: Annotated[
|
|
71
|
+
bool,
|
|
72
|
+
typer.Option(
|
|
73
|
+
"--replace-metadata",
|
|
74
|
+
help="Replace the whole metadata with --metadata/--set instead of merging.",
|
|
75
|
+
),
|
|
76
|
+
] = False,
|
|
77
|
+
content_date: Annotated[
|
|
78
|
+
datetime | None, typer.Option("--content-date", help="Set the content date (UTC).")
|
|
79
|
+
] = None,
|
|
80
|
+
clear_content_date: Annotated[
|
|
81
|
+
bool,
|
|
82
|
+
typer.Option(
|
|
83
|
+
"--clear-content-date",
|
|
84
|
+
help="Go back to the date in the path (a version rule's date group), or none.",
|
|
85
|
+
),
|
|
86
|
+
] = False,
|
|
87
|
+
as_json: AsJson = False,
|
|
88
|
+
api_url: ApiUrl = DEFAULT_API_URL,
|
|
89
|
+
project: Project = "default",
|
|
90
|
+
token: Token = None,
|
|
91
|
+
username: Username = None,
|
|
92
|
+
password_stdin: PasswordStdin = False,
|
|
93
|
+
user: User = None,
|
|
94
|
+
) -> None:
|
|
95
|
+
"""Change the metadata and content date of live files.
|
|
96
|
+
|
|
97
|
+
The version is not set here: it comes from the path, through the project's
|
|
98
|
+
version rules.
|
|
99
|
+
"""
|
|
100
|
+
patch = _metadata_patch(metadata, set_, unset)
|
|
101
|
+
if content_date is not None and clear_content_date:
|
|
102
|
+
_fail("give --content-date or --clear-content-date, not both", 2)
|
|
103
|
+
if replace_metadata and patch is None:
|
|
104
|
+
_fail("--replace-metadata needs --metadata or --set", 2)
|
|
105
|
+
if patch is None and content_date is None and not clear_content_date:
|
|
106
|
+
_fail("nothing to change: give --set, --unset, --metadata or a content date option", 2)
|
|
107
|
+
with _session(api_url, project, token, username, password_stdin, user) as client:
|
|
108
|
+
records = []
|
|
109
|
+
for record in _select(client, ids, path, name):
|
|
110
|
+
if patch is not None:
|
|
111
|
+
record = client.update_metadata(record.id, patch, replace=replace_metadata)
|
|
112
|
+
if content_date is not None or clear_content_date:
|
|
113
|
+
record = client.set_content_date(record.id, content_date)
|
|
114
|
+
records.append(record)
|
|
115
|
+
_print(records, as_json, many=len(records) > 1 or path is not None or name is not None)
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""``file add``, ``file register`` and ``file remove``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Annotated
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
|
|
11
|
+
from heliopuddle.cli_file.app import file_app
|
|
12
|
+
from heliopuddle.cli_file.format import (
|
|
13
|
+
_check_version_options,
|
|
14
|
+
_incomplete,
|
|
15
|
+
_join,
|
|
16
|
+
_metadata,
|
|
17
|
+
_print,
|
|
18
|
+
)
|
|
19
|
+
from heliopuddle.cli_file.options import (
|
|
20
|
+
ApiUrl,
|
|
21
|
+
AsJson,
|
|
22
|
+
FileIds,
|
|
23
|
+
Location,
|
|
24
|
+
NameGlob,
|
|
25
|
+
PasswordStdin,
|
|
26
|
+
PathGlob,
|
|
27
|
+
Project,
|
|
28
|
+
Token,
|
|
29
|
+
User,
|
|
30
|
+
Username,
|
|
31
|
+
VersionNumber,
|
|
32
|
+
VersionText,
|
|
33
|
+
)
|
|
34
|
+
from heliopuddle.cli_file.select import _select
|
|
35
|
+
from heliopuddle.cli_file.session import _session
|
|
36
|
+
from heliopuddle.cli_user import DEFAULT_API_URL, _fail
|
|
37
|
+
from heliopuddle.client import FileRecord
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@file_app.command("add")
|
|
41
|
+
def add(
|
|
42
|
+
local: Annotated[Path, typer.Argument(help="Local file, or a directory with --recursive.")],
|
|
43
|
+
path: Annotated[
|
|
44
|
+
str | None,
|
|
45
|
+
typer.Argument(
|
|
46
|
+
help="Destination path in the store (a prefix with --recursive). "
|
|
47
|
+
"Default: the local file name."
|
|
48
|
+
),
|
|
49
|
+
] = None,
|
|
50
|
+
recursive: Annotated[
|
|
51
|
+
bool, typer.Option("--recursive", "-r", help="Add every file under a directory.")
|
|
52
|
+
] = False,
|
|
53
|
+
overwrite: Annotated[
|
|
54
|
+
bool, typer.Option("--overwrite", help="Replace a live file with different content.")
|
|
55
|
+
] = False,
|
|
56
|
+
metadata: Annotated[
|
|
57
|
+
str | None, typer.Option("--metadata", "-m", help="JSON object stored with the file.")
|
|
58
|
+
] = None,
|
|
59
|
+
content_date: Annotated[
|
|
60
|
+
datetime | None, typer.Option("--content-date", help="Content date (UTC).")
|
|
61
|
+
] = None,
|
|
62
|
+
storage_location: Location = None,
|
|
63
|
+
version_number: VersionNumber = None,
|
|
64
|
+
version_text: VersionText = None,
|
|
65
|
+
as_json: AsJson = False,
|
|
66
|
+
api_url: ApiUrl = DEFAULT_API_URL,
|
|
67
|
+
project: Project = "default",
|
|
68
|
+
token: Token = None,
|
|
69
|
+
username: Username = None,
|
|
70
|
+
password_stdin: PasswordStdin = False,
|
|
71
|
+
user: User = None,
|
|
72
|
+
) -> None:
|
|
73
|
+
"""Upload a file (or a directory tree) and register it; identical content is a no-op.
|
|
74
|
+
|
|
75
|
+
--version-number or --version-text sets the version of a single new file;
|
|
76
|
+
an existing file keeps its version.
|
|
77
|
+
"""
|
|
78
|
+
meta = _metadata(metadata)
|
|
79
|
+
_check_version_options(version_number, version_text)
|
|
80
|
+
versioned = version_number is not None or version_text is not None
|
|
81
|
+
if versioned and (recursive or local.is_dir()):
|
|
82
|
+
_fail("--version-number and --version-text take a single file, not a directory", 2)
|
|
83
|
+
if local.is_dir():
|
|
84
|
+
if not recursive:
|
|
85
|
+
_fail(f"{local} is a directory; use --recursive", 2)
|
|
86
|
+
prefix = path if path is not None else local.name
|
|
87
|
+
sources = sorted(p for p in local.rglob("*") if p.is_file())
|
|
88
|
+
targets = [_join(prefix, p.relative_to(local).as_posix()) for p in sources]
|
|
89
|
+
else:
|
|
90
|
+
sources, targets = [local], [path if path is not None else local.name]
|
|
91
|
+
records: list[FileRecord] = []
|
|
92
|
+
with _session(
|
|
93
|
+
api_url,
|
|
94
|
+
project,
|
|
95
|
+
token,
|
|
96
|
+
username,
|
|
97
|
+
password_stdin,
|
|
98
|
+
user,
|
|
99
|
+
version=(version_number, version_text),
|
|
100
|
+
) as client:
|
|
101
|
+
for source, target in zip(sources, targets, strict=True):
|
|
102
|
+
records.append(
|
|
103
|
+
client.add_file(
|
|
104
|
+
source,
|
|
105
|
+
target,
|
|
106
|
+
storage_location=storage_location,
|
|
107
|
+
metadata=meta,
|
|
108
|
+
overwrite=overwrite,
|
|
109
|
+
content_date=content_date,
|
|
110
|
+
version_number=version_number,
|
|
111
|
+
version_text=version_text,
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
_print(records, as_json, many=recursive)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@file_app.command("register")
|
|
118
|
+
def register(
|
|
119
|
+
path: Annotated[str, typer.Argument(help="Path of an object already in the store.")],
|
|
120
|
+
hash: Annotated[str, typer.Option("--hash", help="Hex md5 of the content.")],
|
|
121
|
+
size: Annotated[int, typer.Option("--size", help="Size in bytes.", min=0)],
|
|
122
|
+
metadata: Annotated[
|
|
123
|
+
str | None, typer.Option("--metadata", "-m", help="JSON object stored with the file.")
|
|
124
|
+
] = None,
|
|
125
|
+
content_date: Annotated[
|
|
126
|
+
datetime | None, typer.Option("--content-date", help="Content date (UTC).")
|
|
127
|
+
] = None,
|
|
128
|
+
storage_location: Location = None,
|
|
129
|
+
version_number: VersionNumber = None,
|
|
130
|
+
version_text: VersionText = None,
|
|
131
|
+
as_json: AsJson = False,
|
|
132
|
+
api_url: ApiUrl = DEFAULT_API_URL,
|
|
133
|
+
project: Project = "default",
|
|
134
|
+
token: Token = None,
|
|
135
|
+
username: Username = None,
|
|
136
|
+
password_stdin: PasswordStdin = False,
|
|
137
|
+
user: User = None,
|
|
138
|
+
) -> None:
|
|
139
|
+
"""Register a file another tool has already written to the store (nothing is uploaded)."""
|
|
140
|
+
meta = _metadata(metadata)
|
|
141
|
+
_check_version_options(version_number, version_text)
|
|
142
|
+
with _session(
|
|
143
|
+
api_url,
|
|
144
|
+
project,
|
|
145
|
+
token,
|
|
146
|
+
username,
|
|
147
|
+
password_stdin,
|
|
148
|
+
user,
|
|
149
|
+
version=(version_number, version_text),
|
|
150
|
+
) as client:
|
|
151
|
+
record = client.register_file(
|
|
152
|
+
path,
|
|
153
|
+
hash,
|
|
154
|
+
size,
|
|
155
|
+
storage_location=storage_location,
|
|
156
|
+
metadata=meta,
|
|
157
|
+
content_date=content_date,
|
|
158
|
+
version_number=version_number,
|
|
159
|
+
version_text=version_text,
|
|
160
|
+
)
|
|
161
|
+
_print([record], as_json)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
@file_app.command("remove")
|
|
165
|
+
def remove(
|
|
166
|
+
ids: FileIds = None,
|
|
167
|
+
path: PathGlob = None,
|
|
168
|
+
name: NameGlob = None,
|
|
169
|
+
yes: Annotated[bool, typer.Option("--yes", "-y", help="Do not ask for confirmation.")] = False,
|
|
170
|
+
as_json: AsJson = False,
|
|
171
|
+
api_url: ApiUrl = DEFAULT_API_URL,
|
|
172
|
+
project: Project = "default",
|
|
173
|
+
token: Token = None,
|
|
174
|
+
username: Username = None,
|
|
175
|
+
password_stdin: PasswordStdin = False,
|
|
176
|
+
user: User = None,
|
|
177
|
+
) -> None:
|
|
178
|
+
"""Delete files from every storage location (the records are kept as deleted).
|
|
179
|
+
|
|
180
|
+
Asks first, listing the chosen files, unless --yes. Credentials are read
|
|
181
|
+
before the question, so --password-stdin takes the first line of stdin.
|
|
182
|
+
"""
|
|
183
|
+
many = False
|
|
184
|
+
with _session(api_url, project, token, username, password_stdin, user) as client:
|
|
185
|
+
targets = _select(client, ids, path, name)
|
|
186
|
+
many = len(targets) > 1 or path is not None or name is not None
|
|
187
|
+
if not yes:
|
|
188
|
+
listing = "\n".join(f" {r.id}\t{r.path}" for r in targets[:20])
|
|
189
|
+
more = f"\n ... and {len(targets) - 20} more" if len(targets) > 20 else ""
|
|
190
|
+
if not typer.confirm(
|
|
191
|
+
f"{listing}{more}\nDelete these {len(targets)} file(s) "
|
|
192
|
+
"from every storage location?",
|
|
193
|
+
default=False,
|
|
194
|
+
):
|
|
195
|
+
_fail("aborted", 1)
|
|
196
|
+
records = [client.remove_file(r.id) for r in targets]
|
|
197
|
+
_print(records, as_json, many=many)
|
|
198
|
+
incomplete = _incomplete(records)
|
|
199
|
+
if incomplete:
|
|
200
|
+
_fail("not deleted from every storage location:\n " + "\n ".join(incomplete))
|