mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
virtcli: Export config variables in a class object
Makes things easier to extend later
This commit is contained in:
parent
a0adcef306
commit
a773a66a3f
27
setup.py
27
setup.py
@ -15,7 +15,7 @@ from distutils.command.sdist import sdist
|
||||
from distutils.sysconfig import get_config_var
|
||||
sysprefix = get_config_var("prefix")
|
||||
|
||||
from virtcli import cliconfig
|
||||
from virtcli import CLIConfig
|
||||
|
||||
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
@ -149,7 +149,8 @@ class my_build(build):
|
||||
os.mkdir("build")
|
||||
|
||||
for app in cmds:
|
||||
sharepath = os.path.join(cliconfig.install_asset_dir, app)
|
||||
sharepath = os.path.join(CLIConfig.prefix,
|
||||
"share", "virt-manager", app)
|
||||
|
||||
wrapper = "#!/bin/sh\n\n"
|
||||
wrapper += "exec \"%s\" \"$@\"" % (sharepath)
|
||||
@ -170,7 +171,7 @@ class my_build(build):
|
||||
ret = os.system('pod2man '
|
||||
'--center "Virtual Machine Manager" '
|
||||
'--release %s --name %s '
|
||||
'< %s > %s' % (cliconfig.__version__,
|
||||
'< %s > %s' % (CLIConfig.version,
|
||||
appname.upper(),
|
||||
path, newpath))
|
||||
if ret != 0:
|
||||
@ -221,13 +222,13 @@ class my_install(install):
|
||||
"""
|
||||
def finalize_options(self):
|
||||
if self.prefix is None:
|
||||
if cliconfig.prefix != sysprefix:
|
||||
print "Using prefix from 'configure': %s" % cliconfig.prefix
|
||||
self.prefix = cliconfig.prefix
|
||||
elif self.prefix != cliconfig.prefix:
|
||||
if CLIConfig.prefix != sysprefix:
|
||||
print "Using prefix from 'configure': %s" % CLIConfig.prefix
|
||||
self.prefix = CLIConfig.prefix
|
||||
elif self.prefix != CLIConfig.prefix:
|
||||
print("Install prefix=%s doesn't match configure prefix=%s\n"
|
||||
"Pass matching --prefix to 'setup.py configure'" %
|
||||
(self.prefix, cliconfig.prefix))
|
||||
(self.prefix, CLIConfig.prefix))
|
||||
sys.exit(1)
|
||||
|
||||
install.finalize_options(self)
|
||||
@ -240,7 +241,7 @@ class my_sdist(sdist):
|
||||
f1 = open('virt-manager.spec.in', 'r')
|
||||
f2 = open('virt-manager.spec', 'w')
|
||||
for line in f1:
|
||||
f2.write(line.replace('@VERSION@', cliconfig.__version__))
|
||||
f2.write(line.replace('@VERSION@', CLIConfig.version))
|
||||
f1.close()
|
||||
f2.close()
|
||||
|
||||
@ -266,7 +267,7 @@ class my_rpm(Command):
|
||||
"""
|
||||
self.run_command('sdist')
|
||||
os.system('rpmbuild -ta --clean dist/virt-manager-%s.tar.gz' %
|
||||
cliconfig.__version__)
|
||||
CLIConfig.version)
|
||||
|
||||
|
||||
class configure(Command):
|
||||
@ -331,8 +332,8 @@ class configure(Command):
|
||||
if self.with_bhyve is not None:
|
||||
template += "with_bhyve = %s\n" % self.with_bhyve
|
||||
|
||||
file(cliconfig.cfgpath, "w").write(template)
|
||||
print "Generated %s" % cliconfig.cfgpath
|
||||
file(CLIConfig.cfgpath, "w").write(template)
|
||||
print "Generated %s" % CLIConfig.cfgpath
|
||||
|
||||
|
||||
class TestBaseCommand(Command):
|
||||
@ -547,7 +548,7 @@ class CheckPylint(Command):
|
||||
|
||||
setup(
|
||||
name="virt-manager",
|
||||
version=cliconfig.__version__,
|
||||
version=CLIConfig.version,
|
||||
author="Cole Robinson",
|
||||
author_email="virt-tools-list@redhat.com",
|
||||
url="http://virt-manager.org",
|
||||
|
@ -20,7 +20,7 @@ import os
|
||||
|
||||
import virtinst
|
||||
from virtinst import VirtualDisk
|
||||
from virtcli import cliconfig
|
||||
from virtcli import CLIConfig
|
||||
|
||||
from tests import utils
|
||||
|
||||
@ -297,7 +297,7 @@ class TestXMLMisc(unittest.TestCase):
|
||||
self._compare(g, "install-f11-norheldefaults", do_install)
|
||||
|
||||
try:
|
||||
cliconfig.stable_defaults = True
|
||||
CLIConfig.stable_defaults = True
|
||||
origemu = g.emulator
|
||||
g.emulator = "/usr/libexec/qemu-kvm"
|
||||
self.assertTrue(g.conn.stable_defaults())
|
||||
@ -307,7 +307,7 @@ class TestXMLMisc(unittest.TestCase):
|
||||
g.emulator = origemu
|
||||
setattr(g.conn, "_support_cache", {})
|
||||
finally:
|
||||
cliconfig.stable_defaults = False
|
||||
CLIConfig.stable_defaults = False
|
||||
|
||||
# Verify main guest wasn't polluted
|
||||
self._compare(g, "install-f11-norheldefaults", do_install)
|
||||
@ -323,7 +323,7 @@ class TestXMLMisc(unittest.TestCase):
|
||||
g.os_variant = "ubuntu13.10"
|
||||
|
||||
self._compare(g, "install-novmvga-rhel", True)
|
||||
cliconfig.stable_defaults = True
|
||||
CLIConfig.stable_defaults = True
|
||||
self._compare(g, "install-novmvga-rhel", True)
|
||||
finally:
|
||||
cliconfig.stable_defaults = False
|
||||
CLIConfig.stable_defaults = False
|
||||
|
10
virt-manager
10
virt-manager
@ -32,7 +32,7 @@ from gi.repository import LibvirtGLib
|
||||
|
||||
from virtinst import util as util
|
||||
from virtinst import cli as virtinstcli
|
||||
from virtcli import cliconfig
|
||||
from virtcli import CLIConfig
|
||||
|
||||
# This is massively heavy handed, but I can't figure out any way to shut
|
||||
# up the slew of gtk deprecation warnings that clog up our very useful
|
||||
@ -89,7 +89,7 @@ def parse_commandline():
|
||||
parser = argparse.ArgumentParser(usage="virt-manager [options]",
|
||||
epilog=epilog)
|
||||
parser.add_argument('--version', action='version',
|
||||
version=cliconfig.__version__)
|
||||
version=CLIConfig.version)
|
||||
parser.set_defaults(uuid=None)
|
||||
|
||||
# Trace every libvirt API call to debug output
|
||||
@ -150,7 +150,7 @@ def main():
|
||||
virtinstcli.setupLogging("virt-manager", options.debug, False, False)
|
||||
|
||||
import virtManager
|
||||
logging.debug("virt-manager version: %s", cliconfig.__version__)
|
||||
logging.debug("virt-manager version: %s", CLIConfig.version)
|
||||
logging.debug("virtManager import: %s", str(virtManager))
|
||||
|
||||
if options.tracelibvirt:
|
||||
@ -213,7 +213,7 @@ def main():
|
||||
Gtk.get_micro_version())
|
||||
|
||||
config = virtManager.config.vmmConfig(
|
||||
"virt-manager", cliconfig, options.testfirstrun)
|
||||
"virt-manager", CLIConfig, options.testfirstrun)
|
||||
|
||||
if not util.local_libvirt_version() >= 6000:
|
||||
# We need this version for threaded virConnect access
|
||||
@ -227,7 +227,7 @@ def main():
|
||||
|
||||
# Add our icon dir to icon theme
|
||||
icon_theme = Gtk.IconTheme.get_default()
|
||||
icon_theme.prepend_search_path(cliconfig.icon_dir)
|
||||
icon_theme.prepend_search_path(CLIConfig.icon_dir)
|
||||
|
||||
from virtManager.engine import vmmEngine
|
||||
|
||||
|
@ -140,11 +140,11 @@ class vmmConfig(object):
|
||||
DEFAULT_VIRT_IMAGE_DIR = "/var/lib/libvirt/images"
|
||||
DEFAULT_VIRT_SAVE_DIR = "/var/lib/libvirt"
|
||||
|
||||
def __init__(self, appname, cliconfig, test_first_run=False):
|
||||
def __init__(self, appname, CLIConfig, test_first_run=False):
|
||||
self.appname = appname
|
||||
self.appversion = cliconfig.__version__
|
||||
self.appversion = CLIConfig.version
|
||||
self.conf_dir = "/org/virt-manager/%s/" % self.appname
|
||||
self.ui_dir = os.path.join(cliconfig.asset_dir, "ui")
|
||||
self.ui_dir = CLIConfig.ui_dir
|
||||
self.test_first_run = bool(test_first_run)
|
||||
|
||||
self.conf = SettingsWrapper("org.virt-manager.virt-manager")
|
||||
@ -154,13 +154,13 @@ class vmmConfig(object):
|
||||
# the keyring
|
||||
self.keyring = None
|
||||
|
||||
self.default_qemu_user = cliconfig.default_qemu_user
|
||||
self.preferred_distros = cliconfig.preferred_distros
|
||||
self.hv_packages = cliconfig.hv_packages
|
||||
self.libvirt_packages = cliconfig.libvirt_packages
|
||||
self.askpass_package = cliconfig.askpass_package
|
||||
self.default_graphics_from_config = cliconfig.default_graphics
|
||||
self.with_bhyve = cliconfig.with_bhyve
|
||||
self.default_qemu_user = CLIConfig.default_qemu_user
|
||||
self.preferred_distros = CLIConfig.preferred_distros
|
||||
self.hv_packages = CLIConfig.hv_packages
|
||||
self.libvirt_packages = CLIConfig.libvirt_packages
|
||||
self.askpass_package = CLIConfig.askpass_package
|
||||
self.default_graphics_from_config = CLIConfig.default_graphics
|
||||
self.with_bhyve = CLIConfig.with_bhyve
|
||||
self.cli_usbredir = None
|
||||
|
||||
self.default_storage_format_from_config = "qcow2"
|
||||
|
@ -1 +1,3 @@
|
||||
# Copyright (C) 2013 Red Hat, Inc.
|
||||
# Copyright (C) 2013-2015 Red Hat, Inc.
|
||||
|
||||
from .cliconfig import CLIConfig
|
||||
|
@ -69,30 +69,44 @@ def _setup_gsettings_path(schemadir):
|
||||
raise RuntimeError("Failed to compile local gsettings schemas")
|
||||
|
||||
|
||||
##############
|
||||
# Public API #
|
||||
##############
|
||||
|
||||
__version__ = "1.1.0"
|
||||
|
||||
cfgpath = _cfgpath
|
||||
prefix = _get_param("prefix", "/usr")
|
||||
gettext_dir = os.path.join(prefix, "share", "locale")
|
||||
install_asset_dir = os.path.join(prefix, "share", "virt-manager")
|
||||
if _running_from_srcdir:
|
||||
asset_dir = _srcdir
|
||||
icon_dir = os.path.join(_srcdir, "data")
|
||||
_setup_gsettings_path(icon_dir)
|
||||
else:
|
||||
asset_dir = install_asset_dir
|
||||
icon_dir = os.path.join(asset_dir, "icons")
|
||||
|
||||
default_qemu_user = _get_param("default_qemu_user", "root")
|
||||
stable_defaults = bool(int(_get_param("stable_defaults", "0")))
|
||||
class _CLIConfig(object):
|
||||
def __init__(self):
|
||||
self.cfgpath = _cfgpath
|
||||
self.version = __version__
|
||||
|
||||
preferred_distros = _split_list(_get_param("preferred_distros", ""))
|
||||
hv_packages = _split_list(_get_param("hv_packages", ""))
|
||||
askpass_package = _split_list(_get_param("askpass_packages", ""))
|
||||
libvirt_packages = _split_list(_get_param("libvirt_packages", ""))
|
||||
default_graphics = _get_param("default_graphics", "spice")
|
||||
with_bhyve = bool(int(_get_param("with_bhyve", "0")))
|
||||
self.default_qemu_user = _get_param("default_qemu_user", "root")
|
||||
self.stable_defaults = bool(int(_get_param("stable_defaults", "0")))
|
||||
|
||||
self.preferred_distros = _split_list(
|
||||
_get_param("preferred_distros", ""))
|
||||
self.hv_packages = _split_list(_get_param("hv_packages", ""))
|
||||
self.askpass_package = _split_list(_get_param("askpass_packages", ""))
|
||||
self.libvirt_packages = _split_list(_get_param("libvirt_packages", ""))
|
||||
self.default_graphics = _get_param("default_graphics", "spice")
|
||||
self.with_bhyve = bool(int(_get_param("with_bhyve", "0")))
|
||||
|
||||
self.prefix = None
|
||||
self.gettext_dir = None
|
||||
self.ui_dir = None
|
||||
self.icon_dir = None
|
||||
self.set_paths_by_prefix(_get_param("prefix", "/usr"),
|
||||
check_source_dir=True)
|
||||
|
||||
def set_paths_by_prefix(self, prefix, check_source_dir=False):
|
||||
self.prefix = prefix
|
||||
self.gettext_dir = os.path.join(prefix, "share", "locale")
|
||||
|
||||
if _running_from_srcdir and check_source_dir:
|
||||
self.icon_dir = os.path.join(_srcdir, "data")
|
||||
self.ui_dir = os.path.join(_srcdir, "ui")
|
||||
_setup_gsettings_path(self.icon_dir)
|
||||
else:
|
||||
self.icon_dir = os.path.join(prefix, "share", "virt-manager",
|
||||
"icons")
|
||||
self.ui_dir = os.path.join(prefix, "share", "virt-manager", "ui")
|
||||
|
||||
|
||||
CLIConfig = _CLIConfig()
|
||||
|
@ -15,7 +15,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA.
|
||||
|
||||
from virtcli import cliconfig as _cliconfig
|
||||
from virtcli import CLIConfig as _CLIConfig
|
||||
|
||||
|
||||
def _setup_i18n():
|
||||
@ -28,11 +28,11 @@ def _setup_i18n():
|
||||
# Can happen if user passed a bogus LANG
|
||||
pass
|
||||
|
||||
gettext.install("virt-manager", _cliconfig.gettext_dir)
|
||||
gettext.bindtextdomain("virt-manager", _cliconfig.gettext_dir)
|
||||
gettext.install("virt-manager", _CLIConfig.gettext_dir)
|
||||
gettext.bindtextdomain("virt-manager", _CLIConfig.gettext_dir)
|
||||
|
||||
_setup_i18n()
|
||||
stable_defaults = _cliconfig.stable_defaults
|
||||
stable_defaults = _CLIConfig.stable_defaults
|
||||
|
||||
from . import util
|
||||
from virtinst import support
|
||||
|
@ -30,7 +30,7 @@ import traceback
|
||||
|
||||
import libvirt
|
||||
|
||||
from virtcli import cliconfig
|
||||
from virtcli import CLIConfig
|
||||
|
||||
from . import util
|
||||
from .clock import Clock
|
||||
@ -125,7 +125,7 @@ def setupParser(usage, description, introspection_epilog=False):
|
||||
formatter_class=VirtHelpFormatter,
|
||||
epilog=epilog)
|
||||
parser.add_argument('--version', action='version',
|
||||
version=cliconfig.__version__)
|
||||
version=CLIConfig.version)
|
||||
|
||||
return parser
|
||||
|
||||
|
@ -31,7 +31,7 @@ from .cli import VirtOptionString
|
||||
from .guest import Guest
|
||||
from .nodedev import NodeDevice
|
||||
from .storage import StoragePool, StorageVolume
|
||||
from virtcli import cliconfig
|
||||
from virtcli import CLIConfig
|
||||
|
||||
_virtinst_uri_magic = "__virtinst_test__"
|
||||
|
||||
@ -334,7 +334,7 @@ class VirtualConnection(object):
|
||||
to ensure we don't enable VM devices that are compiled out on
|
||||
RHEL, like vmvga
|
||||
"""
|
||||
if not cliconfig.stable_defaults and not force:
|
||||
if not CLIConfig.stable_defaults and not force:
|
||||
return False
|
||||
|
||||
if not self.is_qemu_system():
|
||||
|
@ -249,8 +249,8 @@ class VirtualDisk(VirtualDevice):
|
||||
if conn.is_remote() or not conn.is_qemu_system():
|
||||
return None, []
|
||||
|
||||
from virtcli import cliconfig
|
||||
user = cliconfig.default_qemu_user
|
||||
from virtcli import CLIConfig
|
||||
user = CLIConfig.default_qemu_user
|
||||
try:
|
||||
for secmodel in conn.caps.host.secmodels:
|
||||
if secmodel.model != "dac":
|
||||
|
@ -24,7 +24,7 @@ import logging
|
||||
import urlgrabber.progress as progress
|
||||
import libvirt
|
||||
|
||||
from virtcli import cliconfig
|
||||
from virtcli import CLIConfig
|
||||
|
||||
from . import util
|
||||
from . import support
|
||||
@ -113,7 +113,7 @@ class Guest(XMLBuilder):
|
||||
self.replace = False
|
||||
|
||||
# Allow virt-manager to override the default graphics type
|
||||
self.default_graphics_type = cliconfig.default_graphics
|
||||
self.default_graphics_type = CLIConfig.default_graphics
|
||||
|
||||
self.skip_default_console = False
|
||||
self.skip_default_channel = False
|
||||
|
Loading…
Reference in New Issue
Block a user