Last active 1728400902

une lib pour le suivie de l'evolution d'un fichier

libtail.py Raw
1#!/usr/bin/env python3
2
3from time import sleep
4
5def tail (filename, printed_lines_count=0, polling_interval_duration=0.01):
6 line_count = sum(1 for line in open(FILENAME))
7 f = open(FILENAME,'r')
8 cpt = 0
9 while cpt < line_count - printed_lines_count :
10 cpt += 1
11 next(f)
12
13 try:
14 while True:
15 try:
16 line_read = next(f)
17 print(filename,":",line_read[:-1])
18 except:
19 sleep(polling_interval_duration)
20 except:
21 f.close()
22
tail.py Raw
1#!/usr/bin/env python3
2
3from libtail import tail
4from sys import argv
5
6if len(argv) != 2:
7 print("""utilisation:
8%s FICHIER"""%argv[0])
9 exit(1)
10tail(argv[1])
11