Skip to content

Commit bb8d2d8

Browse files
committed
Added test script.
1 parent 8eebbc2 commit bb8d2d8

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

dev/test.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python2.7
2+
3+
import os.path
4+
import sys
5+
current_path = os.path.dirname(__file__)
6+
dev_path = os.path.abspath(os.path.join(current_path, '..'))
7+
sys.path.insert(0, dev_path)
8+
9+
import logging
10+
11+
import inotify.adapters
12+
13+
_DEFAULT_LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
14+
15+
_LOGGER = logging.getLogger(__name__)
16+
17+
def _configure_logging():
18+
_LOGGER.setLevel(logging.DEBUG)
19+
20+
ch = logging.StreamHandler()
21+
22+
formatter = logging.Formatter(_DEFAULT_LOG_FORMAT)
23+
ch.setFormatter(formatter)
24+
25+
_LOGGER.addHandler(ch)
26+
27+
def _main():
28+
# paths = [
29+
# '/tmp',
30+
# ]
31+
#
32+
# i = Inotify(paths=paths)
33+
i = inotify.adapters.Inotify()
34+
35+
i.add_watch('/tmp')
36+
37+
try:
38+
for event in i.event_gen():
39+
if event is not None:
40+
(header, type_names, filename) = event
41+
_LOGGER.info("WD=(%d) MASK=(%d) COOKIE=(%d) LEN=(%d) MASK->NAMES=%s "
42+
"FILENAME=[%s]",
43+
header.wd, header.mask, header.cookie, header.len, type_names,
44+
filename)
45+
finally:
46+
i.remove_watch('/tmp')
47+
48+
if __name__ == '__main__':
49+
_configure_logging()
50+
_main()

0 commit comments

Comments
 (0)