1+ import os
2+ import sys
3+ import argparse
4+
5+ from databusclient import create_distribution , create_dataset , deploy
6+ from dotenv import load_dotenv
7+
8+ from nextcloudclient .upload import upload_to_nextcloud
9+
10+
11+ def deploy_to_databus (
12+ metadata ,
13+ version_id ,
14+ title ,
15+ abstract ,
16+ description ,
17+ license_url
18+ ):
19+
20+ load_dotenv ()
21+ api_key = os .getenv ("API_KEY" )
22+ if not api_key :
23+ raise ValueError ("API_KEY not found in .env" )
24+
25+ distributions = []
26+ counter = 0
27+ for filename , checksum , size , url in metadata :
28+
29+ parts = filename .split ("." )
30+ if len (parts ) == 1 :
31+ file_format = "none"
32+ compression = "none"
33+ elif len (parts ) == 2 :
34+ file_format = parts [- 1 ]
35+ compression = "none"
36+ else :
37+ file_format = parts [- 2 ]
38+ compression = parts [- 1 ]
39+
40+ distributions .append (
41+ create_distribution (
42+ url = url ,
43+ cvs = {"count" :f"{ counter } " },
44+ file_format = file_format ,
45+ compression = compression ,
46+ sha256_length_tuple = (checksum , size )
47+ )
48+ )
49+ counter += 1
50+
51+ dataset = create_dataset (
52+ version_id = version_id ,
53+ title = title ,
54+ abstract = abstract ,
55+ description = description ,
56+ license_url = license_url ,
57+ distributions = distributions
58+ )
59+
60+ deploy (dataset , api_key )
61+ metadata_string = ",\n " .join ([entry [- 1 ] for entry in metadata ])
62+
63+ print (f"Successfully deployed\n { metadata_string } \n to databus { version_id } " )
64+
65+ def parse_args ():
66+ parser = argparse .ArgumentParser (description = "Upload files to Nextcloud and deploy to DBpedia Databus." )
67+
68+ parser .add_argument ("files" , nargs = "+" , help = "Path(s) to file(s) or folder(s) to upload" )
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')" )
71+ parser .add_argument ("--version-id" , required = True , help = "Databus version URI" )
72+ parser .add_argument ("--title" , required = True , help = "Title of the dataset" )
73+ parser .add_argument ("--abstract" , required = True , help = "Short abstract of the dataset" )
74+ parser .add_argument ("--description" , required = True , help = "Detailed description of the dataset" )
75+ parser .add_argument ("--license" , required = True , help = "License URL (e.g., https://dalicc.net/licenselibrary/Apache-2.0)" )
76+
77+ return parser .parse_args ()
78+
79+ if __name__ == '__main__' :
80+
81+ args = parse_args ()
82+
83+ metadata = upload_to_nextcloud (args .files , args .remote , args .path )
84+
85+ deploy_to_databus (
86+ metadata ,
87+ version_id = args .version_id ,
88+ title = args .title ,
89+ abstract = args .abstract ,
90+ description = args .description ,
91+ license_url = args .license
92+ )
0 commit comments