f2ec35a1e555d536749d118c0daa3e67580731c9
[sfa.git] / geni / util / trustedroot.py
1 import os
2
3 from gid import *
4 from geni.util.config import Config
5
6 class TrustedRootList():
7     def __init__(self, dir=None):
8         if not dir:
9             config = Config()
10             dir = config.basepath + os.sep + 'trusted_roots'
11         self.basedir = dir
12         
13         # create the directory to hold the files
14         try:
15             os.makedirs(self.basedir)
16         # if the path already exists then pass
17         except OSError, (errno, strerr):
18             if errno == 17:
19                 pass
20
21     def add_gid(self, gid):
22         fn = os.path.join(self.basedir, gid.get_hrn() + ".gid")
23
24         gid.save_to_file(fn)
25
26     def get_list(self):
27         gid_list = []
28
29         file_list = os.listdir(self.basedir)
30         for gid_file in file_list:
31             fn = os.path.join(self.basedir, gid_file)
32             if os.path.isfile(fn):
33                 gid = GID(filename = fn)
34                 gid_list.append(gid)
35
36         return gid_list
37