Update file_read tool and 9p permissions
This commit is contained in:
parent
e4b7d1de9c
commit
e2e8243c62
|
|
@ -61,6 +61,10 @@ with open(file_path, 'rb') as f:
|
|||
print("(binary file)")
|
||||
sys.exit(0)
|
||||
|
||||
# Count total lines
|
||||
with open(file_path, 'r', errors='replace') as f:
|
||||
total_lines = sum(1 for _ in f)
|
||||
|
||||
start = max(1, start)
|
||||
if head:
|
||||
end = start + head - 1
|
||||
|
|
@ -76,10 +80,10 @@ with open(file_path, 'r', errors='replace') as f:
|
|||
|
||||
if not segment_lines:
|
||||
if start == 1:
|
||||
print("STATUS=ok EMPTY=true")
|
||||
print(f"STATUS=ok LINES=0 TOTAL_LINES={total_lines} TRUNCATED=false EMPTY=true")
|
||||
print("(empty file)")
|
||||
else:
|
||||
print("STATUS=ok EMPTY=true")
|
||||
print(f"STATUS=ok LINES=0 TOTAL_LINES={total_lines} TRUNCATED=false EMPTY=true")
|
||||
print("(no lines in range)")
|
||||
sys.exit(0)
|
||||
|
||||
|
|
@ -91,5 +95,7 @@ for i, line in enumerate(segment_lines):
|
|||
text = text[:MAX_LINE_LEN] + '...'
|
||||
out.append(f"{lineno:>6}\t{text}")
|
||||
|
||||
print(f"STATUS=ok LINES={len(out)}")
|
||||
last_line_shown = start + len(out) - 1
|
||||
truncated = last_line_shown < total_lines
|
||||
print(f"STATUS=ok LINES={len(out)} TOTAL_LINES={total_lines} TRUNCATED={str(truncated).lower()}")
|
||||
print('\n'.join(out))
|
||||
|
|
|
|||
Loading…
Reference in New Issue