Remove dicts and structs globals with config, which is a plain dict, and streamline...
authorBen Steffen <bds@mit.edu>
Tue, 26 Nov 2019 21:50:58 +0000 (16:50 -0500)
committerBen Steffen <bds@mit.edu>
Tue, 26 Nov 2019 21:50:58 +0000 (16:50 -0500)
python/invirt/config.py

index 3ed586c..b06e74b 100644 (file)
@@ -59,11 +59,11 @@ def list_files():
     yield from run_parts_list(SRC_DIRPATH)
 
 def load_master():
-    config = dict()
+    cfg = dict()
     for filename in list_files():
         with open(filename) as f:
-            augment(config, yaml.load(f, yaml.CSafeLoader))
-    return config
+            augment(cfg, yaml.load(f, yaml.CSafeLoader))
+    return cfg
 
 def get_src_mtime():
     return max(max(os.path.getmtime(filename) for filename in list_files()),
@@ -77,9 +77,7 @@ def load(force_refresh=False):
     I assume I have the permissions to write to the cache directory.
     """
 
-    # Namespace container for state variables, so that they can be updated by
-    # closures.
-    ns = struct()
+    cfg = dict()
 
     if force_refresh:
         do_refresh = True
@@ -118,7 +116,7 @@ def load(force_refresh=False):
         # using an atomic filesystem rename in the refreshing stage.
         try:
             with open(CACHE_PATH) as f:
-                ns.cfg = json.read(f.read())
+                cfg = json.load(f)
         except:
             do_refresh = True
 
@@ -131,17 +129,17 @@ def load(force_refresh=False):
         # acquire the lock, just try to load the master configuration.
         try:
             with invirt.common.open_locked(LOCK_PATH):
-                ns.cfg = load_master()
+                cfg = load_master()
                 try:
                     with open(CACHE_PATH + '.tmp', 'w') as f:
-                        f.write(json.write(ns.cfg))
+                        json.dump(cfg, f)
                 except:
                     pass # silent failure
                 else:
                     os.rename(CACHE_PATH + '.tmp', CACHE_PATH)
         except IOError:
-            ns.cfg = load_master()
-    return ns.cfg
+            cfg = load_master()
 
-dicts = load()
-structs = dicts2struct(dicts, '')
+    return cfg
+
+config = load()