From ef1e0e24d8757e28b9097b5c8992a78109fd901b Mon Sep 17 00:00:00 2001 From: Matyas Selmeci Date: Fri, 12 Oct 2018 14:14:32 -0500 Subject: [PATCH] Also look for caches.json in /etc/stashcache and /usr/share/stashcache --- bin/stashcp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bin/stashcp b/bin/stashcp index 44f61ec..b844741 100755 --- a/bin/stashcp +++ b/bin/stashcp @@ -374,19 +374,19 @@ def get_ips(name): return ipv4s + ipv6s def get_best_stashcache(): - - # First, check for caches.json file in this file's directory: - dir_path = os.path.dirname(os.path.realpath(__file__)) - cache_file = os.path.join(dir_path, 'caches.json') - if not os.path.isfile(cache_file): - logging.error("Unable to find caches.json in %s", dir_path) + cache_files = [os.path.join(os.path.dirname(os.path.realpath(__file__)), "caches.json"), + "/etc/stashcache/caches.json", + "/usr/share/stashcache/caches.json"] + for cache_file in cache_files: + if os.path.isfile(cache_file): + with open(cache_file, 'r') as f: + caches_list = json.loads(f.read()) + logging.debug("Loaded caches list from %s", cache_file) + break + else: + logging.error("Unable to find caches.json in %r", cache_files) return None - - # Get all the caches from the json file - f = open(cache_file, 'r') - caches_list = json.loads(f.read()) - f.close() - + # Format the caches for the GeoIP query caches_string = "" usable_caches = []