1 # libguestfs Python bindings
2 # Copyright (C) 2011 Red Hat Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 def log_callback (ev,eh,buf,array):
24 if ev == guestfs.EVENT_APPLIANCE:
28 print ("python event logged: event=0x%x eh=%d buf='%s' array=%s" %
33 def close_callback (ev, eh, buf, array):
36 log_callback (ev, eh, buf, array)
38 # Register an event callback for all log messages.
39 events = guestfs.EVENT_APPLIANCE | guestfs.EVENT_LIBRARY | guestfs.EVENT_TRACE
40 g.set_event_callback (log_callback, events)
42 # Register a callback for the close event.
43 g.set_event_callback (close_callback, guestfs.EVENT_CLOSE)
45 # Now make sure we see some messages.
50 g.add_drive_ro ("/dev/null")
53 # Close the handle. The close callback should be invoked.
54 if close_invoked != 0:
55 raise "Error: close_invoked should be 0"
57 if close_invoked != 1:
58 raise "Error: close_invoked should be 1"