Skip to content

Commit 1190933

Browse files
committed
add allow list and block list options
1 parent e7a497c commit 1190933

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

get_files_on_disk.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ def getOS():
1111
osv = subprocess.check_output(shlex.split(cmd), encoding="utf-8").rstrip()
1212
return osv
1313

14-
def getHosted(dataset, user):
14+
def getHosted(dataset, user, allow=None, block=None):
1515
"""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+
1619
osv = getOS()
1720
rucio_path = f'/cvmfs/cms.cern.ch/rucio/x86_64/rhel{osv}/py3/current'
1821
os.environ['RUCIO_HOME'] = rucio_path
@@ -37,7 +40,7 @@ def getHosted(dataset, user):
3740
filelist = set()
3841
sitelist = defaultdict(int)
3942
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)
4144
for block_group in block_groups:
4245
reps = list(rep_client.list_replicas([{'scope': 'cms', 'name': block['name']} for block in block_group]))
4346
for rep in reps:
@@ -49,9 +52,9 @@ def sitecond(site):
4952
sys.path.pop(0)
5053
return filelist, sitelist
5154

52-
def main(dataset, user, outfile=None, verbose=False):
55+
def main(dataset, user, outfile=None, verbose=False, allow=None, block=None):
5356
"""Prints file list and site list"""
54-
filelist, sitelist = getHosted(dataset, user)
57+
filelist, sitelist = getHosted(dataset, user, allow=allow, block=block)
5558

5659
if verbose:
5760
print("Site list:")
@@ -65,12 +68,15 @@ def main(dataset, user, outfile=None, verbose=False):
6568
default_user = getpass.getuser()
6669
parser = argparse.ArgumentParser(
6770
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"
6972
)
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")
7076
parser.add_argument("-o","--outfile",type=str,default=None,help="write to this file instead of stdout")
7177
parser.add_argument("-u","--user",type=str,default=default_user,help="username for rucio")
7278
parser.add_argument("-v","--verbose",default=False,action="store_true",help="print extra information (site list)")
7379
parser.add_argument("dataset",type=str,help="dataset to query")
7480
args = parser.parse_args()
7581

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

Comments
 (0)