使用看门狗的python来监控来自linux的afp共享文件夹
问题描述:
我希望linux机器(树莓派)通过AFP(苹果文件协议,macbook是主机)来监视共享文件夹。使用看门狗的python来监控来自linux的afp共享文件夹
我可以通过mount_afp挂载共享文件夹,并安装了watchdog python库来监视共享文件夹。问题是看门狗只能监视linux机器本身的修改。
如果监控文件夹已被主机(Apple macbook)或其他电脑修改过,那么linux机器无法找到更改。没有日志出来。
当我在主机(苹果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()
答
对于网络挂载,通常的文件系统事件并不总是发出。在这种情况下,而不是使用Observer
,请尝试使用PollingObserver
- 即,变:
self.observer = Observer()
到
from watchdog.observers import PollingObserver
...
self.observer = PollingObserver()
还有一类PollingObserverVFS
你可以用实验。
文档:https://pythonhosted.org/watchdog/api.html#module-watchdog.observers.polling
看门狗只能监视对本地文件系统的更改。操作系统和远程文件系统未通知有关更改。 –
@Klaus D嗨,有没有任何python库来监控法新社共享文件夹? –
第一个问题是如果主机通知客户端。如果没有,将不会有任何图书馆。 –