Commits

Brent Tubbs committed 1421928

adding support for gettingn config of deployed site

Comments (0)

Files changed (1)

     #TODO: support pulling role info from a web page
 
 def get_site_config(site_root):
+    """Parses and returns site.yaml"""
     site_config_file = os.path.join(site_root, 'site.yaml')
     config = yaml.safe_load(open(site_config_file, 'r').read())
     return config
 
-def get_merged_config(site_root, role):
-    config = get_site_config(site_root)
-    config.update(get_role_config(role))
-    return config
+def get_blame(site_root):
+    """Parses and returns blame.yaml in deployed site"""
+    blame_file = os.path.join(site_root, 'blame.yaml')
+    blame = yaml.safe_load(open(blame_file, 'r').read())
+    return blame
 
-
+def get_config(site_root, role=None):
+    """If given a role, returns merged site and role config,
+    else tries to read config from blame.yaml"""
+    if role is None:
+        try:
+            return get_blame(site_root)['config']
+        except IOError:
+            raise Exception("No role given, and blame.yaml not found")
+    else:
+        config = get_site_config(site_root)
+        config.update(get_role_config(role))
+        return config