-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcli.py
More file actions
136 lines (120 loc) · 4.87 KB
/
cli.py
File metadata and controls
136 lines (120 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python3
import json
import click
from typing import List
from databusclient import client
from nextcloudclient import upload
@click.group()
def app():
"""Databus Client CLI"""
pass
@app.command()
@click.option(
"--version-id", "version_id",
required=True,
help="Target databus version/dataset identifier of the form "
"<https://databus.dbpedia.org/$ACCOUNT/$GROUP/$ARTIFACT/$VERSION>",
)
@click.option("--title", required=True, help="Dataset title")
@click.option("--abstract", required=True, help="Dataset abstract max 200 chars")
@click.option("--description", required=True, help="Dataset description")
@click.option("--license", "license_url", required=True, help="License (see dalicc.net)")
@click.option("--apikey", required=True, help="API key")
@click.argument(
"distributions",
nargs=-1,
required=True,
)
def deploy(version_id, title, abstract, description, license_url, apikey, distributions: List[str]):
"""
Deploy a dataset version with the provided metadata and distributions.
"""
click.echo(f"Deploying dataset version: {version_id}")
dataid = client.create_dataset(version_id, title, abstract, description, license_url, distributions)
client.deploy(dataid=dataid, api_key=apikey)
@app.command()
@click.option(
"--metadata", "metadata_file",
required=True,
type=click.Path(exists=True),
help="Path to metadata JSON file",
)
@click.option(
"--version-id", "version_id",
required=True,
help="Target databus version/dataset identifier of the form "
"<https://databus.dbpedia.org/$ACCOUNT/$GROUP/$ARTIFACT/$VERSION>",
)
@click.option("--title", required=True, help="Dataset title")
@click.option("--abstract", required=True, help="Dataset abstract max 200 chars")
@click.option("--description", required=True, help="Dataset description")
@click.option("--license", "license_url", required=True, help="License (see dalicc.net)")
@click.option("--apikey", required=True, help="API key")
def deploy_with_metadata(metadata_file, version_id, title, abstract, description, license_url, apikey):
"""
Deploy to DBpedia Databus using metadata json file.
"""
with open(metadata_file, 'r') as f:
metadata = json.load(f)
client.deploy_from_metadata(metadata, version_id, title, abstract, description, license_url, apikey)
@app.command()
@click.option(
"--webdav-url", "webdav_url",
required=True,
help="WebDAV URL (e.g., https://cloud.example.com/remote.php/webdav)",
)
@click.option(
"--remote",
required=True,
help="rclone remote name (e.g., 'nextcloud')",
)
@click.option(
"--path",
required=True,
help="Remote path on Nextcloud (e.g., 'datasets/mydataset')",
)
@click.option(
"--version-id", "version_id",
required=True,
help="Target databus version/dataset identifier of the form "
"<https://databus.dbpedia.org/$ACCOUNT/$GROUP/$ARTIFACT/$VERSION>",
)
@click.option("--title", required=True, help="Dataset title")
@click.option("--abstract", required=True, help="Dataset abstract max 200 chars")
@click.option("--description", required=True, help="Dataset description")
@click.option("--license", "license_url", required=True, help="License (see dalicc.net)")
@click.option("--apikey", required=True, help="API key")
@click.argument(
"files",
nargs=-1,
type=click.Path(exists=True),
)
def upload_and_deploy(webdav_url, remote, path, version_id, title, abstract, description, license_url, apikey,
files: List[str]):
"""
Upload files to Nextcloud and deploy to DBpedia Databus.
"""
click.echo(f"Uploading data to nextcloud: {remote}")
metadata = upload.upload_to_nextcloud(files, remote, path, webdav_url)
client.deploy_from_metadata(metadata, version_id, title, abstract, description, license_url, apikey)
@app.command()
@click.argument("databusuris", nargs=-1, required=True)
@click.option("--localdir", help="Local databus folder (if not given, databus folder structure is created in current working directory)")
@click.option("--databus", help="Databus URL (if not given, inferred from databusuri, e.g. https://databus.dbpedia.org/sparql)")
@click.option("--token", help="Path to Vault refresh token file")
@click.option("--authurl", default="https://auth.dbpedia.org/realms/dbpedia/protocol/openid-connect/token", show_default=True, help="Keycloak token endpoint URL")
@click.option("--clientid", default="vault-token-exchange", show_default=True, help="Client ID for token exchange")
def download(databusuris: List[str], localdir, databus, token, authurl, clientid):
"""
Download datasets from databus, optionally using vault access if vault options are provided.
"""
client.download(
localDir=localdir,
endpoint=databus,
databusURIs=databusuris,
token=token,
auth_url=authurl,
client_id=clientid,
)
if __name__ == "__main__":
app()