shape the sfa.trust subpackage
[sfa.git] / geni / trust / trustedroot.py
diff --git a/geni/trust/trustedroot.py b/geni/trust/trustedroot.py
new file mode 100644 (file)
index 0000000..6b131b0
--- /dev/null
@@ -0,0 +1,40 @@
+### $Id$
+### $URL$
+
+import os
+
+from geni.trust.gid import *
+from geni.util.config import Config
+
+class TrustedRootList():
+    def __init__(self, dir=None):
+        if not dir:
+            config = Config()
+            dir = config.config_path + os.sep + 'trusted_roots'
+        self.basedir = dir
+        
+        # create the directory to hold the files
+        try:
+            os.makedirs(self.basedir)
+        # if the path already exists then pass
+        except OSError, (errno, strerr):
+            if errno == 17:
+                pass
+
+    def add_gid(self, gid):
+        fn = os.path.join(self.basedir, gid.get_hrn() + ".gid")
+
+        gid.save_to_file(fn)
+
+    def get_list(self):
+        gid_list = []
+
+        file_list = os.listdir(self.basedir)
+        for gid_file in file_list:
+            fn = os.path.join(self.basedir, gid_file)
+            if os.path.isfile(fn):
+                gid = GID(filename = fn)
+                gid_list.append(gid)
+
+        return gid_list
+