11import os
22import sys
33import argparse
4+ import json
45
56from databusclient import create_distribution , create_dataset , deploy
67from 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 } \n to databus { version_id } " )
6463
64+
6565def 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+ )
0 commit comments