forked from pseyfert/gangascripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_access_urls.py
74 lines (73 loc) · 2.6 KB
/
get_access_urls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# USAGE
# SetupLHCbDirac
# lhcb-proxy-init
# python SCRIPTNAME lfn <lfn <lfn ....>>
from DIRAC.Core.Base import Script
Script.parseCommandLine(ignoreErrors=False)
import sys
import re
import DIRAC.Interfaces.API.Dirac as Dirac
d = Dirac.Dirac()
lfns = sys.argv[1:]
try:
large_dict = d.getReplicas(lfns)['Value']['Successful']
except KeyError:
print "didn't work with input ",lfns
else:
print "got all replicas"
sites = []
site_lfn_maps = {}
for lfn in lfns:
try:
thismap = large_dict[lfn]
except KeyError:
print "failed with ", lfn
else:
try:
site_lfn_maps[thismap.keys()[-1]]
except KeyError:
site_lfn_maps[thismap.keys()[-1]] = [lfn]
else:
site_lfn_maps[thismap.keys()[-1]].append(lfn)
sites = site_lfn_maps.keys()
print "mapped sites to lfns"
for site in sites:
print "processing ", site
if re.match("CNAF.*",site) is None:
try:
site_lfn_maps[site]
except KeyError:
pass
else:
try:
access_dict = d.getAccessURL(site_lfn_maps[site],site)['Value']['Successful']
except KeyError:
print "failed resolving access urls (in standard treatment) at ", site
else:
for k in access_dict.keys():
print access_dict[k]
else:
try:
site_lfn_maps[site]
except KeyError:
pass
else:
import subprocess
output = subprocess.check_output(["dirac-dms-lfn-accessURL","--Protocol=root,xroot"]+site_lfn_maps[site]+[site])
urllines = []
local_dict = {}
for line in output.split('\n'):
if re.match(".* : .*root.*://.*",line) is not None:
#print "the line is ", line
lfn = re.sub(" *: .*root.*://.*$","",re.sub("^ *","",line))
url = re.sub(" *$","",re.sub(" *"+lfn+" * : *","",line))
#print "lfn: ",lfn
#print "url: ",url
local_dict[lfn] = url
#print "looking for ", site_lfn_maps[site]
#print "got ",local_dict
for lfn in site_lfn_maps[site]:
try:
print local_dict[lfn]
except KeyError:
print "failed resolving access urls (in CNAF treatment) at ", site