modify how we define trusted root basedir
[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             self.basedir = config.path + os.sep + 'trusted_roots'
11         else:
12             self.basedir = dir
13         # create the directory to hold the files
14         try:
15             os.makedirs(self.basedir)\r
16         # if the path already exists then pass\r
17         except OSError, (errno, strerr):\r
18             if errno == 17:\r
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