From: Thierry Parmentelat Date: Wed, 13 Jul 2011 10:23:58 +0000 (+0200) Subject: scan only *.gid files in /etc/sfa/trusted_roots X-Git-Tag: sfa-1.0-28~7^2~12 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=2a2d23c8e42a0a8b20d4564ca2a8bceaab482a5c;p=sfa.git scan only *.gid files in /etc/sfa/trusted_roots previous behaviour was to scan all files, which was error-prone --- diff --git a/sfa/trust/trustedroot.py b/sfa/trust/trustedroot.py index ec8d2f05..2cd4f3b9 100644 --- a/sfa/trust/trustedroot.py +++ b/sfa/trust/trustedroot.py @@ -1,44 +1,36 @@ -### $Id$ -### $URL$ +import os.path +import glob -import os - -from sfa.trust.gid import * +from sfa.trust.gid import GID class TrustedRootList: def __init__(self, dir): self.basedir = dir - - # create the directory to hold the files - try: + # create the directory to hold the files, if not existing + if not os.path.isdir (self.basedir): 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) + pattern=os.path.join(self.basedir,"*.gid") + gid_files = glob.glob(pattern) + for gid_file in gid_files: + # ignore non-files + if os.path.isfile(gid_file): + gid = GID(filename = gid_file) gid_list.append(gid) return gid_list def get_file_list(self): gid_file_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_file_list.append(fn) - + pattern=os.path.join(self.basedir,"*.gid") + gid_files = glob.glob(pattern) + for gid_file in gid_files: + # ignore non-files + if os.path.isfile(gid_file): + gid_file_list.append(gid_file) return gid_file_list