Skip to content

Commit

Permalink
Some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sofagris committed Jun 7, 2023
1 parent 54b9183 commit b5ceec4
Show file tree
Hide file tree
Showing 7 changed files with 2,345 additions and 17 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[flake8]
exclude =
Integrations/VMware/UAG
Integrations/Dell/VxRail

ignore =
# E203 whitespace before ':' (per Black, this is actually correct in some cases)
Expand Down
31 changes: 31 additions & 0 deletions cli/logview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import time
import os

def tail(filename, n=10):
'''
Print the last `n` lines from the file with name `filename`
'''
with open(filename, 'r') as file:
lines = file.readlines()
last_lines = lines[-n:]
for line in last_lines:
print(line, end='')

def tail_follow(filename):
'''
Continuously monitor the file with name `filename` and
print new lines as they are written to the file.
'''
with open(filename, 'r') as file:
# Move to the end of the file
file.seek(0, os.SEEK_END)
while True:
line = file.readline()
if not line:
time.sleep(0.1) # Sleep briefly
continue
print(line, end='')

# Example usage:
# tail('my_file.txt')
tail_follow('npyscreen.log')
238 changes: 223 additions & 15 deletions cli/menu.py

Large diffs are not rendered by default.

Loading

0 comments on commit b5ceec4

Please sign in to comment.