def main(): try: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) except getopt.GetoptError as err: # print help information and exit: print(str(err)) # will print something like "option -a not recognized" usage() sys.exit(2) for o, a in opts: if o in ("-h", "--help"): usage() sys.exit() if len(sys.argv) > 1: uri = sys.argv[1] else: uri = "qemu:///system" print("Using uri:" + uri) LibvirtGLib.init() LibvirtGLib.event_register() vc = libvirt.open(uri) #Add 2 callbacks to prove this works with more than just one vc.domainEventRegister(myDomainEventCallback1, None) vc.domainEventRegister(myDomainEventCallback2, None) Gtk.main()
def main(): (options, leftovers) = parse_commandline() cli.setupLogging("virt-manager", options.debug, False, False) log.debug("virt-manager version: %s", BuildConfig.version) log.debug("virtManager import: %s", os.path.dirname(__file__)) if BuildConfig.running_from_srcdir: _setup_gsettings_path(BuildConfig.gsettings_dir) if options.trace_libvirt: log.debug("Libvirt tracing requested") from .lib import module_trace import libvirt module_trace.wrap_module( libvirt, mainloop=(options.trace_libvirt == "mainloop"), regex=None) CLITestOptions = CLITestOptionsClass(options.test_options) # With F27 gnome+wayland we need to set these before GTK import os.environ["GSETTINGS_SCHEMA_DIR"] = BuildConfig.gsettings_dir # Now we've got basic environment up & running we can fork do_drop_stdio = False if not options.no_fork and not options.debug: drop_tty() do_drop_stdio = True # Ignore SIGHUP, otherwise a serial console closing drops the whole app signal.signal(signal.SIGHUP, signal.SIG_IGN) leftovers = _import_gtk(leftovers) Gtk = globals()["Gtk"] # Do this after the Gtk import so the user has a chance of seeing any error if do_drop_stdio: drop_stdio() if leftovers: raise RuntimeError("Unhandled command line options '%s'" % leftovers) log.debug("PyGObject version: %d.%d.%d", gi.version_info[0], gi.version_info[1], gi.version_info[2]) log.debug("GTK version: %d.%d.%d", Gtk.get_major_version(), Gtk.get_minor_version(), Gtk.get_micro_version()) # Prime the vmmConfig cache from . import config config.vmmConfig.get_instance(BuildConfig, CLITestOptions) # Add our icon dir to icon theme icon_theme = Gtk.IconTheme.get_default() icon_theme.prepend_search_path(BuildConfig.icon_dir) from .engine import vmmEngine Gtk.Window.set_default_icon_name("virt-manager") show_window = None domain = None if options.show_domain_creator: show_window = vmmEngine.CLI_SHOW_DOMAIN_CREATOR elif options.show_host_summary: show_window = vmmEngine.CLI_SHOW_HOST_SUMMARY elif options.show_domain_editor: show_window = vmmEngine.CLI_SHOW_DOMAIN_EDITOR domain = options.show_domain_editor elif options.show_domain_performance: show_window = vmmEngine.CLI_SHOW_DOMAIN_PERFORMANCE domain = options.show_domain_performance elif options.show_domain_console: show_window = vmmEngine.CLI_SHOW_DOMAIN_CONSOLE domain = options.show_domain_console elif options.show_domain_delete: show_window = vmmEngine.CLI_SHOW_DOMAIN_DELETE domain = options.show_domain_delete if show_window and options.uri is None: # pragma: no cover raise RuntimeError("can't use --show-* options without --connect") skip_autostart = False if show_window: skip_autostart = True # Hook libvirt events into glib main loop LibvirtGLib.init(None) LibvirtGLib.event_register() engine = vmmEngine.get_instance() # Actually exit when we receive ctrl-c from gi.repository import GLib def _sigint_handler(user_data): ignore = user_data log.debug("Received KeyboardInterrupt. Exiting application.") engine.exit_app() GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, _sigint_handler, None) engine.start(options.uri, show_window, domain, skip_autostart)
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"] ) except getopt.GetoptError, err: # print help information and exit: print str(err) # will print something like "option -a not recognized" usage() sys.exit(2) for o, a in opts: if o in ("-h", "--help"): usage() sys.exit() if len(sys.argv) > 1: uri = sys.argv[1] else: uri = "qemu:///system" print "Using uri:" + uri LibvirtGLib.init(0, "") LibvirtGLib.event_register() vc = libvirt.open(uri) #Add 2 callbacks to prove this works with more than just one vc.domainEventRegister(myDomainEventCallback1,None) vc.domainEventRegister(myDomainEventCallback2,None) Gtk.main() if __name__ == "__main__": main()