2cd4f3b9b1faf33843c7efed86324bf3f7829647
[sfa.git] / sfa / trust / trustedroot.py
1 import os.path
2 import glob
3
4 from sfa.trust.gid import GID
5
6 class TrustedRootList:
7     def __init__(self, dir):
8         self.basedir = dir
9         # create the directory to hold the files, if not existing
10         if not os.path.isdir (self.basedir):
11             os.makedirs(self.basedir)
12
13     def add_gid(self, gid):
14         fn = os.path.join(self.basedir, gid.get_hrn() + ".gid")
15         gid.save_to_file(fn)
16
17     def get_list(self):
18         gid_list = []
19         pattern=os.path.join(self.basedir,"*.gid")
20         gid_files = glob.glob(pattern)
21         for gid_file in gid_files:
22             # ignore non-files
23             if os.path.isfile(gid_file):
24                 gid = GID(filename = gid_file)
25                 gid_list.append(gid)
26         return gid_list
27
28     def get_file_list(self):
29         gid_file_list = []
30         pattern=os.path.join(self.basedir,"*.gid")
31         gid_files = glob.glob(pattern)
32         for gid_file in gid_files:
33             # ignore non-files
34             if os.path.isfile(gid_file):
35                 gid_file_list.append(gid_file)        
36         return gid_file_list