<commit_before>from functools import wraps
import itertools
import os
import datetime
from rezoirclogs.utils import LogLine


class Base(object):
    """Base resource object, useful for debugging"""
    __name__ = ''
    __parent__ = None

    def __repr__(self):
        return u'<%s: %s>' % (self.__class__.__name__, self.__name__)


def jailed(f):
    @wraps(f)
    def jailed_f(self, path):
        if path.startswith(self.root_path):
            return f(self, path)
    return jailed_f


class Filesystem(object):
    """Jailed wrapper around os.path"""
    def __init__(self, root_path):
        self.root_path = os.path.abspath(os.path.normpath(root_path))

    join = staticmethod(os.path.join)

    @jailed
    def listdir(self, path):
        return os.listdir(path)

    @jailed
    def isrealfile(self, path):
        return os.path.isfile(path) and not os.path.islink(path)

    @jailed
    def isrealdir(self, path):
        return os.path.isdir(path) and not os.path.islink(path)

    def open(self, path):
        return open(path)


class LogFile(Base):
    def __init__(self, filesystem, path, date):
        self.fs = filesystem
        self.path = os.path.abspath(os.path.normpath(path))
        self.date = datetime.date(int(date[0:4]), int(date[4:6]), int(date[6:8]))

    def __iter__(self):
        for line in self.fs.open(self.path):
            yield LogLine(line)

    def neighbour(self, n):
        wanted = self.date + datetime.timedelta(days=n)
        wanted = wanted.strftime('%Y%m%d')
        try:
            return self.__parent__[wanted]
        except KeyError:
            return

    @property
    def previous(self):
        return self.neighbour(-1)<commit_msg>Ajouté du logging pour les accès fs.<commit_after>from functools import wraps
import itertools
import os
import datetime
import logging
from rezoirclogs.utils import LogLine

log = logging.getLogger(__name__)

class Base(object):
    """Base resource object, useful for debugging"""
    __name__ = ''
    __parent__ = None

    def __repr__(self):
        return u'<%s: %s>' % (self.__class__.__name__, self.__name__)


def jailed(f):
    @wraps(f)
    def jailed_f(self, path):
        if path.startswith(self.root_path):
            return f(self, path)
    return jailed_f


class Filesystem(object):
    """Jailed wrapper around os.path"""
    def __init__(self, root_path):
        self.root_path = os.path.abspath(os.path.normpath(root_path))

    join = staticmethod(os.path.join)

    @jailed
    def listdir(self, path):
        log.debug('listdir %s', path)
        return os.listdir(path)

    @jailed
    def isrealfile(self, path):
        log.debug('isrealfile %s', path)
        return os.path.isfile(path) and not os.path.islink(path)

    @jailed
    def isrealdir(self, path):
        log.debug('isrealdir %s', path)
        return os.path.isdir(path) and not os.path.islink(path)

    def open(self, path):
        log.debug('open %s', path)
        return open(path)


class LogFile(Base):
    def __init__(self, filesystem, path, date):
        self.fs = filesystem
        self.path = os.path.abspath(os.path.normpath(path))
        self.date = datetime.date(int(date[0:4]), int(date[4:6]), int(date[6:8]))

    def __iter__(self):
        for line in self.fs.open(self.path):
            yield LogLine(line)

    def neighbour(self, n):
        wanted = self.date + datetime.timedelta(days=n)
        wanted = wanted.strftime('%Y%m%d')
        try:
            return self.__parent__[wanted]
        except KeyError:
            return

    @property
    def previous(self):
        return self.neighbour(-1)
{'fraction_non_alphanumeric': 0.12403740374037404, 'fraction_numerical': 0.0038503850385038503, 'mean_word_length': 2.696138211382114, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4406500', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1193, 'n_words': 279}