Jad*_*Lee 3 python linux afp watchdog raspberry-pi
我希望linux机器(Raspberry pi)通过AFP监视共享文件夹(Apple文件协议,macbook是主机)。
我可以通过mount_afp挂载共享文件夹,并安装看门狗python库来监视共享文件夹。问题是看门狗只能监视来自Linux机器本身的修改。
如果监视文件夹已由主机(Apple Macbook)或其他PC修改,则linux机器无法找到更改。没有日志出来。
在主机(Apple Macbook)上测试了相同的看门狗python文件后,我可以获取其他计算机所做的修改日志。
主机可以获取文件或文件夹的所有修改。但是其他计算机(来宾计算机)无法监视主机或其他设备对文件的修改。
看门狗是否正常?还是帐户和权限有问题?
这是看门狗样本。
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class Watcher:
DIRECTORY_TO_WATCH = "/path/to/my/directory"
def __init__(self):
self.observer = Observer()
def run(self):
event_handler = Handler()
self.observer.schedule(event_handler, self.DIRECTORY_TO_WATCH, recursive=True)
self.observer.start()
try:
while True:
time.sleep(5)
except:
self.observer.stop()
print "Error"
self.observer.join()
class Handler(FileSystemEventHandler):
@staticmethod
def on_any_event(event):
if event.is_directory:
return None
elif event.event_type == 'created':
# Take any action here when a file is first created.
print "Received created event - %s." % event.src_path
elif event.event_type == 'modified':
# Taken any action here when a file is modified.
print "Received modified event - %s." % event.src_path
if __name__ == '__main__':
w = Watcher()
w.run()
Run Code Online (Sandbox Code Playgroud)
对于网络安装,通常的文件系统事件并不总是发出。在这种情况下,请Observer尝试使用PollingObserver- 而不是使用,即更改为:
self.observer = Observer()
Run Code Online (Sandbox Code Playgroud)
至
from watchdog.observers.polling import PollingObserver
...
self.observer = PollingObserver()
Run Code Online (Sandbox Code Playgroud)
PollingObserverVFS您还可以尝试一门课。
文档:https : //pythonhosted.org/watchdog/api.html#module-watchdog.observers.polling