Rename const variables in all caps
authorBen Steffen <bds@mit.edu>
Tue, 26 Nov 2019 21:12:19 +0000 (16:12 -0500)
committerBen Steffen <bds@mit.edu>
Tue, 26 Nov 2019 21:12:19 +0000 (16:12 -0500)
src_path -> SRC_PATH
src_dirpath -> SRC_DIRPATH
cache_path -> CACHE_PATH
lock_path -> LOCK_PATH

python/invirt/config.py

index f9bff6a..6763c5c 100644 (file)
@@ -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