mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Few fixes
This commit is contained in:
parent
b57c9e7b77
commit
ae22e55a10
1 changed files with 19 additions and 16 deletions
|
@ -218,13 +218,16 @@ def _get_services():
|
||||||
|
|
||||||
|
|
||||||
def _tail(file, n, offset=None):
|
def _tail(file, n, offset=None):
|
||||||
"""Reads a n lines from f with an offset of offset lines. The return
|
"""
|
||||||
|
Reads a n lines from f with an offset of offset lines. The return
|
||||||
value is a tuple in the form ``(lines, has_more)`` where `has_more` is
|
value is a tuple in the form ``(lines, has_more)`` where `has_more` is
|
||||||
an indicator that is `True` if there are more lines in the file.
|
an indicator that is `True` if there are more lines in the file.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
avg_line_length = 74
|
avg_line_length = 74
|
||||||
to_read = n + (offset or 0)
|
to_read = n + (offset or 0)
|
||||||
|
|
||||||
|
try:
|
||||||
with open(file, 'r') as f:
|
with open(file, 'r') as f:
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
|
@ -237,6 +240,6 @@ def _tail(file, n, offset=None):
|
||||||
lines = f.read().splitlines()
|
lines = f.read().splitlines()
|
||||||
if len(lines) >= to_read or pos == 0:
|
if len(lines) >= to_read or pos == 0:
|
||||||
return lines[-to_read:offset and -offset or None]
|
return lines[-to_read:offset and -offset or None]
|
||||||
#return lines[-to_read:offset and -offset or None], \
|
|
||||||
# len(lines) > to_read or pos > 0
|
|
||||||
avg_line_length *= 1.3
|
avg_line_length *= 1.3
|
||||||
|
|
||||||
|
except IOError: return []
|
||||||
|
|
Loading…
Reference in a new issue