@@ -26,6 +26,9 @@ writeback_host = "http://stash-xrd.osgconnect.net:1094"
2626# Global variable for nearest cache
2727nearest_cache = None
2828
29+ # Global variable for the location of the caches.json file
30+ caches_json_location = None
31+
2932TIMEOUT = 300
3033DIFF = TIMEOUT * 10
3134
@@ -379,10 +382,16 @@ def get_ips(name):
379382 return ipv4s + ipv6s
380383
381384def get_best_stashcache ():
382- prefix = os .environ .get ("OSG_LOCATION" , "" )
383- cache_files = [os .path .join (os .path .dirname (os .path .realpath (__file__ )), "caches.json" ),
384- os .path .join (prefix , "/etc/stashcache/caches.json" ),
385- os .path .join (prefix , "/usr/share/stashcache/caches.json" )]
385+
386+ # Check if the user provided a caches json file location
387+ if caches_json_location and os .path .exists (caches_json_location ):
388+ cache_files = [ caches_json_location ]
389+ else :
390+ prefix = os .environ .get ("OSG_LOCATION" , "" )
391+ cache_files = [os .path .join (os .path .dirname (os .path .realpath (__file__ )), "caches.json" ),
392+ os .path .join (prefix , "/etc/stashcache/caches.json" ),
393+ os .path .join (prefix , "/usr/share/stashcache/caches.json" )]
394+
386395 for cache_file in cache_files :
387396 if os .path .isfile (cache_file ):
388397 with open (cache_file , 'r' ) as f :
@@ -460,13 +469,16 @@ def get_best_stashcache():
460469
461470def main ():
462471 global nearest_cache
463-
472+ global caches_json_location
473+
464474 usage = "usage: %prog [options] source destination"
465475 parser = optparse .OptionParser (usage )
466476 parser .add_option ('-d' , '--debug' , dest = 'debug' , action = 'store_true' , help = 'debug' )
467477 parser .add_option ('-r' , dest = 'recursive' , action = 'store_true' , help = 'recursively copy' )
468- parser .add_option ('--closest' , action = 'store_true' )
478+ parser .add_option ('--closest' , action = 'store_true' , help = "Return the closest cache and exit" )
469479 parser .add_option ('-c' , '--cache' , dest = 'cache' , help = "Cache to use" )
480+ parser .add_option ('-j' , '--caches-json' , dest = 'caches_json' , help = "The JSON file containing the list of caches" ,
481+ default = None )
470482 args ,opts = parser .parse_args ()
471483
472484 logging .basicConfig (format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s' ,
@@ -478,7 +490,8 @@ def main():
478490 logger .setLevel (logging .DEBUG )
479491 else :
480492 logger .setLevel (logging .WARNING )
481-
493+
494+ caches_json_location = args .caches_json
482495 if args .closest :
483496 print get_best_stashcache ()
484497 sys .exit (0 )
0 commit comments