-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatcher.py
More file actions
35 lines (32 loc) 路 1 KB
/
Copy pathwatcher.py
File metadata and controls
35 lines (32 loc) 路 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! /usr/bin/env python3
import sys
import logging
import os
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
print(" ")
print("Welcome to Watcher! 馃憖")
print(" ")
print("This program will log any changes in the")
print("current directory. If any changes occur,")
print("a log output will be printed here.")
print("To quit, press ctrl + c.")
print(" ")
print("To quit, press ctrl + c.")
print(" ")
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
path = sys.argv[1] if len(sys.argv) > 1 else '.'
event_handler = LoggingEventHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while observer.isAlive():
observer.join(1)
except KeyboardInterrupt:
observer.stop()
os.remove("watcher.py")
observer.join()