3
# Checking DNotify registration/dregistration when monitoring a
4
# file as a file, then remove the file, then recreate it as a file
5
# in addition the directory is being watched, as a rsult internally
6
# the dnotify monitoring sequence is different since we keep
16
db_expect = [ 51, # directory watch
17
53, # file watch count incremented
18
53, # file disapear count decremented
20
53, # removal of watch on file
21
52 # removal of watch on directory
24
expect_f = [gamin.GAMExists, gamin.GAMEndExist, gamin.GAMDeleted,
27
expect_d = [gamin.GAMExists, # directory exists
28
gamin.GAMExists, # file a exists
29
gamin.GAMEndExist,# end listing
30
gamin.GAMDeleted, # file a removed
31
gamin.GAMCreated # file a created
34
def debug(path, type, data):
35
global dbg, db_expect, ok
37
# print "Got debug %s, %s, %s" % (path, type, data)
38
if path[-8:] != "temp_dir":
39
print "Error got debug path unexpected %s" % (path)
41
if db_expect[dbg] != type:
42
print "Error got debug event %d expected %d" % (type, db_expect[dbg])
46
def callback_file(path, event):
47
global top_f, expect_f, ok
48
# print "Got callback: %s, %s" % (path, event)
49
if event == gamin.GAMAcknowledge:
51
if expect_f[top_f] != event:
52
print "Error got file event %d expected %d" % (expect_f[top_f], event)
56
def callback_dir(path, event):
57
global top_d, expect_d, ok
58
# print "Got callback: %s, %s" % (path, event)
59
if event == gamin.GAMAcknowledge:
61
if expect_d[top_d] != event:
62
print "Error got dir event %d expected %d" % (expect_d[top_d], event)
66
shutil.rmtree ("temp_dir", True)
68
open("temp_dir/a", "w").close()
70
mon = gamin.WatchMonitor()
71
mon._debug_object("notify", debug, 0)
72
mon.watch_directory("temp_dir", callback_dir)
73
mon.watch_file("temp_dir/a", callback_file)
76
os.unlink("temp_dir/a")
79
open("temp_dir/a", "w").close()
82
mon.stop_watch("temp_dir/a")
83
mon.stop_watch("temp_dir")
88
shutil.rmtree ("temp_dir", True)
91
print "Error: file monitor got %d events insteads of 4" % (top_f)
93
print "Error: dir monitor got %d events insteads of 4" % (top_d)
94
elif dbg != 6 and gamin.has_debug_api == 1:
95
print "Error: debug got %d events insteads of 6" % (dbg)