有什么方法可以显示文件更改(例如使用pyinotify)? [英] Any ways to show file changes (with pyinotify for example)?

查看:55
本文介绍了有什么方法可以显示文件更改(例如使用pyinotify)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以打印监视文件的修改?让我们举个例子:我正在监视file.txt,Pyinotify可以告诉我它已被修改,但是它似乎无法输出发生了什么更改?我错了吗 ?如何查看正在监视的文件有哪些更改?

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 ? 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.

推荐答案

inotify 机制不会在事件中嵌入增量,因为它应该在保存文件之前对其进行计算,并且由于通常不需要此信息,因此可能会影响性能.

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.

您可以使用类似的方法:

You could use an approach like:

  • file.txt 中读取数据,并将其存储在变量(或需要持久性的其他文件)中.

  • Read the data from file.txt and store it in a variable (or another file if persistence is needed).

使用 pyinotify 收听更改事件或 watchdog .

事件触发时,使用 difflib 检查您先前存储的快照中的增量和当前文件数据.

When the event is fired use difflib to check the deltas from the previous snapshot that you stored and the current file data.

这篇关于有什么方法可以显示文件更改(例如使用pyinotify)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆