X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Ftrust%2Ftrustedroots.py;h=5f8dcd3c2275bbfcbfddd74f8d1564cb9632ff85;hb=fd395e1944dcd49f10a4d5b27ce4983ad389fb96;hp=fb6b6425d43cb7ad19daa16fecc8078f242ee541;hpb=b835890db506439d1925577ccdc9ef4f0b3dc6ac;p=sfa.git diff --git a/sfa/trust/trustedroots.py b/sfa/trust/trustedroots.py index fb6b6425..5f8dcd3c 100644 --- a/sfa/trust/trustedroots.py +++ b/sfa/trust/trustedroots.py @@ -4,17 +4,18 @@ import glob from sfa.trust.gid import GID from sfa.util.sfalogging import logger + class TrustedRoots: - + # we want to avoid reading all files in the directory # this is because it's common to have backups of all kinds # e.g. *~, *.hide, *-00, *.bak and the like - supported_extensions= [ 'gid', 'cert', 'pem' ] + supported_extensions = ['gid', 'cert', 'pem'] def __init__(self, dir): self.basedir = dir # create the directory to hold the files, if not existing - if not os.path.isdir (self.basedir): + if not os.path.isdir(self.basedir): os.makedirs(self.basedir) def add_gid(self, gid): @@ -22,22 +23,23 @@ class TrustedRoots: gid.save_to_file(fn) def get_list(self): - gid_list = [GID(filename=cert_file) for cert_file in self.get_file_list()] + gid_list = [GID(filename=cert_file) + for cert_file in self.get_file_list()] return gid_list def get_file_list(self): - file_list = [] - pattern = os.path.join(self.basedir,"*") + file_list = [] + pattern = os.path.join(self.basedir, "*") for cert_file in glob.glob(pattern): if os.path.isfile(cert_file): if self.has_supported_extension(cert_file): - file_list.append(cert_file) + file_list.append(cert_file) else: logger.warning("File {} ignored - supported extensions are {}" .format(cert_file, TrustedRoots.supported_extensions)) return file_list - def has_supported_extension (self,path): - (_,ext)=os.path.splitext(path) - ext=ext.replace('.','').lower() + def has_supported_extension(self, path): + _, ext = os.path.splitext(path) + ext = ext.replace('.', '').lower() return ext in TrustedRoots.supported_extensions