@@ -272,7 +272,7 @@ def fetch_s5_metadata(product_url, title, metadata_dir):
272
272
request_with_progress (url , output_file )
273
273
274
274
275
- def regenerate_href_links (stacfile_path , metadata_dir , product_url ):
275
+ def regenerate_href_links (stacfile_path , metadata_dir , product_url , salt ):
276
276
"""
277
277
Replaces href links in the final json containing the local path to contain the OData path and format.
278
278
Cannot use stactools' create_item function parameters for this change, as the stac module is then actually reading
@@ -285,12 +285,18 @@ def regenerate_href_links(stacfile_path, metadata_dir, product_url):
285
285
with (open (stacfile_path , 'r' ) as infile , open (new_file , 'w' ) as outfile ):
286
286
for line in infile :
287
287
if metadata_dir in line :
288
+ # replace file links
288
289
split_line = line .split ('"' ) # [' ', 'href', ': ', 'matadata_dir/resource/path', '\n']
289
290
url_path_segments = split_line [- 2 ].split (f"{ metadata_dir } { '/' } " )[1 ].split ("/" )
290
291
correct_link = product_url + '' .join (
291
292
f"/Nodes('{ segment } ')" for segment in url_path_segments ) + "/$value"
292
293
split_line [- 2 ] = correct_link
293
294
outfile .write ('"' .join (split_line ))
295
+ elif '"id":' in line and salt :
296
+ # prefix title, so unique UUID is generated if same product comes from different sources
297
+ split_line = line .split ('": "' )
298
+ salted_line = split_line [0 ] + '": "' + salt + split_line [1 ]
299
+ outfile .write (salted_line )
294
300
else :
295
301
outfile .write (line )
296
302
os .replace (new_file , stacfile_path )
@@ -398,6 +404,7 @@ def main():
398
404
die_with_error ("Flag --push was provided, but SUCC_PREFIX and ERR_PREFIX need to be set in the configuration "
399
405
"file for logging!" )
400
406
407
+ salt = config .get ("SALT" )
401
408
if args .push and not stac_host :
402
409
die_with_error ('--push requires --stacHost argument or STAC_HOST configuration option to be set!' )
403
410
@@ -444,7 +451,7 @@ def main():
444
451
print (f"Writing metadata to file: { stac_filepath } " )
445
452
item .save_object (dest_href = stac_filepath , include_self_link = False )
446
453
447
- regenerate_href_links (stac_filepath , metadata_dir , product_url )
454
+ regenerate_href_links (stac_filepath , metadata_dir , product_url , salt )
448
455
449
456
if args .push :
450
457
upload_to_catalogue (stac_host , stac_filepath , overwrite = args .overwrite )
0 commit comments