11#!/usr/bin/env python3
22import json
3+ import os
4+ import re
35
46import click
57from typing import List
@@ -25,90 +27,68 @@ def app():
2527@click .option ("--description" , required = True , help = "Dataset description" )
2628@click .option ("--license" , "license_url" , required = True , help = "License (see dalicc.net)" )
2729@click .option ("--apikey" , required = True , help = "API key" )
28- @click .argument (
29- "distributions" ,
30- nargs = - 1 ,
31- required = True ,
32- )
33- def deploy (version_id , title , abstract , description , license_url , apikey , distributions : List [str ]):
34- """
35- Deploy a dataset version with the provided metadata and distributions.
36- """
37- click .echo (f"Deploying dataset version: { version_id } " )
38- dataid = client .create_dataset (version_id , title , abstract , description , license_url , distributions )
39- client .deploy (dataid = dataid , api_key = apikey )
40-
41-
42- @app .command ()
43- @click .option (
44- "--metadata" , "metadata_file" ,
45- required = True ,
46- type = click .Path (exists = True ),
47- help = "Path to metadata JSON file" ,
48- )
49- @click .option (
50- "--version-id" , "version_id" ,
51- required = True ,
52- help = "Target databus version/dataset identifier of the form "
53- "<https://databus.dbpedia.org/$ACCOUNT/$GROUP/$ARTIFACT/$VERSION>" ,
54- )
55- @click .option ("--title" , required = True , help = "Dataset title" )
56- @click .option ("--abstract" , required = True , help = "Dataset abstract max 200 chars" )
57- @click .option ("--description" , required = True , help = "Dataset description" )
58- @click .option ("--license" , "license_url" , required = True , help = "License (see dalicc.net)" )
59- @click .option ("--apikey" , required = True , help = "API key" )
60- def deploy_with_metadata (metadata_file , version_id , title , abstract , description , license_url , apikey ):
61- """
62- Deploy to DBpedia Databus using metadata json file.
63- """
64-
65- with open (metadata_file , 'r' ) as f :
66- metadata = json .load (f )
6730
68- client .deploy_from_metadata (metadata , version_id , title , abstract , description , license_url , apikey )
31+ @click .option ("--metadata" , "metadata_file" , type = click .Path (exists = True ),
32+ help = "Path to metadata JSON file (for metadata mode)" )
33+ @click .option ("--webdav-url" , "webdav_url" , help = "WebDAV URL (e.g., https://cloud.example.com/remote.php/webdav)" )
34+ @click .option ("--remote" , help = "rclone remote name (e.g., 'nextcloud')" )
35+ @click .option ("--path" , help = "Remote path on Nextcloud (e.g., 'datasets/mydataset')" )
6936
70-
71- @app .command ()
72- @click .option (
73- "--webdav-url" , "webdav_url" ,
74- required = True ,
75- help = "WebDAV URL (e.g., https://cloud.example.com/remote.php/webdav)" ,
76- )
77- @click .option (
78- "--remote" ,
79- required = True ,
80- help = "rclone remote name (e.g., 'nextcloud')" ,
81- )
82- @click .option (
83- "--path" ,
84- required = True ,
85- help = "Remote path on Nextcloud (e.g., 'datasets/mydataset')" ,
86- )
87- @click .option (
88- "--version-id" , "version_id" ,
89- required = True ,
90- help = "Target databus version/dataset identifier of the form "
91- "<https://databus.dbpedia.org/$ACCOUNT/$GROUP/$ARTIFACT/$VERSION>" ,
92- )
93- @click .option ("--title" , required = True , help = "Dataset title" )
94- @click .option ("--abstract" , required = True , help = "Dataset abstract max 200 chars" )
95- @click .option ("--description" , required = True , help = "Dataset description" )
96- @click .option ("--license" , "license_url" , required = True , help = "License (see dalicc.net)" )
97- @click .option ("--apikey" , required = True , help = "API key" )
98- @click .argument (
99- "files" ,
100- nargs = - 1 ,
101- type = click .Path (exists = True ),
102- )
103- def upload_and_deploy (webdav_url , remote , path , version_id , title , abstract , description , license_url , apikey ,
104- files : List [str ]):
37+ @click .argument ("inputs" , nargs = - 1 )
38+ def deploy (version_id , title , abstract , description , license_url , apikey ,
39+ metadata_file , webdav_url , remote , path , inputs : List [str ]):
10540 """
106- Upload files to Nextcloud and deploy to DBpedia Databus.
41+ Flexible deploy to databus command:\n
42+ - Classic dataset deployment\n
43+ - Metadata-based deployment\n
44+ - Upload & deploy via Nextcloud
10745 """
10846
109- click .echo (f"Uploading data to nextcloud: { remote } " )
110- metadata = upload .upload_to_nextcloud (files , remote , path , webdav_url )
111- client .deploy_from_metadata (metadata , version_id , title , abstract , description , license_url , apikey )
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." )
51+
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 )} " )
56+
57+ click .echo (f"[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 )
61+ return
62+
63+ # === Mode 2: Metadata File ===
64+ if metadata_file :
65+ click .echo (f"[MODE] Deploy from metadata file: { metadata_file } " )
66+ with open (metadata_file , 'r' ) as f :
67+ metadata = json .load (f )
68+ client .deploy_from_metadata (metadata , version_id , title , abstract , description , license_url , apikey )
69+ return
70+
71+ # === Mode 3: Classic Deploy ===
72+ if inputs :
73+ invalid = client .validate_distributions (inputs )
74+ if invalid :
75+ raise click .UsageError (
76+ f"The following distributions are not in a valid format:\n "
77+ + "\n " .join (invalid )
78+ + "\n Expected format example:\n "
79+ "https://example.com/file.ttl|format=ttl|gzip|abcdef123456789:12345"
80+ )
81+ click .echo (f"[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 )
84+ return
85+
86+ raise click .UsageError (
87+ "No valid input provided. Please use one of the following modes:\n "
88+ " - Classic deploy: pass distributions as arguments\n "
89+ " - Metadata deploy: use --metadata <file>\n "
90+ " - Upload & deploy: use --webdav-url, --remote, --path, and file arguments"
91+ )
11292
11393
11494@app .command ()
0 commit comments