mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-08 21:18:04 +03:00
Move virtcli/cliconfig.py to virtinst/buildconfig.py
There's really no reason for the split, just contain it all within virtinst for simplicity
This commit is contained in:
parent
0e5fb7d7c2
commit
ab7b3c189f
2
.gitignore
vendored
2
.gitignore
vendored
@ -18,4 +18,4 @@ po/virt-manager.pot
|
||||
/man/virt-xml.1
|
||||
|
||||
/virt-manager.spec
|
||||
/virtcli/cli.cfg
|
||||
/virtinst/build.cfg
|
||||
|
@ -10,7 +10,6 @@ recursive-include po *
|
||||
recursive-include tests *
|
||||
recursive-include ui *
|
||||
recursive-include virtManager *
|
||||
recursive-include virtcli *
|
||||
recursive-include virtconv *
|
||||
recursive-include virtinst *
|
||||
global-exclude *.pyc
|
||||
|
69
setup.py
69
setup.py
@ -4,10 +4,15 @@
|
||||
# See the COPYING file in the top-level directory.
|
||||
|
||||
|
||||
import sys
|
||||
if sys.version_info.major < 3:
|
||||
print("virt-manager is python3 only. Run this as ./setup.py")
|
||||
sys.exit(1)
|
||||
|
||||
import glob
|
||||
import fnmatch
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import unittest
|
||||
|
||||
import distutils
|
||||
@ -21,15 +26,27 @@ import distutils.log
|
||||
import distutils.sysconfig
|
||||
|
||||
|
||||
if sys.version_info.major < 3:
|
||||
print("virt-manager is python3 only. Run this as ./setup.py")
|
||||
sys.exit(1)
|
||||
|
||||
from virtcli import CLIConfig
|
||||
|
||||
sysprefix = distutils.sysconfig.get_config_var("prefix")
|
||||
|
||||
|
||||
def _parse_version():
|
||||
# We do these tricks to not mess up code coverage testing. Switching
|
||||
# to pytest will let use drop these
|
||||
path = os.path.join(os.path.dirname(__file__),
|
||||
"virtinst", "buildconfig.py")
|
||||
content = open(path).read()
|
||||
match = re.search(r"^__version__ = \".*\"$", content, re.MULTILINE)
|
||||
return str(match.group(0)).split()[-1].strip("\"")
|
||||
|
||||
|
||||
def _get_buildconfig():
|
||||
from virtinst import BuildConfig
|
||||
return BuildConfig
|
||||
|
||||
|
||||
VERSION = _parse_version()
|
||||
|
||||
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
|
||||
_desktop_files = [
|
||||
@ -54,7 +71,6 @@ def _generate_potfiles_in():
|
||||
|
||||
potfiles = "\n".join(scripts) + "\n\n"
|
||||
potfiles += "\n".join(find("virtManager", "*.py")) + "\n\n"
|
||||
potfiles += "\n".join(find("virtcli", "*.py")) + "\n\n"
|
||||
potfiles += "\n".join(find("virtconv", "*.py")) + "\n\n"
|
||||
potfiles += "\n".join(find("virtinst", "*.py")) + "\n\n"
|
||||
|
||||
@ -164,12 +180,13 @@ class my_build(distutils.command.build.build):
|
||||
def _make_bin_wrappers(self):
|
||||
cmds = ["virt-manager", "virt-install", "virt-clone",
|
||||
"virt-convert", "virt-xml"]
|
||||
BuildConfig = _get_buildconfig()
|
||||
|
||||
if not os.path.exists("build"):
|
||||
os.mkdir("build")
|
||||
|
||||
for app in cmds:
|
||||
sharepath = os.path.join(CLIConfig.prefix,
|
||||
sharepath = os.path.join(BuildConfig.prefix,
|
||||
"share", "virt-manager", app)
|
||||
|
||||
wrapper = "#!/bin/sh\n\n"
|
||||
@ -181,6 +198,7 @@ class my_build(distutils.command.build.build):
|
||||
|
||||
|
||||
def _make_man_pages(self):
|
||||
BuildConfig = _get_buildconfig()
|
||||
for path in glob.glob("man/*.pod"):
|
||||
base = os.path.basename(path)
|
||||
appname = os.path.splitext(base)[0]
|
||||
@ -191,7 +209,7 @@ class my_build(distutils.command.build.build):
|
||||
ret = os.system('pod2man '
|
||||
'--center "Virtual Machine Manager" '
|
||||
'--release %s --name %s '
|
||||
'< %s > %s' % (CLIConfig.version,
|
||||
'< %s > %s' % (BuildConfig.version,
|
||||
appname.upper(),
|
||||
path, newpath))
|
||||
if ret != 0:
|
||||
@ -263,19 +281,20 @@ class my_install(distutils.command.install.install):
|
||||
Error if we weren't 'configure'd with the correct install prefix
|
||||
"""
|
||||
def finalize_options(self):
|
||||
BuildConfig = _get_buildconfig()
|
||||
if self.prefix is None:
|
||||
if CLIConfig.prefix != sysprefix:
|
||||
if BuildConfig.prefix != sysprefix:
|
||||
print("Using configured prefix=%s instead of sysprefix=%s" % (
|
||||
CLIConfig.prefix, sysprefix))
|
||||
self.prefix = CLIConfig.prefix
|
||||
BuildConfig.prefix, sysprefix))
|
||||
self.prefix = BuildConfig.prefix
|
||||
else:
|
||||
print("Using sysprefix=%s" % sysprefix)
|
||||
self.prefix = sysprefix
|
||||
|
||||
elif self.prefix != CLIConfig.prefix:
|
||||
elif self.prefix != BuildConfig.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, BuildConfig.prefix))
|
||||
sys.exit(1)
|
||||
|
||||
distutils.command.install.install.finalize_options(self)
|
||||
@ -301,10 +320,11 @@ class my_sdist(distutils.command.sdist.sdist):
|
||||
description = "Update virt-manager.spec; build sdist-tarball."
|
||||
|
||||
def run(self):
|
||||
BuildConfig = _get_buildconfig()
|
||||
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@', BuildConfig.version))
|
||||
f1.close()
|
||||
f2.close()
|
||||
|
||||
@ -328,9 +348,10 @@ class my_rpm(distutils.core.Command):
|
||||
"""
|
||||
Run sdist, then 'rpmbuild' the tar.gz
|
||||
"""
|
||||
BuildConfig = _get_buildconfig()
|
||||
self.run_command('sdist')
|
||||
os.system('rpmbuild -ta --clean dist/virt-manager-%s.tar.gz' %
|
||||
CLIConfig.version)
|
||||
BuildConfig.version)
|
||||
|
||||
|
||||
class configure(distutils.core.Command):
|
||||
@ -355,6 +376,7 @@ class configure(distutils.core.Command):
|
||||
|
||||
|
||||
def run(self):
|
||||
BuildConfig = _get_buildconfig()
|
||||
template = ""
|
||||
template += "[config]\n"
|
||||
template += "prefix = %s\n" % self.prefix
|
||||
@ -363,8 +385,8 @@ class configure(distutils.core.Command):
|
||||
if self.default_hvs is not None:
|
||||
template += "default_hvs = %s\n" % self.default_hvs
|
||||
|
||||
open(CLIConfig.cfgpath, "w").write(template)
|
||||
print("Generated %s" % CLIConfig.cfgpath)
|
||||
open(BuildConfig.cfgpath, "w").write(template)
|
||||
print("Generated %s" % BuildConfig.cfgpath)
|
||||
|
||||
|
||||
class TestBaseCommand(distutils.core.Command):
|
||||
@ -587,7 +609,7 @@ class CheckPylint(distutils.core.Command):
|
||||
|
||||
files = ["setup.py", "virt-install", "virt-clone",
|
||||
"virt-convert", "virt-xml", "virt-manager",
|
||||
"virtcli", "virtinst", "virtconv", "virtManager",
|
||||
"virtinst", "virtconv", "virtManager",
|
||||
"tests"]
|
||||
|
||||
try:
|
||||
@ -639,7 +661,7 @@ class VMMDistribution(distutils.dist.Distribution):
|
||||
|
||||
distutils.core.setup(
|
||||
name="virt-manager",
|
||||
version=CLIConfig.version,
|
||||
version=VERSION,
|
||||
author="Cole Robinson",
|
||||
author_email="virt-tools-list@redhat.com",
|
||||
url="http://virt-manager.org",
|
||||
@ -675,9 +697,8 @@ distutils.core.setup(
|
||||
|
||||
("share/virt-manager/virtManager", glob.glob("virtManager/*.py")),
|
||||
|
||||
("share/virt-manager/virtcli",
|
||||
glob.glob("virtcli/*.py") + glob.glob("virtcli/cli.cfg")),
|
||||
("share/virt-manager/virtinst", glob.glob("virtinst/*.py")),
|
||||
("share/virt-manager/virtinst",
|
||||
glob.glob("virtinst/*.py") + glob.glob("virtinst/build.cfg")),
|
||||
("share/virt-manager/virtinst/devices", glob.glob("virtinst/devices/*.py")),
|
||||
("share/virt-manager/virtinst/domain", glob.glob("virtinst/domain/*.py")),
|
||||
("share/virt-manager/virtconv", glob.glob("virtconv/*.py")),
|
||||
|
@ -14,9 +14,9 @@ os.environ["VIRTINST_TEST_SUITE"] = "1"
|
||||
os.environ.pop("_ARC_DEBUG", None)
|
||||
|
||||
# pylint: disable=wrong-import-position
|
||||
from virtcli import cliconfig
|
||||
from virtinst import buildconfig
|
||||
# This sets all the cli bits back to their defaults
|
||||
imp.reload(cliconfig)
|
||||
imp.reload(buildconfig)
|
||||
|
||||
from tests import utils
|
||||
|
||||
|
@ -75,7 +75,6 @@ class TestDist(unittest.TestCase):
|
||||
files = ["virt-install", "virt-clone", "virt-convert"]
|
||||
files += _find_py("virtinst")
|
||||
files += _find_py("virtconv")
|
||||
files += _find_py("virtcli")
|
||||
|
||||
self._check_modules(files)
|
||||
|
||||
|
30
virt-manager
30
virt-manager
@ -17,9 +17,9 @@ import gi
|
||||
gi.require_version('LibvirtGLib', '1.0')
|
||||
from gi.repository import LibvirtGLib
|
||||
|
||||
from virtinst import BuildConfig
|
||||
from virtinst import VirtinstConnection
|
||||
from virtinst import cli
|
||||
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
|
||||
@ -90,6 +90,21 @@ def _import_gtk(leftovers):
|
||||
return leftovers
|
||||
|
||||
|
||||
def _setup_gsettings_path(schemadir):
|
||||
"""
|
||||
If running from the virt-manager.git srcdir, compile our gsettings
|
||||
schema and use it directly
|
||||
"""
|
||||
import subprocess
|
||||
import shutil
|
||||
|
||||
exe = shutil.which("glib-compile-schemas")
|
||||
if not exe: # pragma: no cover
|
||||
raise RuntimeError("You must install glib-compile-schemas to run "
|
||||
"virt-manager from git.")
|
||||
subprocess.check_call([exe, "--strict", schemadir])
|
||||
|
||||
|
||||
def drop_tty():
|
||||
# We fork and setsid so that we drop the controlling
|
||||
# tty. This prevents libvirt's SSH tunnels from prompting
|
||||
@ -118,7 +133,7 @@ def parse_commandline():
|
||||
parser = argparse.ArgumentParser(usage="virt-manager [options]",
|
||||
epilog=epilog)
|
||||
parser.add_argument('--version', action='version',
|
||||
version=CLIConfig.version)
|
||||
version=BuildConfig.version)
|
||||
parser.set_defaults(domain=None)
|
||||
|
||||
# Trace every libvirt API call to debug output
|
||||
@ -205,9 +220,12 @@ def main():
|
||||
cli.setupLogging("virt-manager", options.debug, False, False)
|
||||
|
||||
import virtManager
|
||||
logging.debug("virt-manager version: %s", CLIConfig.version)
|
||||
logging.debug("virt-manager version: %s", BuildConfig.version)
|
||||
logging.debug("virtManager import: %s", str(virtManager))
|
||||
|
||||
if BuildConfig.running_from_srcdir:
|
||||
_setup_gsettings_path(BuildConfig.gsettings_dir)
|
||||
|
||||
if options.trace_libvirt:
|
||||
logging.debug("Libvirt tracing requested")
|
||||
import virtManager.module_trace
|
||||
@ -227,7 +245,7 @@ def main():
|
||||
CLITestOptions.old_poll = True
|
||||
|
||||
# With F27 gnome+wayland we need to set these before GTK import
|
||||
os.environ["GSETTINGS_SCHEMA_DIR"] = CLIConfig.gsettings_dir
|
||||
os.environ["GSETTINGS_SCHEMA_DIR"] = BuildConfig.gsettings_dir
|
||||
if CLITestOptions.first_run:
|
||||
os.environ["GSETTINGS_BACKEND"] = "memory"
|
||||
|
||||
@ -266,11 +284,11 @@ def main():
|
||||
return
|
||||
|
||||
# Prime the vmmConfig cache
|
||||
virtManager.config.vmmConfig.get_instance(CLIConfig, CLITestOptions)
|
||||
virtManager.config.vmmConfig.get_instance(BuildConfig, CLITestOptions)
|
||||
|
||||
# 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(BuildConfig.icon_dir)
|
||||
|
||||
from virtManager.engine import vmmEngine
|
||||
|
||||
|
@ -152,7 +152,6 @@ done
|
||||
%files common -f %{name}.lang
|
||||
%dir %{_datadir}/%{name}
|
||||
|
||||
%{_datadir}/%{name}/virtcli
|
||||
%{_datadir}/%{name}/virtconv
|
||||
%{_datadir}/%{name}/virtinst
|
||||
|
||||
|
@ -160,11 +160,11 @@ class vmmConfig(object):
|
||||
def is_initialized(cls):
|
||||
return bool(cls._instance)
|
||||
|
||||
def __init__(self, CLIConfig, CLITestOptions):
|
||||
def __init__(self, BuildConfig, CLITestOptions):
|
||||
self.appname = "virt-manager"
|
||||
self.appversion = CLIConfig.version
|
||||
self.appversion = BuildConfig.version
|
||||
self.conf_dir = "/org/virt-manager/%s/" % self.appname
|
||||
self.ui_dir = CLIConfig.ui_dir
|
||||
self.ui_dir = BuildConfig.ui_dir
|
||||
|
||||
self.conf = _SettingsWrapper("org.virt-manager.virt-manager")
|
||||
|
||||
@ -177,8 +177,8 @@ class vmmConfig(object):
|
||||
# the keyring
|
||||
self.keyring = None
|
||||
|
||||
self.default_graphics_from_config = CLIConfig.default_graphics
|
||||
self.default_hvs = CLIConfig.default_hvs
|
||||
self.default_graphics_from_config = BuildConfig.default_graphics
|
||||
self.default_hvs = BuildConfig.default_hvs
|
||||
|
||||
self.default_storage_format_from_config = "qcow2"
|
||||
self.default_console_resizeguest = 0
|
||||
|
@ -1,6 +0,0 @@
|
||||
# Copyright (C) 2013-2015 Red Hat, Inc.
|
||||
#
|
||||
# This work is licensed under the GNU GPLv2 or later.
|
||||
# See the COPYING file in the top-level directory.
|
||||
|
||||
from .cliconfig import CLIConfig
|
@ -8,7 +8,7 @@
|
||||
import gi
|
||||
gi.require_version('Libosinfo', '1.0')
|
||||
|
||||
from virtcli import CLIConfig as _CLIConfig
|
||||
from virtinst.buildconfig import BuildConfig
|
||||
|
||||
|
||||
def _setup_i18n():
|
||||
@ -21,8 +21,8 @@ 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", BuildConfig.gettext_dir)
|
||||
gettext.bindtextdomain("virt-manager", BuildConfig.gettext_dir)
|
||||
|
||||
|
||||
def _set_libvirt_error_handler():
|
||||
|
@ -23,7 +23,7 @@ import configparser
|
||||
_cfg = configparser.ConfigParser()
|
||||
_filepath = os.path.abspath(__file__)
|
||||
_srcdir = os.path.abspath(os.path.join(os.path.dirname(_filepath), ".."))
|
||||
_cfgpath = os.path.join(os.path.dirname(_filepath), "cli.cfg")
|
||||
_cfgpath = os.path.join(os.path.dirname(_filepath), "build.cfg")
|
||||
if os.path.exists(_cfgpath):
|
||||
_cfg.read(_cfgpath) # pragma: no cover
|
||||
|
||||
@ -45,25 +45,10 @@ def _get_param(name, default): # pragma: no cover
|
||||
return default
|
||||
|
||||
|
||||
def _setup_gsettings_path(schemadir):
|
||||
"""
|
||||
If running from the virt-manager.git srcdir, compile our gsettings
|
||||
schema and use it directly
|
||||
"""
|
||||
import subprocess
|
||||
import shutil
|
||||
|
||||
exe = shutil.which("glib-compile-schemas")
|
||||
if not exe: # pragma: no cover
|
||||
raise RuntimeError("You must install glib-compile-schemas to run "
|
||||
"virt-manager from git.")
|
||||
subprocess.check_call([exe, "--strict", schemadir])
|
||||
|
||||
|
||||
__version__ = "2.1.0"
|
||||
|
||||
|
||||
class _CLIConfig(object):
|
||||
class _BuildConfig(object):
|
||||
def __init__(self):
|
||||
self.cfgpath = _cfgpath
|
||||
self.version = __version__
|
||||
@ -76,18 +61,18 @@ class _CLIConfig(object):
|
||||
self.ui_dir = None
|
||||
self.icon_dir = None
|
||||
self.gsettings_dir = None
|
||||
self.set_paths_by_prefix(_get_param("prefix", "/usr"),
|
||||
check_source_dir=True)
|
||||
self.running_from_srcdir = _running_from_srcdir
|
||||
self._set_paths_by_prefix(_get_param("prefix", "/usr"))
|
||||
|
||||
def set_paths_by_prefix(self, prefix, check_source_dir=False):
|
||||
|
||||
def _set_paths_by_prefix(self, prefix):
|
||||
self.prefix = prefix
|
||||
self.gettext_dir = os.path.join(prefix, "share", "locale")
|
||||
|
||||
if _running_from_srcdir and check_source_dir:
|
||||
if self.running_from_srcdir:
|
||||
self.ui_dir = os.path.join(_srcdir, "ui")
|
||||
self.icon_dir = os.path.join(_srcdir, "data")
|
||||
self.gsettings_dir = self.icon_dir
|
||||
_setup_gsettings_path(self.gsettings_dir)
|
||||
else: # pragma: no cover
|
||||
self.ui_dir = os.path.join(prefix, "share", "virt-manager", "ui")
|
||||
self.icon_dir = os.path.join(prefix, "share", "virt-manager",
|
||||
@ -96,4 +81,4 @@ class _CLIConfig(object):
|
||||
"glib-2.0", "schemas")
|
||||
|
||||
|
||||
CLIConfig = _CLIConfig()
|
||||
BuildConfig = _BuildConfig()
|
@ -20,9 +20,8 @@ import types
|
||||
|
||||
import libvirt
|
||||
|
||||
from virtcli import CLIConfig
|
||||
|
||||
from . import xmlutil
|
||||
from .buildconfig import BuildConfig
|
||||
from .connection import VirtinstConnection
|
||||
from .devices import (Device, DeviceController, DeviceDisk, DeviceGraphics,
|
||||
DeviceInterface, DevicePanic)
|
||||
@ -111,7 +110,7 @@ def setupParser(usage, description, introspection_epilog=False):
|
||||
formatter_class=VirtHelpFormatter,
|
||||
epilog=epilog)
|
||||
parser.add_argument('--version', action='version',
|
||||
version=CLIConfig.version)
|
||||
version=BuildConfig.version)
|
||||
|
||||
return parser
|
||||
|
||||
|
@ -11,10 +11,9 @@ import random
|
||||
|
||||
import libvirt
|
||||
|
||||
from virtcli import CLIConfig
|
||||
|
||||
from . import generatename
|
||||
from . import xmlutil
|
||||
from .buildconfig import BuildConfig
|
||||
from .devices import * # pylint: disable=wildcard-import
|
||||
from .domain import * # pylint: disable=wildcard-import
|
||||
from .domcapabilities import DomainCapabilities
|
||||
@ -220,7 +219,7 @@ class Guest(XMLBuilder):
|
||||
XMLBuilder.__init__(self, *args, **kwargs)
|
||||
|
||||
# Allow virt-manager to override the default graphics type
|
||||
self.default_graphics_type = CLIConfig.default_graphics
|
||||
self.default_graphics_type = BuildConfig.default_graphics
|
||||
|
||||
self.skip_default_console = False
|
||||
self.skip_default_channel = False
|
||||
|
Loading…
Reference in New Issue
Block a user