From 73848b129eb98d6b43037cc0223d38e9a9172445 Mon Sep 17 00:00:00 2001 From: Ben Steffen Date: Tue, 26 Nov 2019 16:10:54 -0500 Subject: [PATCH] Fix formatting --- python/invirt/config.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/python/invirt/config.py b/python/invirt/config.py index 93d61c7..f9bff6a 100644 --- a/python/invirt/config.py +++ b/python/invirt/config.py @@ -69,7 +69,7 @@ def get_src_mtime(): return max(max(os.path.getmtime(filename) for filename in list_files()), os.path.getmtime(src_dirpath)) -def load(force_refresh = False): +def load(force_refresh=False): """ Try loading the configuration from the faster-to-load JSON cache at cache_path. If it doesn't exist or is outdated, load the configuration @@ -85,9 +85,12 @@ def load(force_refresh = False): do_refresh = True else: src_mtime = get_src_mtime() - try: cache_mtime = os.path.getmtime(cache_path) - except OSError: do_refresh = True - else: do_refresh = src_mtime + 1 >= cache_mtime + try: + cache_mtime = os.path.getmtime(cache_path) + except OSError: + do_refresh = True + else: + do_refresh = src_mtime + 1 >= cache_mtime # We chose not to simply say # @@ -113,10 +116,11 @@ def load(force_refresh = False): # (changing) version of the data (but the transaction can share the # lock with other concurrent reads). This isolation is accomplished # using an atomic filesystem rename in the refreshing stage. - try: + try: with open(cache_path) as f: ns.cfg = json.read(f.read()) - except: do_refresh = True + except: + do_refresh = True if do_refresh: # Atomically reload the source and regenerate the cache. The read and @@ -128,11 +132,13 @@ def load(force_refresh = False): try: with invirt.common.open_locked(lock_path): ns.cfg = load_master() - try: + try: with open(cache_path + '.tmp', 'w') as f: f.write(json.write(ns.cfg)) - except: pass # silent failure - else: os.rename(cache_path + '.tmp', cache_path) + except: + pass # silent failure + else: + os.rename(cache_path + '.tmp', cache_path) except IOError: ns.cfg = load_master() return ns.cfg -- 1.7.9.5