Skip to content

Commit a56f01d

Browse files
committed
added deploying to the databus without upload to nextcloud
1 parent 9edc0dc commit a56f01d

File tree

4 files changed

+65
-13
lines changed

4 files changed

+65
-13
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@
55
python3 -m pip install databusclient
66
```
77

8+
## Deploy to Databus
9+
Please add databus API_KEY to .env file
10+
Use metadata.json file to list all files which should be added to the databus
11+
12+
The script registers all files on the databus.
13+
### Example Call
14+
```bash
15+
cd databusclient
16+
17+
python deploy.py \
18+
--no-upload \
19+
--metadata ./metadata.json \
20+
--version-id https://databus.org/user/dataset/version/1.0 \
21+
--title "Test Dataset" \
22+
--abstract "This is a short abstract of the test dataset." \
23+
--description "This dataset was uploaded for testing the Nextcloud → Databus deployment pipeline." \
24+
--license https://dalicc.net/licenselibrary/Apache-2.0
25+
26+
```
27+
828
## Upload to Nextcloud and Deploy to Databus
929
Please add databus API_KEY to .env file
1030

databusclient/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,9 @@ def download(
480480
query = __handle_databus_collection__(endpoint,databusURI)
481481
res = __handle__databus_file_query__(endpoint, query)
482482
else:
483-
print("dataId not supported yet") #TODO add support for other DatabusIds here (artifact, group, etc.)
483+
query = __handle_databus_collection__(endpoint,databusURI)
484+
res = __handle__databus_file_query__(endpoint, query)
485+
__download_list__(res,localDir)
484486
# query in local file
485487
elif databusURI.startswith("file://"):
486488
print("query in file not supported yet")

databusclient/deploy.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
import argparse
4+
import json
45

56
from databusclient import create_distribution, create_dataset, deploy
67
from dotenv import load_dotenv
@@ -16,16 +17,14 @@ def deploy_to_databus(
1617
description,
1718
license_url
1819
):
19-
2020
load_dotenv()
2121
api_key = os.getenv("API_KEY")
2222
if not api_key:
2323
raise ValueError("API_KEY not found in .env")
2424

2525
distributions = []
26-
counter=0
26+
counter = 0
2727
for filename, checksum, size, url in metadata:
28-
2928
parts = filename.split(".")
3029
if len(parts) == 1:
3130
file_format = "none"
@@ -40,13 +39,13 @@ def deploy_to_databus(
4039
distributions.append(
4140
create_distribution(
4241
url=url,
43-
cvs={"count":f"{counter}"},
42+
cvs={"count": f"{counter}"},
4443
file_format=file_format,
4544
compression=compression,
4645
sha256_length_tuple=(checksum, size)
4746
)
4847
)
49-
counter+=1
48+
counter += 1
5049

5150
dataset = create_dataset(
5251
version_id=version_id,
@@ -62,12 +61,16 @@ def deploy_to_databus(
6261

6362
print(f"Successfully deployed\n{metadata_string}\nto databus {version_id}")
6463

64+
6565
def parse_args():
6666
parser = argparse.ArgumentParser(description="Upload files to Nextcloud and deploy to DBpedia Databus.")
67-
parser.add_argument("files", nargs="+", help="Path(s) to file(s) or folder(s) to upload")
68-
parser.add_argument("--webdav-url", required=True, help="URL to webdav cloud(e.g., 'https://cloud.scadsai.uni-leipzig.de/remote.php/webdav')")
69-
parser.add_argument("--remote", required=True, help="rclone remote name (e.g., 'nextcloud')")
70-
parser.add_argument("--path", required=True, help="Remote path on Nextcloud (e.g., 'datasets/mydataset')")
67+
parser.add_argument("files", nargs="*", help="Path(s) to file(s) or folder(s) to upload")
68+
parser.add_argument("--webdav-url", help="WebDAV URL (e.g., https://cloud.example.com/remote.php/webdav)")
69+
parser.add_argument("--remote", help="rclone remote name (e.g., 'nextcloud')")
70+
parser.add_argument("--path", help="Remote path on Nextcloud (e.g., 'datasets/mydataset')")
71+
parser.add_argument("--no-upload", action="store_true", help="Skip file upload and use existing metadata")
72+
parser.add_argument("--metadata", help="Path to metadata JSON file (required if --no-upload is used)")
73+
7174
parser.add_argument("--version-id", required=True, help="Databus version URI")
7275
parser.add_argument("--title", required=True, help="Title of the dataset")
7376
parser.add_argument("--abstract", required=True, help="Short abstract of the dataset")
@@ -76,11 +79,24 @@ def parse_args():
7679

7780
return parser.parse_args()
7881

79-
if __name__ == '__main__':
8082

83+
if __name__ == '__main__':
8184
args = parse_args()
8285

83-
metadata = upload_to_nextcloud(args.files, args.remote, args.path, args.webdav_url)
86+
if args.no_upload:
87+
if not args.metadata:
88+
print("Error: --metadata is required when using --no-upload")
89+
sys.exit(1)
90+
if not os.path.isfile(args.metadata):
91+
print(f"Error: Metadata file not found: {args.metadata}")
92+
sys.exit(1)
93+
with open(args.metadata, 'r') as f:
94+
metadata = json.load(f)
95+
else:
96+
if not (args.webdav_url and args.remote and args.path):
97+
print("Error: --webdav-url, --remote, and --path are required unless --no-upload is used")
98+
sys.exit(1)
99+
metadata = upload_to_nextcloud(args.files, args.remote, args.path, args.webdav_url)
84100

85101
deploy_to_databus(
86102
metadata,
@@ -89,4 +105,4 @@ def parse_args():
89105
abstract=args.abstract,
90106
description=args.description,
91107
license_url=args.license
92-
)
108+
)

databusclient/metadata.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
[
3+
"example.ttl",
4+
"6e340b9cffb37a989ca544e6bb780a2c7e5d7dcb",
5+
12345,
6+
"https://cloud.example.com/remote.php/webdav/datasets/mydataset/example.ttl"
7+
],
8+
[
9+
"example.csv.gz",
10+
"3f786850e387550fdab836ed7e6dc881de23001b",
11+
54321,
12+
"https://cloud.example.com/remote.php/webdav/datasets/mydataset/example.csv.gz"
13+
]
14+
]

0 commit comments

Comments
 (0)