Skip to content

Commit 4151ae6

Browse files
authored
Merge pull request #93 from djw8605/custom_json
Adding custom caches.json support
2 parents 1e6e3d1 + 0bd9b21 commit 4151ae6

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ env:
1010
- OS_TYPE=centos OS_VERSION=6 XRD_CACHE="root://osgxroot.usatlas.bnl.gov"
1111
- OS_TYPE=centos OS_VERSION=6 XRD_CACHE="root://its-condor-xrootd1.syr.edu"
1212
- OS_TYPE=centos OS_VERSION=6 XRD_CACHE="root://stashcache.grid.uchicago.edu"
13+
- OS_TYPE=centos OS_VERSION=6 XRD_CACHE="root://sc-cache.chtc.wisc.edu"
1314
- OS_TYPE=centos OS_VERSION=7 XRD_CACHE="root://xrd-cache-1.t2.ucsd.edu"
1415
- OS_TYPE=centos OS_VERSION=7 XRD_CACHE="root://mwt2-stashcache.campuscluster.illinois.edu"
1516
- OS_TYPE=centos OS_VERSION=7 XRD_CACHE="root://hcc-stash.unl.edu"
1617
- OS_TYPE=centos OS_VERSION=7 XRD_CACHE="root://osgxroot.usatlas.bnl.gov"
1718
- OS_TYPE=centos OS_VERSION=7 XRD_CACHE="root://its-condor-xrootd1.syr.edu"
1819
- OS_TYPE=centos OS_VERSION=7 XRD_CACHE="root://stashcache.grid.uchicago.edu"
20+
- OS_TYPE=centos OS_VERSION=7 XRD_CACHE="root://sc-cache.chtc.wisc.edu"
1921

2022

2123
language: python

bin/stashcp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ writeback_host = "http://stash-xrd.osgconnect.net:1094"
2626
# Global variable for nearest cache
2727
nearest_cache = None
2828

29+
# Global variable for the location of the caches.json file
30+
caches_json_location = None
31+
2932
TIMEOUT = 300
3033
DIFF = TIMEOUT * 10
3134

@@ -379,10 +382,16 @@ def get_ips(name):
379382
return ipv4s + ipv6s
380383

381384
def 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

461470
def 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

Comments
 (0)