From 8e69fda46c4a4c99ecfe82fbd0d14cded58d5252 Mon Sep 17 00:00:00 2001 From: Ben Steffen Date: Tue, 26 Nov 2019 16:12:19 -0500 Subject: [PATCH] Rename const variables in all caps src_path -> SRC_PATH src_dirpath -> SRC_DIRPATH cache_path -> CACHE_PATH lock_path -> LOCK_PATH --- python/invirt/config.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/python/invirt/config.py b/python/invirt/config.py index f9bff6a..6763c5c 100644 --- a/python/invirt/config.py +++ b/python/invirt/config.py @@ -6,10 +6,10 @@ import yaml import invirt.common -src_path = '/etc/invirt/master.yaml' -src_dirpath = '/etc/invirt/conf.d' -cache_path = '/var/lib/invirt/cache.json' -lock_path = '/var/lib/invirt/cache.lock' +SRC_PATH = '/etc/invirt/master.yaml' +SRC_DIRPATH = '/etc/invirt/conf.d' +CACHE_PATH = '/var/lib/invirt/cache.json' +LOCK_PATH = '/var/lib/invirt/cache.lock' def augment(d1, d2): """ @@ -54,8 +54,8 @@ def run_parts_list(dirname): yield os.path.join(dirname, name) def list_files(): - yield src_path - for name in run_parts_list(src_dirpath): + yield SRC_PATH + for name in run_parts_list(SRC_DIRPATH): yield name def load_master(): @@ -67,13 +67,13 @@ def load_master(): def get_src_mtime(): return max(max(os.path.getmtime(filename) for filename in list_files()), - os.path.getmtime(src_dirpath)) + os.path.getmtime(SRC_DIRPATH)) 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 - instead from the original YAML file at src_path and regenerate the cache. + CACHE_PATH. If it doesn't exist or is outdated, load the configuration + instead from the original YAML file at SRC_PATH and regenerate the cache. I assume I have the permissions to write to the cache directory. """ @@ -86,7 +86,7 @@ def load(force_refresh=False): else: src_mtime = get_src_mtime() try: - cache_mtime = os.path.getmtime(cache_path) + cache_mtime = os.path.getmtime(CACHE_PATH) except OSError: do_refresh = True else: @@ -96,7 +96,7 @@ def load(force_refresh=False): # # do_refresh = src_mtime >= cache_time # - # because between the getmtime(src_path) and the time the cache is + # because between the getmtime(SRC_PATH) and the time the cache is # rewritten, the master configuration may have been updated, so future # checks here would find a cache with a newer mtime than the master # (and thus treat the cache as containing the latest version of the @@ -117,7 +117,7 @@ def load(force_refresh=False): # lock with other concurrent reads). This isolation is accomplished # using an atomic filesystem rename in the refreshing stage. try: - with open(cache_path) as f: + with open(CACHE_PATH) as f: ns.cfg = json.read(f.read()) except: do_refresh = True @@ -130,15 +130,15 @@ def load(force_refresh=False): # transactionally isolated from the above cache read. If we fail to # acquire the lock, just try to load the master configuration. try: - with invirt.common.open_locked(lock_path): + with invirt.common.open_locked(LOCK_PATH): ns.cfg = load_master() try: - with open(cache_path + '.tmp', 'w') as f: + 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) + os.rename(CACHE_PATH + '.tmp', CACHE_PATH) except IOError: ns.cfg = load_master() return ns.cfg -- 1.7.9.5