Compare commits
No commits in common. "master" and "v3.08" have entirely different histories.
36
kitsune
36
kitsune
|
@ -54,18 +54,12 @@ def watch(args):
|
|||
if st.st_mtime_ns > last_ts:
|
||||
last_ts = st.st_mtime_ns
|
||||
for de in os.scandir(d):
|
||||
try:
|
||||
if de.is_file():
|
||||
if args.match_filename is None or fnmatch.fnmatch(de.name, args.match_filename):
|
||||
if de.path not in watched_files:
|
||||
watched_files[de.path] = WatchedFile(de.path, seek_to_end)
|
||||
if len(de.path) > filename_length:
|
||||
filename_length = len(de.path)
|
||||
except (PermissionError, OSError):
|
||||
# ignore,
|
||||
# or maybe remove from watched_files?
|
||||
# or just mark as unavailable?
|
||||
pass
|
||||
if de.is_file():
|
||||
if args.match_filename is None or fnmatch.fnmatch(de.name, args.match_filename):
|
||||
if de.path not in watched_files:
|
||||
watched_files[de.path] = WatchedFile(de.path, seek_to_end)
|
||||
if len(de.path) > filename_length:
|
||||
filename_length = len(de.path)
|
||||
|
||||
# has any of the files changed
|
||||
for f in watched_files.values():
|
||||
|
@ -77,7 +71,7 @@ def watch(args):
|
|||
if stf.st_ino != st.st_ino:
|
||||
f.reopen()
|
||||
st = os.stat(f.fileno)
|
||||
except (FileNotFoundError, PermissionError):
|
||||
except FileNotFoundError:
|
||||
# ignore,
|
||||
# or maybe remove from watched_files?
|
||||
# or just mark as deleted?
|
||||
|
@ -94,19 +88,13 @@ def watch(args):
|
|||
if lines[-1] == "":
|
||||
lines.pop()
|
||||
for ln in lines:
|
||||
s = ""
|
||||
if args.print_filename:
|
||||
s += f"{f.path:{filename_length}} "
|
||||
if args.print_timestamp:
|
||||
s += format_ts(f.last_ts) + " "
|
||||
s += dead + " " + ln
|
||||
print(s)
|
||||
print(f"{f.path:{filename_length}}", format_ts(f.last_ts), dead, ln)
|
||||
else:
|
||||
try:
|
||||
stf = os.stat(f.path)
|
||||
if stf.st_ctime_ns != f.st_ctime_ns:
|
||||
f.reopen()
|
||||
except (FileNotFoundError, PermissionError):
|
||||
except FileNotFoundError:
|
||||
# ignore,
|
||||
# or maybe remove from watched_files?
|
||||
# or just mark as deleted?
|
||||
|
@ -121,12 +109,6 @@ if __name__ == "__main__":
|
|||
ap.add_argument("--match-filename",
|
||||
help="follow only matching files in directories",
|
||||
metavar="GLOB-PATTERN")
|
||||
ap.add_argument("--no-filename", "--no-print-filename", action="store_false",
|
||||
dest="print_filename",
|
||||
help="don't print filename in each line")
|
||||
ap.add_argument("--no-timestamp", "--no-print-timestamp", action="store_false",
|
||||
dest="print_timestamp",
|
||||
help="don't print timestamp in each line")
|
||||
ap.add_argument("files", nargs="*", default=["."],
|
||||
metavar="file")
|
||||
args = ap.parse_args()
|
||||
|
|
Loading…
Reference in New Issue