diff --git a/.hgignore b/.hgignore index b3805d2d5..8b0fcabbc 100644 --- a/.hgignore +++ b/.hgignore @@ -46,6 +46,8 @@ po/remove-potcdate\.sin syntax: glob Makefile src/virt-manager +src/virt-manager-tui +src/virt-manager-tui.py src/virt-manager-launch src/virt-manager.desktop src/virt-manager.py diff --git a/configure.ac b/configure.ac index 8b0bc9c6a..205539004 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,7 @@ AC_OUTPUT(Makefile po/Makefile.in src/Makefile src/virtManager/Makefile + src/virtManagerTui/Makefile man/Makefile tests/Makefile virt-manager.spec) diff --git a/src/Makefile.am b/src/Makefile.am index 0818500d9..96b8f03e2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,12 +1,12 @@ -SUBDIRS = virtManager +SUBDIRS = virtManager virtManagerTui -bin_SCRIPTS_IN = virt-manager.in -bin_SCRIPTS = virt-manager +bin_SCRIPTS_IN = virt-manager.in virt-manager-tui.in +bin_SCRIPTS = virt-manager virt-manager-tui pythondir = $(pkgdatadir) -python_DATA_IN = $(PACKAGE).py.in -python_DATA = $(PACKAGE).py +python_DATA_IN = $(PACKAGE).py.in $(PACKAGE)-tui.py.in +python_DATA = $(PACKAGE).py $(PACKAGE)-tui.py libexec_DATA_IN = $(PACKAGE)-launch.in libexec_SCRIPTS = $(PACKAGE)-launch @@ -54,6 +54,9 @@ EXTRA_DIST = $(bin_SCRIPTS_IN) $(desktop_DATA_IN) $(dbus_DATA_IN) $(python_DATA_ $(PACKAGE): $(srcdir)/$(PACKAGE).in sed -e "s,::PACKAGE::,$(PACKAGE)," -e "s,::PYTHONDIR::,$(pkgdatadir)," < $< > $@ +$(PACKAGE)-tui: $(srcdir)/$(PACKAGE)-tui.in + sed -e "s,::PACKAGE::,$(PACKAGE)-tui," -e "s,::PYTHONDIR::,$(pkgdatadir)," < $< > $@ + $(PACKAGE)-launch: $(srcdir)/$(PACKAGE)-launch.in sed -e "s,::PACKAGE::,$(PACKAGE)," -e "s,::PYTHONDIR::,$(pkgdatadir)," < $< > $@ diff --git a/src/virt-manager-tui.in b/src/virt-manager-tui.in new file mode 100644 index 000000000..192cc2236 --- /dev/null +++ b/src/virt-manager-tui.in @@ -0,0 +1,3 @@ +#!/bin/sh + +exec python "::PYTHONDIR::/::PACKAGE::.py" "$@" diff --git a/src/virt-manager-tui.py.in b/src/virt-manager-tui.py.in new file mode 100644 index 000000000..9e1a283ee --- /dev/null +++ b/src/virt-manager-tui.py.in @@ -0,0 +1,147 @@ +# virt-manager-tui.py - Copyright (C) 2010 Red Hat, Inc. +# Written by Darryl L. Pierce, . +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA. +# + +from newt_syrup.dialogscreen import DialogScreen +from optparse import OptionParser, OptionValueError + +import gettext +import locale +import logging +import os +import sys +import traceback + +# These are substituted into code based on --prefix given to configure +appname = "::PACKAGE::" +appversion = "::VERSION::" +gettext_app = "virt-manager" +gettext_dir = "::GETTEXTDIR::" +virtinst_str = "::VIRTINST_VERSION::" +virtinst_version = tuple([ int(num) for num in virtinst_str.split('.')]) + +gconf_dir = "/apps/" + appname +asset_dir = "::ASSETDIR::" +glade_dir = asset_dir +icon_dir = asset_dir + "/pixmaps" +pylib_dir = "::PYLIBDIR::" +pyarchlib_dir = "::PYARCHLIBDIR::" +data_dir = "::DATADIR::" + +def setup_i18n(): + locale.setlocale(locale.LC_ALL, '') + gettext.install(gettext_app, gettext_dir) + gettext.bindtextdomain(gettext_app, gettext_dir) + +def setup_pypath(): + global glade_dir, icon_dir, data_dir + # Hacks for find assets in local dir for dev purposes + if os.path.exists(os.getcwd() + "/src/vmm-about.glade"): + glade_dir = os.getcwd() + "/src" + if os.path.exists(os.getcwd() + "/pixmaps/state_running.png"): + icon_dir = os.getcwd() + "/pixmaps" + if os.path.exists(os.getcwd() + "../gnome/help/virt-manager/C/virt-manager.xml"): + data_dir = os.getcwd() + "../" + + # First 2 hacks are to point python to local dir for source files in dev, + # the third is the main path if you have normal install + if os.path.exists(os.getcwd() + "/src/virt-manager.py"): + pass + elif os.path.exists(os.getcwd() + "/build/src/virt-manager.py"): + sys.path.insert(0, os.getcwd() + "/src") + else: + sys.path.insert(0, pylib_dir) + sys.path.insert(0, pyarchlib_dir) + +def parse_commandline(): + optParser = OptionParser(version=appversion) + optParser.add_option("--profile", dest="profile", help="Generate runtime performance profile stats", metavar="FILE") + optParser.set_defaults(uuid=None) + optParser.add_option("-c", "--connect", dest="uri", + help="Connect to hypervisor at URI", metavar="URI") + optParser.add_option("--debug", action="store_true", dest="debug", + help="Print debug output to stdout (implies --no-fork)", + default=False) + optParser.add_option("--no-dbus", action="store_true", dest="nodbus", + help="Disable DBus service for controlling UI") + optParser.add_option("--no-fork", action="store_true", dest="nofork", + help="Don't fork into background on startup") + optParser.add_option("--no-conn-autostart", action="store_true", + dest="no_conn_auto", + help="Do not autostart connections") + optParser.add_option("--show-domain-creator", action="callback", + callback=opt_show_cb, dest="show", help="Create a new virtual machine") + optParser.add_option("--show-domain-editor", type="string", metavar="UUID", + action="callback", callback=opt_show_cb, help="Edit a domain configuration") + optParser.add_option("--show-domain-performance", type="string", metavar="UUID", + action="callback", callback=opt_show_cb, help="Show a domain performance") + optParser.add_option("--show-domain-console", type="string", metavar="UUID", + action="callback", callback=opt_show_cb, help="Show a domain console") + optParser.add_option("--show-host-summary", action="callback", + callback=opt_show_cb, help="Show a host summary") + + return optParser.parse_args() + +def opt_show_cb(option, opt_str, value, parser): + if option.metavar=="UUID": + setattr(parser.values, "uuid", value) + s = str(option) + show = s[s.rindex('-')+1:] + setattr(parser.values, "show", show) + +def _show_startup_error(message, details): + errordlg = DialogScreen("Error Starting Virtual Machine Manager", message) + errordlg.show() + +def main(): + setup_i18n() + setup_pypath() + + (options, ignore) = parse_commandline() + + # Make sure we have a sufficiently new virtinst version, since we are + # very closely tied to the lib + msg = ("virt-manager requires the python-virtinst library version " + + virtinst_str + " or greater. This can be downloaded at:" + "\n\nhttp://virt-manager.org/download.html") + try: + import virtinst + ignore = virtinst.__version__ + ignore = virtinst.__version_info__ + except Exception, e: + logging.exception("Error import virtinst") + raise RuntimeError(str(e) + "\n\n" + msg) + + if virtinst.__version_info__ < virtinst_version: + raise RuntimeError("virtinst version %s is too old." % + (virtinst.__version__) + + "\n\n" + msg) + + # start the app + from virtManagerTui.mainmenu import MainMenu + MainMenu() + +if __name__ == "__main__": + try: + main() + except SystemExit: + raise + except Exception, error: + logging.exception(error) + _show_startup_error(str(error), "".join(traceback.format_exc())) + diff --git a/src/virtManagerTui/Makefile.am b/src/virtManagerTui/Makefile.am new file mode 100644 index 000000000..4c4788e7d --- /dev/null +++ b/src/virtManagerTui/Makefile.am @@ -0,0 +1,16 @@ + +pythondir = $(pkgdatadir)/virtManagerTui +python_DATA = $(wildcard $(srcdir)/*.py) + +EXTRA_DIST = $(python_DATA) + +SYNTAX_CHECK_TSTAMPS = $(python_DATA:$(srcdir)/%.py=.tstamp.%.py) + + +check-local: $(SYNTAX_CHECK_TSTAMPS) + +clean-local: + rm -f $(SYNTAX_CHECK_TSTAMPS) + +.tstamp.%.py: %.py + touch $@