3
# Checking DNotify registration/dregistration when monitoring a
4
# directory as a directory and also watching the parent directory,
5
# then remove the children directory and check we are still watching
6
# the parent one correctly
18
db_expect = [ 51, 51, 52, 52 ]
19
expect = [gamin.GAMExists, gamin.GAMExists, gamin.GAMEndExist,
20
gamin.GAMDeleted, gamin.GAMCreated]
21
expect2 = [gamin.GAMExists, gamin.GAMEndExist, gamin.GAMDeleted ]
23
def debug(path, type, data):
24
global dbg, db_expect, ok
26
# print "Got debug %s, %s, %s" % (path, type, data)
27
if db_expect[dbg] != type:
28
print "Error got debug event %d expected %d" % (type, db_expect[dbg])
32
def callback(path, event, which):
33
global top, expect, ok
34
# print "Got callback: %s, %s" % (path, event)
35
if event == gamin.GAMAcknowledge:
37
if expect[top] != event:
38
print "Error got event %d expected %d" % (expect[top], event)
42
def callback2(path, event, which):
43
global top2, expect2, ok
44
# print "Got callback2: %s, %s" % (path, event)
45
if event == gamin.GAMAcknowledge:
47
if expect2[top2] != event:
48
print "Error got event %d expected %d" % (expect2[top2], event)
52
shutil.rmtree ("temp_dir", True)
54
os.mkdir ("temp_dir/a")
56
mon = gamin.WatchMonitor()
57
mon._debug_object("notify", debug, 0)
58
mon.watch_directory("temp_dir", callback, 0)
59
mon.watch_directory("temp_dir/a", callback2, 0)
62
shutil.rmtree("temp_dir/a")
65
open("temp_dir/b", "w").close()
68
mon.stop_watch("temp_dir/a")
69
mon.stop_watch("temp_dir")
74
shutil.rmtree ("temp_dir", True)
77
print "Error: monitor got %d events insteads of 5" % (top)
79
print "Error: monitor got %d events insteads of 3" % (top2)
80
elif dbg != 4 and gamin.has_debug_api == 1:
81
print "Error: debug got %d events insteads of 4" % (dbg)