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
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
#
# (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
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