2013-03-17 09:32:29 +08:00
|
|
|
#
|
2014-01-21 00:09:13 +08:00
|
|
|
# Copyright (C) 2013, 2014 Red Hat, Inc.
|
2013-03-17 09:32:29 +08:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
|
|
|
"""
|
|
|
|
Configuration variables that can be set at build time
|
|
|
|
"""
|
|
|
|
|
|
|
|
import ConfigParser
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
2015-04-07 02:23:10 +08:00
|
|
|
_cfg = ConfigParser.ConfigParser()
|
2013-03-17 09:32:29 +08:00
|
|
|
_filepath = os.path.abspath(__file__)
|
|
|
|
_srcdir = os.path.abspath(os.path.join(os.path.dirname(_filepath), ".."))
|
2015-04-07 02:23:10 +08:00
|
|
|
_cfgpath = os.path.join(os.path.dirname(_filepath), "cli.cfg")
|
|
|
|
if os.path.exists(_cfgpath):
|
|
|
|
_cfg.read(_cfgpath)
|
|
|
|
|
2013-10-03 06:42:51 +08:00
|
|
|
_istest = "VIRTINST_TEST_SUITE" in os.environ
|
2015-04-07 02:23:10 +08:00
|
|
|
_running_from_srcdir = os.path.exists(
|
|
|
|
os.path.join(_srcdir, "tests", "clitest.py"))
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2013-03-17 09:32:29 +08:00
|
|
|
def _split_list(commastr):
|
|
|
|
return [d for d in commastr.split(",") if d]
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2013-04-11 04:47:36 +08:00
|
|
|
def _get_param(name, default):
|
2013-10-09 02:42:59 +08:00
|
|
|
if _istest:
|
|
|
|
return default
|
|
|
|
try:
|
2015-04-07 02:23:10 +08:00
|
|
|
return _cfg.get("config", name)
|
2013-10-09 23:33:18 +08:00
|
|
|
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
|
2013-03-17 09:32:29 +08:00
|
|
|
return default
|
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
|
|
|
|
def _setup_gsettings_path(schemadir):
|
|
|
|
"""
|
|
|
|
If running from the virt-manager.git srcdir, compile our gsettings
|
|
|
|
schema and use it directly
|
|
|
|
"""
|
|
|
|
import subprocess
|
2014-06-01 04:28:58 +08:00
|
|
|
from distutils.spawn import find_executable
|
|
|
|
|
|
|
|
exe = find_executable("glib-compile-schemas")
|
|
|
|
if not exe:
|
|
|
|
raise RuntimeError("You must install glib-compile-schemas to run "
|
|
|
|
"virt-manager from git.")
|
2013-04-18 05:39:25 +08:00
|
|
|
|
2014-06-01 04:28:58 +08:00
|
|
|
ret = subprocess.call([exe, "--strict", schemadir])
|
2013-04-24 01:17:20 +08:00
|
|
|
if ret != 0:
|
|
|
|
raise RuntimeError("Failed to compile local gsettings schemas")
|
2013-04-18 05:39:25 +08:00
|
|
|
|
|
|
|
|
2017-03-09 07:48:48 +08:00
|
|
|
__version__ = "1.4.1"
|
2013-03-17 09:32:29 +08:00
|
|
|
|
2015-04-07 03:42:40 +08:00
|
|
|
|
|
|
|
class _CLIConfig(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.cfgpath = _cfgpath
|
|
|
|
self.version = __version__
|
|
|
|
|
|
|
|
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")
|
2015-04-07 04:29:28 +08:00
|
|
|
self.default_hvs = _split_list(_get_param("default_hvs", ""))
|
2015-04-07 03:42:40 +08:00
|
|
|
|
|
|
|
self.prefix = None
|
|
|
|
self.gettext_dir = None
|
|
|
|
self.ui_dir = None
|
|
|
|
self.icon_dir = None
|
2015-11-03 05:19:31 +08:00
|
|
|
self.gsettings_dir = None
|
2015-04-07 03:42:40 +08:00
|
|
|
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.ui_dir = os.path.join(_srcdir, "ui")
|
2015-11-03 05:19:31 +08:00
|
|
|
self.icon_dir = os.path.join(_srcdir, "data")
|
|
|
|
self.gsettings_dir = self.icon_dir
|
|
|
|
_setup_gsettings_path(self.gsettings_dir)
|
2015-04-07 03:42:40 +08:00
|
|
|
else:
|
2015-11-03 05:19:31 +08:00
|
|
|
self.ui_dir = os.path.join(prefix, "share", "virt-manager", "ui")
|
2015-04-07 03:42:40 +08:00
|
|
|
self.icon_dir = os.path.join(prefix, "share", "virt-manager",
|
|
|
|
"icons")
|
2015-11-03 05:19:31 +08:00
|
|
|
self.gsettings_dir = os.path.join(prefix, "share",
|
|
|
|
"glib-2.0", "schemas")
|
2015-04-07 03:42:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
CLIConfig = _CLIConfig()
|