Skip to content

Commit 274f252

Browse files
committed
chores
1 parent f95155f commit 274f252

File tree

3 files changed

+36
-58
lines changed

3 files changed

+36
-58
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ databusclient download 'PREFIX dcat: <http://www.w3.org/ns/dcat#> SELECT ?x WHER
163163
databusclient deploy --help
164164
```
165165
```
166-
Usage: databusclient deploy [OPTIONS] [INPUTS]...
166+
Usage: databusclient deploy [OPTIONS] [DISTRIBUTIONS]...
167167
168168
Flexible deploy to databus command:
169169
@@ -174,7 +174,7 @@ Usage: databusclient deploy [OPTIONS] [INPUTS]...
174174
- Upload & deploy via Nextcloud
175175
176176
Arguments:
177-
INPUTS... Depending on mode:
177+
DISTRIBUTIONS... Depending on mode:
178178
- Classic mode: List of distributions in the form
179179
URL|CV|fileext|compression|sha256sum:contentlength
180180
(where URL is the download URL and CV the key=value pairs,
@@ -200,7 +200,7 @@ Options:
200200
201201
```
202202
#### Examples of using deploy command
203-
Mode 1: Classic Deploy (Distributions)
203+
##### Mode 1: Classic Deploy (Distributions)
204204
```
205205
databusclient deploy --version-id https://databus.dbpedia.org/user1/group1/artifact1/2022-05-18 --title title1 --abstract abstract1 --description description1 --license http://dalicc.net/licenselibrary/AdaptivePublicLicense10 --apikey MYSTERIOUS 'https://raw.githubusercontent.com/dbpedia/databus/master/server/app/api/swagger.yml|type=swagger'
206206
```
@@ -215,7 +215,7 @@ A few more notes for CLI usage:
215215
* If other parameters are used, you need to leave them empty like `https://raw.githubusercontent.com/dbpedia/databus/master/server/app/api/swagger.yml||yml|7a751b6dd5eb8d73d97793c3c564c71ab7b565fa4ba619e4a8fd05a6f80ff653:367116`
216216

217217

218-
Mode 2: Deploy with Metadata File
218+
##### Mode 2: Deploy with Metadata File
219219

220220
Use a JSON metadata file to define all distributions.
221221
The metadata.json should list all distributions and their metadata.
@@ -251,7 +251,7 @@ Metadata file structure (file_format and compression are optional):
251251
```
252252

253253

254-
Mode 3: Upload & Deploy via Nextcloud
254+
##### Mode 3: Upload & Deploy via Nextcloud
255255

256256
Upload local files or folders to a WebDAV/Nextcloud instance and automatically deploy to DBpedia Databus.
257257
Rclone is required.

databusclient/cli.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22
import json
33
import os
4-
import re
54

65
import click
76
from typing import List
@@ -34,30 +33,29 @@ def app():
3433
@click.option("--remote", help="rclone remote name (e.g., 'nextcloud')")
3534
@click.option("--path", help="Remote path on Nextcloud (e.g., 'datasets/mydataset')")
3635

37-
@click.argument("inputs", nargs=-1)
36+
@click.argument("distributions", nargs=-1)
3837
def deploy(version_id, title, abstract, description, license_url, apikey,
39-
metadata_file, webdav_url, remote, path, inputs: List[str]):
38+
metadata_file, webdav_url, remote, path, distributions: List[str]):
4039
"""
41-
Flexible deploy to databus command:\n
42-
- Classic dataset deployment\n
43-
- Metadata-based deployment\n
44-
- Upload & deploy via Nextcloud
40+
Flexible deploy to Databus command supporting three modes:\n
41+
- Classic deploy (distributions as arguments)\n
42+
- Metadata-based deploy (--metadata <file>)\n
43+
- Upload & deploy via Nextcloud (--webdav-url, --remote, --path)
4544
"""
4645

47-
# === Mode 1: Upload & Deploy (Nextcloud) ===
48-
if webdav_url and remote and path:
49-
if not inputs:
50-
raise click.UsageError("Please provide files to upload when using WebDAV/Nextcloud mode.")
46+
# Sanity checks for conflicting options
47+
if metadata_file and any([distributions, webdav_url, remote, path]):
48+
raise click.UsageError("Invalid combination: when using --metadata, do not provide --webdav-url, --remote, --path, or distributions.")
49+
if any([webdav_url, remote, path]) and not all([webdav_url, remote, path]):
50+
raise click.UsageError("Invalid combination: when using WebDAV/Nextcloud mode, please provide --webdav-url, --remote, and --path together.")
5151

52-
#Check that all given paths exist and are files or directories.#
53-
invalid = [f for f in inputs if not os.path.exists(f)]
54-
if invalid:
55-
raise click.UsageError(f"The following input files or folders do not exist: {', '.join(invalid)}")
52+
# === Mode 1: Classic Deploy ===
53+
if distributions and not (metadata_file or webdav_url or remote or path):
54+
click.echo("[MODE] Classic deploy with distributions")
55+
click.echo(f"Deploying dataset version: {version_id}")
5656

57-
click.echo("[MODE] Upload & Deploy to DBpedia Databus via Nextcloud")
58-
click.echo(f"→ Uploading to: {remote}:{path}")
59-
metadata = upload.upload_to_nextcloud(inputs, remote, path, webdav_url)
60-
client.deploy_from_metadata(metadata, version_id, title, abstract, description, license_url, apikey)
57+
dataid = client.create_dataset(version_id, title, abstract, description, license_url, distributions)
58+
client.deploy(dataid=dataid, api_key=apikey)
6159
return
6260

6361
# === Mode 2: Metadata File ===
@@ -67,20 +65,21 @@ def deploy(version_id, title, abstract, description, license_url, apikey,
6765
metadata = json.load(f)
6866
client.deploy_from_metadata(metadata, version_id, title, abstract, description, license_url, apikey)
6967
return
68+
69+
# === Mode 3: Upload & Deploy (Nextcloud) ===
70+
if webdav_url and remote and path:
71+
if not distributions:
72+
raise click.UsageError("Please provide files to upload when using WebDAV/Nextcloud mode.")
7073

71-
# === Mode 3: Classic Deploy ===
72-
if inputs:
73-
invalid = client.validate_distributions(inputs)
74+
#Check that all given paths exist and are files or directories.#
75+
invalid = [f for f in distributions if not os.path.exists(f)]
7476
if invalid:
75-
raise click.UsageError(
76-
f"The following distributions are not in a valid format:\n"
77-
+ "\n".join(invalid)
78-
+ "\nExpected format example:\n"
79-
"https://example.com/file.ttl|format=ttl|gzip|abcdef123456789:12345"
80-
)
81-
click.echo("[MODE] Classic deploy with distributions")
82-
dataid = client.create_dataset(version_id, title, abstract, description, license_url, inputs)
83-
client.deploy(dataid=dataid, api_key=apikey)
77+
raise click.UsageError(f"The following input files or folders do not exist: {', '.join(invalid)}")
78+
79+
click.echo("[MODE] Upload & Deploy to DBpedia Databus via Nextcloud")
80+
click.echo(f"→ Uploading to: {remote}:{path}")
81+
metadata = upload.upload_to_nextcloud(distributions, remote, path, webdav_url)
82+
client.deploy_from_metadata(metadata, version_id, title, abstract, description, license_url, apikey)
8483
return
8584

8685
raise click.UsageError(

databusclient/client.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from SPARQLWrapper import SPARQLWrapper, JSON
88
from hashlib import sha256
99
import os
10-
import re
1110

1211
__debug = False
1312

@@ -256,26 +255,6 @@ def create_distributions_from_metadata(metadata: List[Dict[str, Union[str, int]]
256255
counter += 1
257256
return distributions
258257

259-
260-
def validate_distributions(distros: List[str]) -> List[str]:
261-
"""
262-
Check that all distributions follow the pattern:
263-
url|key=value|[format]|[compression]|[sha256:len]
264-
265-
Parameters
266-
----------
267-
distros: List[str]
268-
List of distribution identifiers to validate
269-
270-
Returns
271-
-------
272-
List[str]
273-
List of invalid distribution identifier strings
274-
"""
275-
pattern = re.compile(r"^https?://[^|]+\|.+$")
276-
return [d for d in distros if not pattern.match(d)]
277-
278-
279258
def create_dataset(
280259
version_id: str,
281260
title: str,
@@ -754,7 +733,7 @@ def __download_list__(urls: List[str],
754733
def __get_databus_id_parts__(uri: str) -> Tuple[Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[str]]:
755734
uri = uri.removeprefix("https://").removeprefix("http://")
756735
parts = uri.strip("/").split("/")
757-
parts += [None] * (6 - len(parts)) # pad fwith None if less than 6 parts
736+
parts += [None] * (6 - len(parts)) # pad with None if less than 6 parts
758737
return tuple(parts[:6]) # return only the first 6 parts
759738

760739

0 commit comments

Comments
 (0)