예제 #1
0
def _get_tail_from_path(path, count=DEFAULT_LINE_COUNT):
    log_path = open(path, 'rb')

    rliter = reverse_iter_lines(log_path)
    lines = []
    for i, line in enumerate(rliter):
        if i > count:
            break
        lines.append(line)
    lines.reverse()
    return lines
예제 #2
0
    def _last_logging(self, args, response):
        """
        Get the first message by a user from a log file.
        @type   response:   firefly.containers.Response
        """
        try:
            with self.logger.read(response.channel.raw) as log:
                line = self._iterate_logfile(args.nick, reverse_iter_lines(log))
        except KeyError:
            return None

        # Make sure we got a result
        if not line:
            return None

        # Parse the datetime string
        date, name, message = line
        date = arrow.get(date, 'YYYY-MM-DD HH:mm:ss')

        return date, name, message
예제 #3
0
def _test_reverse_iter_lines(filename, blocksize=DEFAULT_BLOCKSIZE):
    fo = open(filename)
    reference = fo.read()
    fo.seek(0, os.SEEK_END)
    rev_lines = list(reverse_iter_lines(fo, blocksize))
    assert '\n'.join(rev_lines[::-1]) == reference
예제 #4
0
def _test_reverse_iter_lines(filename, blocksize=DEFAULT_BLOCKSIZE):
    fo = open(filename)
    reference = fo.read()
    fo.seek(0, os.SEEK_END)
    rev_lines = list(reverse_iter_lines(fo, blocksize))
    assert '\n'.join(rev_lines[::-1]) == reference
예제 #5
0
def _test_reverse_iter_lines_bytes(filename, blocksize=DEFAULT_BLOCKSIZE):
    fo = open(filename, 'rb')
    reference = fo.read()
    fo.seek(0, os.SEEK_SET)
    rev_lines = list(reverse_iter_lines(fo, blocksize))
    assert os.linesep.encode('ascii').join(rev_lines[::-1]) == reference