libtail.py
· 467 B · Python
Raw
#!/usr/bin/env python3
from time import sleep
def tail (filename, printed_lines_count=0, polling_interval_duration=0.01):
line_count = sum(1 for line in open(FILENAME))
f = open(FILENAME,'r')
cpt = 0
while cpt < line_count - printed_lines_count :
cpt += 1
next(f)
try:
while True:
try:
line_read = next(f)
print(filename,":",line_read[:-1])
except:
sleep(polling_interval_duration)
except:
f.close()
| 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | from time import sleep |
| 4 | |
| 5 | def 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 |
| 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | from libtail import tail |
| 4 | from sys import argv |
| 5 | |
| 6 | if len(argv) != 2: |
| 7 | print("""utilisation: |
| 8 | %s FICHIER"""%argv[0]) |
| 9 | exit(1) |
| 10 | tail(argv[1]) |
| 11 |