<commit_before>### $Id$
### $URL$

import os

from sfa.trust.gid import *

class TrustedRootList:
    def __init__(self, dir):
        self.basedir = dir
        
        # create the directory to hold the files
        try:
            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)
                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)

        return gid_file_list
<commit_msg>scan only *.gid files in /etc/sfa/trusted_roots previous behaviour was to scan all files, which was error-prone<commit_after>import os.path
import glob

from sfa.trust.gid import GID

class TrustedRootList:
    def __init__(self, dir):
        self.basedir = dir
        # create the directory to hold the files, if not existing
        if not os.path.isdir (self.basedir):
            os.makedirs(self.basedir)

    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 = []
        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 = []
        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

{'fraction_non_alphanumeric': 0.09987410826689047, 'fraction_numerical': 0.000839278220730172, 'mean_word_length': 1.882708585247884, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2939585', 'n_tokens_mistral': 827, 'n_tokens_neox': 775, 'n_words': 174}