merging with geni-api branch
[sfa.git] / sfa / trust / trustedroot.py
1 ### $Id$
2 ### $URL$
3
4 import os
5
6 from sfa.trust.gid import *
7
8 class TrustedRootList:
9     def __init__(self, dir):
10         self.basedir = dir
11         
12         # create the directory to hold the files
13         try:
14             os.makedirs(self.basedir)
15         # if the path already exists then pass
16         except OSError, (errno, strerr):
17             if errno == 17:
18                 pass
19
20     def add_gid(self, gid):
21         fn = os.path.join(self.basedir, gid.get_hrn() + ".gid")
22
23         gid.save_to_file(fn)
24
25     def get_list(self):
26         gid_list = []
27
28         file_list = os.listdir(self.basedir)
29         for gid_file in file_list:
30             fn = os.path.join(self.basedir, gid_file)
31             if os.path.isfile(fn):
32                 gid = GID(filename = fn)
33                 gid_list.append(gid)
34
35         return gid_list
36
37     def get_file_list(self):
38         gid_file_list = []
39         
40         file_list = os.listdir(self.basedir)
41         for gid_file in file_list:
42             fn = os.path.join(self.basedir, gid_file)
43             if os.path.isfile(fn):
44                 gid_file_list.append(fn)
45
46         return gid_file_list