Skip to content

Commit 2028873

Browse files
committed
add --list-names option to print pre-configured list names
1 parent 726e260 commit 2028873

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

stashcp/__init__.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
# Global variable for the location of the token to use for reading / writing
4949
token_location = None
5050

51+
# Global variable to print names of cache lists
52+
print_cache_list_names = False
53+
5154
TIMEOUT = 300
5255
DIFF = TIMEOUT * 10
5356

@@ -680,6 +683,15 @@ def get_stashservers_caches(responselines):
680683
lists = responselines[4].split(';')
681684
logging.debug("Cache lists: %s", lists)
682685

686+
if print_cache_list_names:
687+
names = ""
688+
# skip hash at the end
689+
for l in lists[0:-1]:
690+
names = names + ',' + l.split('=')[0]
691+
# skip leading comma
692+
print(names[1:])
693+
sys.exit(0)
694+
683695
if cache_list_name == None:
684696
caches = lists[0].split('=')[1]
685697
else:
@@ -812,6 +824,7 @@ def main():
812824
default=None)
813825
parser.add_option('-n', '--cache-list-name', dest='cache_list_name', help="Name of pre-configured cache list to use",
814826
default=None)
827+
parser.add_option('--list-names', dest='list_names', action='store_true', help="Return the names of pre-configured cache lists and exit (first one is default for -n)")
815828
parser.add_option('--methods', dest='methods', help="Comma separated list of methods to try, in order. Default: cvmfs,xrootd,http", default="cvmfs,xrootd,http")
816829
parser.add_option('-t', '--token', dest='token', help="Token file to use for reading and/or writing")
817830
args,opts=parser.parse_args()
@@ -826,12 +839,19 @@ def main():
826839
else:
827840
logger.setLevel(logging.WARNING)
828841

842+
if args.list_names:
843+
global print_cache_list_names
844+
print_cache_list_names = True
845+
get_best_stashcache()
846+
# does not return
847+
829848
if 'CACHES_JSON' in os.environ:
830849
caches_json_location = os.environ['CACHES_JSON']
831850
else:
832851
caches_json_location = args.caches_json
852+
833853
cache_list_name = args.cache_list_name
834-
if args.closest:
854+
if args.closest or args.list_names:
835855
print get_best_stashcache()
836856
sys.exit(0)
837857

0 commit comments

Comments
 (0)