Dropbox 和 pyinotify
我刚买了一台 iPad,然后愚蠢地得到了 TexTouch 应用程序。愚蠢的是,由于Apple的规定,TexTouch无法编译Tex。它使用Dropbox将.tex文件同步到计算机。在远程计算机上,它被另一个程序捕获,该程序将 .tex 文件编译为 PDF 并将其发送回。但是(令人惊讶!)那个远程程序仅适用于 Windows 和 Mac。而且我在 Linux 上。所以我想,为什么不使用inotify呢?为了让事情变得更简单,我实际上使用了 pyinotify,这样我就不必处理大量的编译。但是,当 Dropbox 删除文件时,用 pyinotify 的话说,以下是发生的事件。 (显然,“first doc.tex”是我正在同步的文件的名称。)
event: <Event dir=False mask=0x20 maskname=IN_OPEN name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x1 maskname=IN_ACCESS name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x10 maskname=IN_CLOSE_NOWRITE name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event cookie=151401 dir=False mask=0x40 maskname=IN_MOVED_FROM name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event cookie=151402 dir=False mask=0x80 maskname=IN_MOVED_TO name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x4 maskname=IN_ATTRIB name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x20 maskname=IN_OPEN name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x1 maskname=IN_ACCESS name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x10 maskname=IN_CLOSE_NOWRITE name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x20 maskname=IN_OPEN name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x1 maskname=IN_ACCESS name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x10 maskname=IN_CLOSE_NOWRITE name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x20 maskname=IN_OPEN name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x1 maskname=IN_ACCESS name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x10 maskname=IN_CLOSE_NOWRITE name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x20 maskname=IN_OPEN name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x1 maskname=IN_ACCESS name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x10 maskname=IN_CLOSE_NOWRITE name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
我能用它来做什么?唯一看起来唯一的事件是 IN_MOVE_FROM 和 IN_MOVE_TO 事件。但监控这些看起来是个坏主意。有没有办法检测 Dropbox 发起的事件?我应该使用 inotify 或 pyinotify 以外的其他东西吗?
I just got an iPad and I foolishly got the TexTouch application. Foolishly, because due to Apple regulation, TexTouch can't compile Tex. It syncs the .tex file to a computer using Dropbox. On the distant computer, it gets caught by another program that compiles the .tex file to PDF and sends it back. But (surprise!) that distant program in Windows and Mac only. And I'm on Linux. So I thought, why not use inotify? To make things a bit simpler, I actually used pyinotify so I wouldn't have to deal with tons of compilation. BUT when Dropbox drops a file, here are, in pyinotify vernacular, the events that happen. (Obviously, "first doc.tex" is the name of the file I'm syncing.)
event: <Event dir=False mask=0x20 maskname=IN_OPEN name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x1 maskname=IN_ACCESS name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x10 maskname=IN_CLOSE_NOWRITE name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event cookie=151401 dir=False mask=0x40 maskname=IN_MOVED_FROM name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event cookie=151402 dir=False mask=0x80 maskname=IN_MOVED_TO name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x4 maskname=IN_ATTRIB name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x20 maskname=IN_OPEN name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x1 maskname=IN_ACCESS name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x10 maskname=IN_CLOSE_NOWRITE name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x20 maskname=IN_OPEN name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x1 maskname=IN_ACCESS name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x10 maskname=IN_CLOSE_NOWRITE name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x20 maskname=IN_OPEN name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x1 maskname=IN_ACCESS name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x10 maskname=IN_CLOSE_NOWRITE name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x20 maskname=IN_OPEN name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x1 maskname=IN_ACCESS name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
event: <Event dir=False mask=0x10 maskname=IN_CLOSE_NOWRITE name=first doc.tex path=/home/eje211/Dropbox/TexTouch pathname=/home/eje211/Dropbox/TexTouch/first doc.tex wd=1 >
What can I make of that? The only events that appear to be unique are the IN_MOVE_FROM and IN_MOVE_TO events. But it looks like a BAD idea to monitor those. Is there a way to detect an event that is initiated by Dropbox? Should I use something other than inotify or pyinotify?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,
IN_OPEN
(打开文件以供读取)、IN_ACCESS
(文件已访问)和IN_ATTRIB
(已修改文件属性)显然不是您所需要的。IN_CLOSE_NOWRITE
表示该文件已关闭以供读取(即无法进行任何更改),因此这也不是您所需要的。因此它必须是IN_MOVED_FROM
或IN_MOVED_TO
。您确定没有其他事件发生吗?
如果是,那么该文件可能正在其他地方创建,然后被移动到其最终位置
~/Dropbox
。Well,
IN_OPEN
(file opened for reading),IN_ACCESS
(file accessed) andIN_ATTRIB
(file attributes modified) are obviously not what you need.IN_CLOSE_NOWRITE
means that the file has been closed for reading (i.e. no changes could have been made), so that's also not what you need. So it'll have to be eitherIN_MOVED_FROM
orIN_MOVED_TO
.Are you sure there are no other events happening whatsoever?
If you are, then the file is probably being created somewhere else and then being moved to its final location at
~/Dropbox
.我有一个正在监视 IN_MOVED_TO 的脚本。每当 Dropbox 删除新文件时,就会触发该文件。您应该使用 IN_MOVED_TO。
I got a script working that watches for IN_MOVED_TO. Whenever Dropbox drops a new file, it is triggered. You should use IN_MOVED_TO.