setup: Make gsettings always work regardless of install dir (bz #1267377)
Most of this is lifted from 'meld'. The bits are - compile gsettings schemas at setup.py install time - add options to disable that, and use them in the RPM - always pass GSETTINGS_SCHEMA_DIR so gsettings loading always works regardless of the install dir https://bugzilla.redhat.com/show_bug.cgi?id=1267377
This commit is contained in:
parent
293a1d1509
commit
fe722b99cb
|
@ -4,6 +4,7 @@ include MANIFEST.in
|
|||
include setup.py
|
||||
include virt-*
|
||||
recursive-include data *
|
||||
exclude data/gschemas.compiled
|
||||
recursive-include man *
|
||||
recursive-include po *
|
||||
recursive-include tests *
|
||||
|
|
43
setup.py
43
setup.py
|
@ -5,14 +5,16 @@ import glob
|
|||
import fnmatch
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import distutils
|
||||
import distutils.command.build
|
||||
import distutils.command.install
|
||||
import distutils.command.install_data
|
||||
import distutils.command.install_egg_info
|
||||
import distutils.command.sdist
|
||||
import distutils.dist
|
||||
import distutils.log
|
||||
import distutils.sysconfig
|
||||
sysprefix = distutils.sysconfig.get_config_var("prefix")
|
||||
|
||||
|
@ -237,15 +239,25 @@ class my_install(distutils.command.install.install):
|
|||
(self.prefix, CLIConfig.prefix))
|
||||
sys.exit(1)
|
||||
|
||||
if self.prefix != "/usr":
|
||||
print ("WARNING: GSettings may not find your schema if it's\n"
|
||||
"not in /usr/share. You may need to manually play with\n"
|
||||
"GSETTINGS_SCHEMA_DIR and glib-compile-schemas.\n\n")
|
||||
time.sleep(2)
|
||||
|
||||
distutils.command.install.install.finalize_options(self)
|
||||
|
||||
|
||||
class my_install_data(distutils.command.install_data.install_data):
|
||||
def run(self):
|
||||
distutils.command.install_data.install_data.run(self)
|
||||
|
||||
if not self.distribution.no_update_icon_cache:
|
||||
distutils.log.info("running gtk-update-icon-cache")
|
||||
icon_path = os.path.join(self.install_dir, "share/icons/hicolor")
|
||||
self.spawn(["gtk-update-icon-cache", "-q", "-t", icon_path])
|
||||
|
||||
if not self.distribution.no_compile_schemas:
|
||||
distutils.log.info("compiling gsettings schemas")
|
||||
gschema_install = os.path.join(self.install_dir,
|
||||
"share/glib-2.0/schemas")
|
||||
self.spawn(["glib-compile-schemas", gschema_install])
|
||||
|
||||
|
||||
class my_sdist(distutils.command.sdist.sdist):
|
||||
description = "Update virt-manager.spec; build sdist-tarball."
|
||||
|
||||
|
@ -593,6 +605,18 @@ class CheckPylint(distutils.core.Command):
|
|||
os.system(cmd)
|
||||
|
||||
|
||||
class VMMDistribution(distutils.dist.Distribution):
|
||||
global_options = distutils.dist.Distribution.global_options + [
|
||||
("no-update-icon-cache", None, "Don't run gtk-update-icon-cache"),
|
||||
("no-compile-schemas", None, "Don't compile gsettings schemas"),
|
||||
]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.no_update_icon_cache = False
|
||||
self.no_compile_schemas = False
|
||||
distutils.dist.Distribution.__init__(self, *args, **kwargs)
|
||||
|
||||
|
||||
distutils.core.setup(
|
||||
name="virt-manager",
|
||||
version=CLIConfig.version,
|
||||
|
@ -645,6 +669,7 @@ distutils.core.setup(
|
|||
|
||||
'sdist': my_sdist,
|
||||
'install': my_install,
|
||||
'install_data': my_install_data,
|
||||
'install_egg_info': my_egg_info,
|
||||
|
||||
'configure': configure,
|
||||
|
@ -655,5 +680,7 @@ distutils.core.setup(
|
|||
'test_ui': TestUI,
|
||||
'test_urls' : TestURLFetch,
|
||||
'test_initrd_inject' : TestInitrdInject,
|
||||
}
|
||||
},
|
||||
|
||||
distclass=VMMDistribution,
|
||||
)
|
||||
|
|
|
@ -141,7 +141,9 @@ python setup.py configure \
|
|||
|
||||
|
||||
%install
|
||||
python setup.py install -O1 --root=%{buildroot}
|
||||
python setup.py \
|
||||
--no-update-icon-cache --no-compile-schemas \
|
||||
install -O1 --root=%{buildroot}
|
||||
%find_lang %{name}
|
||||
|
||||
# The conversion script was only added to virt-manager after several
|
||||
|
|
|
@ -31,12 +31,18 @@ RUNNING_CONFIG = None
|
|||
|
||||
|
||||
class SettingsWrapper(object):
|
||||
def __init__(self, settings_id):
|
||||
"""
|
||||
Wrapper class to simplify interacting with gsettings APIs
|
||||
"""
|
||||
def __init__(self, settings_id, schemadir):
|
||||
self._root = settings_id
|
||||
|
||||
os.environ["GSETTINGS_SCHEMA_DIR"] = schemadir
|
||||
self._settings = Gio.Settings.new(self._root)
|
||||
|
||||
self._settingsmap = {"": self._settings}
|
||||
self._handler_map = {}
|
||||
|
||||
for child in self._settings.list_children():
|
||||
childschema = self._root + "." + child
|
||||
self._settingsmap[child] = Gio.Settings.new(childschema)
|
||||
|
@ -155,7 +161,8 @@ class vmmConfig(object):
|
|||
self.ui_dir = CLIConfig.ui_dir
|
||||
self.test_first_run = bool(test_first_run)
|
||||
|
||||
self.conf = SettingsWrapper("org.virt-manager.virt-manager")
|
||||
self.conf = SettingsWrapper("org.virt-manager.virt-manager",
|
||||
CLIConfig.gsettings_dir)
|
||||
|
||||
# We don't create it straight away, since we don't want
|
||||
# to block the app pending user authorization to access
|
||||
|
|
|
@ -63,7 +63,6 @@ def _setup_gsettings_path(schemadir):
|
|||
raise RuntimeError("You must install glib-compile-schemas to run "
|
||||
"virt-manager from git.")
|
||||
|
||||
os.environ["GSETTINGS_SCHEMA_DIR"] = schemadir
|
||||
ret = subprocess.call([exe, "--strict", schemadir])
|
||||
if ret != 0:
|
||||
raise RuntimeError("Failed to compile local gsettings schemas")
|
||||
|
@ -92,6 +91,7 @@ class _CLIConfig(object):
|
|||
self.gettext_dir = None
|
||||
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)
|
||||
|
||||
|
@ -100,13 +100,16 @@ class _CLIConfig(object):
|
|||
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)
|
||||
self.icon_dir = os.path.join(_srcdir, "data")
|
||||
self.gsettings_dir = self.icon_dir
|
||||
_setup_gsettings_path(self.gsettings_dir)
|
||||
else:
|
||||
self.ui_dir = os.path.join(prefix, "share", "virt-manager", "ui")
|
||||
self.icon_dir = os.path.join(prefix, "share", "virt-manager",
|
||||
"icons")
|
||||
self.ui_dir = os.path.join(prefix, "share", "virt-manager", "ui")
|
||||
self.gsettings_dir = os.path.join(prefix, "share",
|
||||
"glib-2.0", "schemas")
|
||||
|
||||
|
||||
CLIConfig = _CLIConfig()
|
||||
|
|
Loading…
Reference in New Issue