Create a new deposition on Zenodo.
Interactive mode: Leave options blank to be prompted.
Examples:
Interactive mode
gwmock repository create
With all options
gwmock repository create --title "GW Simulation Data" --description "MDC v1"
gwmock repository create --metadata-file metadata.yaml
Source code in src/gwmock/cli/repository/create.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 | def create_command( # pylint: disable=too-many-locals
title: Annotated[str | None, typer.Option("--title", help="Deposition title")] = None,
description: Annotated[str | None, typer.Option("--description", help="Deposition description")] = None,
metadata_file: Annotated[
Path | None, typer.Option("--metadata-file", help="YAML file with additional metadata")
] = None,
sandbox: Annotated[bool, typer.Option("--sandbox", help="Use sandbox environment for testing")] = False,
token: Annotated[
str | None,
typer.Option(
"--token",
help=(
"Zenodo access token (default: ZENODO_API_TOKEN env or ZENODO_SANDBOX_API_TOKEN env for Zenodo Sandbox)"
),
),
] = None,
) -> None:
"""Create a new deposition on Zenodo.
Interactive mode: Leave options blank to be prompted.
Examples:
# Interactive mode
gwmock repository create
# With all options
gwmock repository create --title "GW Simulation Data" --description "MDC v1"
# Using metadata file
gwmock repository create --metadata-file metadata.yaml
"""
import logging
import yaml
from rich.console import Console
from gwmock.cli.repository.utils import get_zenodo_client
logger = logging.getLogger("gwmock")
console = Console()
client = get_zenodo_client(sandbox=sandbox, token=token)
if title is None:
title = typer.prompt("Deposition Title")
if description is None:
description = typer.prompt("Deposition Description", default="")
metadata_dict = {"title": title}
metadata_dict["description"] = description
if metadata_file:
if not metadata_file.exists():
console.print(f"[red]Error:[/red] Metadata file not found: {metadata_file}")
raise typer.Exit(1)
with metadata_file.open("r") as f:
extra = yaml.safe_load(f)
if extra:
metadata_dict.update(extra)
console.print("[bold blue]Creating deposition...[/bold blue]")
try:
result = client.create_deposition(metadata=metadata_dict)
deposition_id = result.get("id")
if sandbox:
console.print("[yellow]Note:[/yellow] Created in Zenodo Sandbox environment.")
console.print("[green]✓ Deposition created successfully![/green]")
console.print(f" [cyan]ID:[/cyan] {deposition_id}")
if sandbox:
console.print(
"[yellow]Note:[/yellow] This is a sandbox deposition. Use [bold]--sandbox[/bold] to access it later."
)
console.print(f" [cyan]Next:[/cyan] gwmock repository upload {deposition_id} --file <path> --sandbox")
else:
console.print(f" [cyan]Next:[/cyan] gwmock repository upload {deposition_id} --file <path>")
except Exception as e:
console.print(f"[red]✗ Failed to create deposition: {e}[/red]")
logger.error("Create deposition failed: %s", e)
raise typer.Exit(1) from e
|