Skip to content

Commit

Permalink
Update register_to_rucio.py
Browse files Browse the repository at this point in the history
Switch to using rucio upload client instead of manually registering files
  • Loading branch information
rahmans1 authored Dec 20, 2024
1 parent 38a64d5 commit 3a0fe12
Showing 1 changed file with 20 additions and 42 deletions.
62 changes: 20 additions & 42 deletions scripts/register_to_rucio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,28 @@

import argparse
import os
from rucio.client import Client
from rucio.common import exception
from rucio.common.utils import adler32
from rucio.client.uploadclient import UploadClient

parser = argparse.ArgumentParser(prog='Register to RUCIO', description='Registers files to RUCIO')

parser.add_argument("-f", dest="file_path", action="store", required=True, help="Enter the file path")
parser.add_argument("--du", dest="file_size", action="store", required=True, help="Enter the file size")

parser.add_argument("-f", dest="file_path", action="store", required=True, help="Enter the local file path")
parser.add_argument("-d", dest="did_name", action="store", required=True, help="Enter the data identifier for rucio catalogue")
parser.add_argument("-s", dest="scope", action="store", required=True, help="Enter the scope")
args=parser.parse_args()

rse_url="https://dtn-rucio.jlab.org:1094/" # Change this to an array later to add BNL rucio
rse_name="EIC-XRD"
scope="epic"
file_path = args.file_path
file_size = args.file_size
parent_dir=os.path.dirname(file_path)

client=Client()

try:
client.add_dataset(scope=scope, name=parent_dir)
except exception.DataIdentifierAlreadyExists:
print(f"Dataset {parent_dir} already exists its okay")
except Exception as e:
print(f"Dataset {parent_dir} failed to add. error: {e}")

pfn = rse_url + file_path
replicas = [{ # Change this to an array later to add BNL rucio
'scope': scope,
'name': file_path,
'bytes': file_size,
'adler32': adler32(file_path),
'pfn': pfn
}]

try:
client.add_replicas(rse=rse_name, files=replicas)
except exception.FileReplicaAlreadyExists:
print(f"file replicas already exists")
except Exception as e:
print(f"Error adding replicas: {e}")

try:
client.attach_dids(scope=scope, name=parent_dir, dids=[{'scope': scope, 'name': r['name']} for r in replicas])
except Exception as e:
print(f"Error attaching files to dataset: {e}")
did_name = args.did_name
parent_directory = os.path.dirname(did_name)
scope= args.scope
rse="EIC-XRD"

uploads_items = [{
'path': file_path,
'rse': rse,
'did_scope': scope,
'did_name': did_name,
'dataset_scope' = scope,
'dataset_name' = parent_directory
}]

upload_client = UploadClient()
upload_client.upload(uploads_items)

0 comments on commit 3a0fe12

Please sign in to comment.