2013-03-16 21:32:29 -04:00
#
2014-01-20 17:09:13 +01:00
# Copyright (C) 2013, 2014 Red Hat, Inc.
2013-03-16 21:32:29 -04:00
#
2018-04-04 14:35:41 +01:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 15:00:02 -04:00
# See the COPYING file in the top-level directory.
2013-03-16 21:32:29 -04:00
#
"""
Configuration variables that can be set at build time
"""
import os
2018-03-21 18:00:38 -04:00
import sys
2019-06-10 18:13:31 -04:00
if ( sys . version_info . major != 3 or
sys . version_info . minor < 4 ) : # pragma: no cover
2018-03-21 18:00:38 -04:00
print ( " python 3.4 or later is required, your ' s is %s " %
sys . version_info )
sys . exit ( 1 )
2013-03-16 21:32:29 -04:00
2018-03-21 18:00:38 -04:00
import configparser
2013-03-16 21:32:29 -04:00
2017-10-11 12:35:39 +01:00
_cfg = configparser . ConfigParser ( )
2013-03-16 21:32:29 -04:00
_filepath = os . path . abspath ( __file__ )
_srcdir = os . path . abspath ( os . path . join ( os . path . dirname ( _filepath ) , " .. " ) )
2019-06-14 16:34:00 -04:00
_cfgpath = os . path . join ( os . path . dirname ( _filepath ) , " build.cfg " )
2015-04-06 14:23:10 -04:00
if os . path . exists ( _cfgpath ) :
2019-06-10 18:13:31 -04:00
_cfg . read ( _cfgpath ) # pragma: no cover
2015-04-06 14:23:10 -04:00
2013-10-02 18:42:51 -04:00
_istest = " VIRTINST_TEST_SUITE " in os . environ
2015-04-06 14:23:10 -04:00
_running_from_srcdir = os . path . exists (
2020-01-26 18:29:39 -05:00
os . path . join ( _srcdir , " tests " , " test_cli.py " ) )
2013-03-16 21:32:29 -04:00
2013-04-13 14:34:52 -04:00
2013-03-16 21:32:29 -04:00
def _split_list ( commastr ) :
return [ d for d in commastr . split ( " , " ) if d ]
2013-04-13 14:34:52 -04:00
2019-06-10 18:13:31 -04:00
def _get_param ( name , default ) : # pragma: no cover
2013-10-08 14:42:59 -04:00
if _istest :
return default
try :
2015-04-06 14:23:10 -04:00
return _cfg . get ( " config " , name )
2017-10-11 12:35:39 +01:00
except ( configparser . NoOptionError , configparser . NoSectionError ) :
2013-03-16 21:32:29 -04:00
return default
2013-04-17 17:39:25 -04:00
2022-08-04 15:53:33 -04:00
__version__ = " 4.1.0 "
2013-03-16 21:32:29 -04:00
2015-04-06 15:42:40 -04:00
2019-06-14 16:34:00 -04:00
class _BuildConfig ( object ) :
2015-04-06 15:42:40 -04:00
def __init__ ( self ) :
self . cfgpath = _cfgpath
self . version = __version__
self . default_graphics = _get_param ( " default_graphics " , " spice " )
2015-04-06 16:29:28 -04:00
self . default_hvs = _split_list ( _get_param ( " default_hvs " , " " ) )
2015-04-06 15:42:40 -04:00
self . prefix = None
self . gettext_dir = None
self . ui_dir = None
self . icon_dir = None
2015-11-02 16:19:31 -05:00
self . gsettings_dir = None
2019-06-14 16:34:00 -04:00
self . running_from_srcdir = _running_from_srcdir
self . _set_paths_by_prefix ( _get_param ( " prefix " , " /usr " ) )
2015-04-06 15:42:40 -04:00
2019-06-14 16:34:00 -04:00
def _set_paths_by_prefix ( self , prefix ) :
2015-04-06 15:42:40 -04:00
self . prefix = prefix
self . gettext_dir = os . path . join ( prefix , " share " , " locale " )
2019-06-14 16:34:00 -04:00
if self . running_from_srcdir :
2015-04-06 15:42:40 -04:00
self . ui_dir = os . path . join ( _srcdir , " ui " )
2015-11-02 16:19:31 -05:00
self . icon_dir = os . path . join ( _srcdir , " data " )
self . gsettings_dir = self . icon_dir
2019-06-10 18:13:31 -04:00
else : # pragma: no cover
2015-11-02 16:19:31 -05:00
self . ui_dir = os . path . join ( prefix , " share " , " virt-manager " , " ui " )
2015-04-06 15:42:40 -04:00
self . icon_dir = os . path . join ( prefix , " share " , " virt-manager " ,
" icons " )
2015-11-02 16:19:31 -05:00
self . gsettings_dir = os . path . join ( prefix , " share " ,
" glib-2.0 " , " schemas " )
2015-04-06 15:42:40 -04:00
2019-06-14 16:34:00 -04:00
BuildConfig = _BuildConfig ( )