简体   繁体   English

有什么方法可以显示文件更改(例如使用pyinotify)?

[英]Any ways to show file changes (with pyinotify for example)?

Is there any way to print a watched file modification ? 有什么方法可以打印监视文件的修改? let's take an example: I'm monitoring file.txt, Pyinotify can tell me that it has been modified, but It can't seem to be able to output what changes occured ? 让我们举个例子:我正在监视file.txt,Pyinotify可以告诉我它已经被修改,但是它似乎无法输出发生了什么变化? Am I wrong ? 我错了吗 ? How can I see what changes has been made to a file that I'm monitoring ? 如何查看正在监视的文件有哪些更改?

Big thanks in advance, sorry for my bad english. 在此先感谢您,我的英语不好。

The inotify mechanism does not embed the deltas in the event, because it should compute it before saving the files and this could affect performance since this information is not usually needed. inotify机制不会在事件中嵌入增量,因为它应该在保存文件之前对其进行计算,并且由于通常不需要此信息,因此这可能会影响性能。

You could use an approach like: 您可以使用类似的方法:

  • Read the data from file.txt and store it in a variable (or another file if persistence is needed). file.txt读取数据,并将其存储在变量中(如果需要持久性,则存储在另一个文件中)。

  • Listen for change events using pyinotify or watchdog . 使用pyinotifywatchdog监听更改事件。

  • When the event is fired use difflib to check the deltas from the previous snapshot that you stored and the current file data. 触发事件后,请使用difflib来检查您存储的上一个快照和当前文件数据中的增量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM