@@ -11,8 +11,11 @@ def getOS():
11
11
osv = subprocess .check_output (shlex .split (cmd ), encoding = "utf-8" ).rstrip ()
12
12
return osv
13
13
14
- def getHosted (dataset , user ):
14
+ def getHosted (dataset , user , allow = None , block = None ):
15
15
"""Gets list of files on disk for a dataset, and list of sites along with how many files each site has"""
16
+ if allow is not None and block is not None :
17
+ raise RuntimeError ("Cannot specify both allow list and block list, pick one" )
18
+
16
19
osv = getOS ()
17
20
rucio_path = f'/cvmfs/cms.cern.ch/rucio/x86_64/rhel{ osv } /py3/current'
18
21
os .environ ['RUCIO_HOME' ] = rucio_path
@@ -37,7 +40,7 @@ def getHosted(dataset, user):
37
40
filelist = set ()
38
41
sitelist = defaultdict (int )
39
42
def sitecond (site ):
40
- return "_Tape" not in site
43
+ return ( "_Tape" not in site ) and ( allow is None or site in allow ) and ( block is None or site not in block )
41
44
for block_group in block_groups :
42
45
reps = list (rep_client .list_replicas ([{'scope' : 'cms' , 'name' : block ['name' ]} for block in block_group ]))
43
46
for rep in reps :
@@ -49,9 +52,9 @@ def sitecond(site):
49
52
sys .path .pop (0 )
50
53
return filelist , sitelist
51
54
52
- def main (dataset , user , outfile = None , verbose = False ):
55
+ def main (dataset , user , outfile = None , verbose = False , allow = None , block = None ):
53
56
"""Prints file list and site list"""
54
- filelist , sitelist = getHosted (dataset , user )
57
+ filelist , sitelist = getHosted (dataset , user , allow = allow , block = block )
55
58
56
59
if verbose :
57
60
print ("Site list:" )
@@ -65,12 +68,15 @@ def main(dataset, user, outfile=None, verbose=False):
65
68
default_user = getpass .getuser ()
66
69
parser = argparse .ArgumentParser (
67
70
formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
68
- description = "Find all available files (those hosted on disk) for a given dataset" ,
71
+ description = "Find all available files (those hosted on disk) for a given dataset"
69
72
)
73
+ site_args = parser .add_mutually_exclusive_group (required = False )
74
+ site_args .add_argument ("-a" ,"--allow" ,type = str ,default = None ,nargs = '*' ,help = "allow only these sites" )
75
+ site_args .add_argument ("-b" ,"--block" ,type = str ,default = None ,nargs = '*' ,help = "block these sites" )
70
76
parser .add_argument ("-o" ,"--outfile" ,type = str ,default = None ,help = "write to this file instead of stdout" )
71
77
parser .add_argument ("-u" ,"--user" ,type = str ,default = default_user ,help = "username for rucio" )
72
78
parser .add_argument ("-v" ,"--verbose" ,default = False ,action = "store_true" ,help = "print extra information (site list)" )
73
79
parser .add_argument ("dataset" ,type = str ,help = "dataset to query" )
74
80
args = parser .parse_args ()
75
81
76
- main (args .dataset , args .user , outfile = args .outfile , verbose = args .verbose )
82
+ main (args .dataset , args .user , outfile = args .outfile , verbose = args .verbose , allow = args . allow , block = args . block )
0 commit comments