Commits

Anonymous committed b616649

first step: getting an arbitrary list.

Comments (0)

Files changed (1)

+#!/usr/bin/env python3
+
+import yaml
+from os.path import join
+def get_data_for_key(key):
+    """Get the data for the given key.
+
+    >>> a = get_data_for_key("KSK@gpl.txt")
+    >>> list(a)
+    []
+    """
+    try: 
+        keypath = join("site", key.split("/")[0])
+        filename = "/" + "/".join(key.split("/")[1])
+    except IndexError:
+        # no "/" in path. 
+        keypath = key
+        filename = "/"
+
+    # ksk keys are in their own file.
+    if keypath.startswith("KSK"):
+        keypath = "KSK"
+        filename = key
+        
+    try: 
+        with open(keypath) as f: 
+            yaml_data = f.read()
+    except IOError:
+        return (i for i in []) # empty generator
+    data = yaml.safe_load_all(yaml_data)
+    return data
+
+def _test():
+    from doctest import testmod
+    testmod()
+
+if __name__ == "__main__":
+    from sys import argv
+    if "--test" in argv: 
+        _test()
+        exit()