-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.py
More file actions
51 lines (44 loc) · 1.55 KB
/
Copy pathmonitor.py
File metadata and controls
51 lines (44 loc) · 1.55 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import argparse
import json
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import logging
from db_utils import *
class MyHandler(FileSystemEventHandler):
def __init__(self) -> None:
super().__init__()
def on_created(self, event):
print(f"File created: {event.src_path}")
def on_deleted(self, event):
# print(f"[Monitor] deleted file: {event.src_path}")
if event.is_directory:
print(f"[Monitor] deleted directory: {event.src_path}")
delete_link_src(args.db_dir, args.link_dst, event.src_path)
else:
pass
# filename, ext = os.path.splitext(event.src_path)
# if ext in ['.mp4', '.mkv', '.avi', '.rmvb']:
# delete_link_src(args.db_dir, event.src_path, is_dir=event.is_directory)
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--db-dir',
required=True,
help='db dir')
parser.add_argument('-l', '--link_dst',
required=True,
help='The link dst, will monitor this dir')
parser.add_argument('-v',
'--verbose',
action='store_true',
help='Verbose mode, print debug')
args = parser.parse_args()
observer = Observer()
observer.schedule(MyHandler(), path=args.link_dst, recursive=True)
try:
observer.start()
observer.join()
except KeyboardInterrupt:
print('KeyboardInterrupt')
observer.stop()
observer.join()