2 # Most of this is copied from Twisted 11.0. The reason for this hack is that
3 # twisted.internet.inotify can't be imported when the platform does not support inotify.
6 # from /usr/src/linux/include/linux/inotify.h
8 IN_ACCESS = 0x00000001L # File was accessed
9 IN_MODIFY = 0x00000002L # File was modified
10 IN_ATTRIB = 0x00000004L # Metadata changed
11 IN_CLOSE_WRITE = 0x00000008L # Writeable file was closed
12 IN_CLOSE_NOWRITE = 0x00000010L # Unwriteable file closed
13 IN_OPEN = 0x00000020L # File was opened
14 IN_MOVED_FROM = 0x00000040L # File was moved from X
15 IN_MOVED_TO = 0x00000080L # File was moved to Y
16 IN_CREATE = 0x00000100L # Subfile was created
17 IN_DELETE = 0x00000200L # Subfile was delete
18 IN_DELETE_SELF = 0x00000400L # Self was deleted
19 IN_MOVE_SELF = 0x00000800L # Self was moved
20 IN_UNMOUNT = 0x00002000L # Backing fs was unmounted
21 IN_Q_OVERFLOW = 0x00004000L # Event queued overflowed
22 IN_IGNORED = 0x00008000L # File was ignored
24 IN_ONLYDIR = 0x01000000 # only watch the path if it is a directory
25 IN_DONT_FOLLOW = 0x02000000 # don't follow a sym link
26 IN_MASK_ADD = 0x20000000 # add to the mask of an already existing watch
27 IN_ISDIR = 0x40000000 # event occurred against dir
28 IN_ONESHOT = 0x80000000 # only send event once
30 IN_CLOSE = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE # closes
31 IN_MOVED = IN_MOVED_FROM | IN_MOVED_TO # moves
32 IN_CHANGED = IN_MODIFY | IN_ATTRIB # changes
34 IN_WATCH_MASK = (IN_MODIFY | IN_ATTRIB |
35 IN_CREATE | IN_DELETE |
36 IN_DELETE_SELF | IN_MOVE_SELF |
37 IN_UNMOUNT | IN_MOVED_FROM | IN_MOVED_TO)
41 (IN_ACCESS, 'access'),
42 (IN_MODIFY, 'modify'),
43 (IN_ATTRIB, 'attrib'),
44 (IN_CLOSE_WRITE, 'close_write'),
45 (IN_CLOSE_NOWRITE, 'close_nowrite'),
47 (IN_MOVED_FROM, 'moved_from'),
48 (IN_MOVED_TO, 'moved_to'),
49 (IN_CREATE, 'create'),
50 (IN_DELETE, 'delete'),
51 (IN_DELETE_SELF, 'delete_self'),
52 (IN_MOVE_SELF, 'move_self'),
53 (IN_UNMOUNT, 'unmount'),
54 (IN_Q_OVERFLOW, 'queue_overflow'),
55 (IN_IGNORED, 'ignored'),
56 (IN_ONLYDIR, 'only_dir'),
57 (IN_DONT_FOLLOW, 'dont_follow'),
58 (IN_MASK_ADD, 'mask_add'),
60 (IN_ONESHOT, 'one_shot')
65 def humanReadableMask(mask):
67 Auxiliary function that converts an hexadecimal mask into a series
68 of human readable flags.
71 for k, v in _FLAG_TO_HUMAN:
77 # This class is not copied from Twisted; it acts as a mock.
78 class INotify(object):
79 def startReading(self):
82 def stopReading(self):
85 def watch(self, filepath, mask=IN_WATCH_MASK, autoAdd=False, callbacks=None, recursive=False):
86 self.callbacks = callbacks
88 def event(self, filepath, mask):
89 for cb in self.callbacks:
90 cb(None, filepath, mask)
93 __all__ = ["INotify", "humanReadableMask", "IN_WATCH_MASK", "IN_ACCESS",
94 "IN_MODIFY", "IN_ATTRIB", "IN_CLOSE_NOWRITE", "IN_CLOSE_WRITE",
95 "IN_OPEN", "IN_MOVED_FROM", "IN_MOVED_TO", "IN_CREATE",
96 "IN_DELETE", "IN_DELETE_SELF", "IN_MOVE_SELF", "IN_UNMOUNT",
97 "IN_Q_OVERFLOW", "IN_IGNORED", "IN_ONLYDIR", "IN_DONT_FOLLOW",
98 "IN_MASK_ADD", "IN_ISDIR", "IN_ONESHOT", "IN_CLOSE",
99 "IN_MOVED", "IN_CHANGED"]