
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> add a method to get kimchi version in config.py If kimchi run after package install, just get the version. Or get the build nubmer. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/Makefile.am | 4 +++- src/kimchi/config.py.in | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/kimchi/Makefile.am b/src/kimchi/Makefile.am index 957d2c9..e2b5bea 100644 --- a/src/kimchi/Makefile.am +++ b/src/kimchi/Makefile.am @@ -41,7 +41,9 @@ do_substitution = \ -e 's,[@]sysconfdir[@],$(sysconfdir),g' \ -e 's,[@]localstatedir[@],$(localstatedir),g' \ -e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \ - -e 's,[@]kimchidir[@],$(kimchidir),g' + -e 's,[@]kimchidir[@],$(kimchidir),g' \ + -e 's,[@]kimchiversion[@],$(PACKAGE_VERSION),g' \ + -e 's,[@]kimchirelease[@],$(PACKAGE_RELEASE),g' config.py: config.py.in Makefile diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in index 04218c2..a260885 100644 --- a/src/kimchi/config.py.in +++ b/src/kimchi/config.py.in @@ -21,6 +21,7 @@ import libvirt import os import platform +import subprocess import threading @@ -29,6 +30,8 @@ from ConfigParser import SafeConfigParser from kimchi.xmlutils import xpath_get_text +__version__ = "@kimchiversion@" +__release__ = "@kimchirelease@" DEFAULT_LOG_LEVEL = "debug" @@ -54,6 +57,50 @@ def get_debugreports_path(): return os.path.join(paths.state_dir, 'debugreports') +def check_in_source_directory(): + if __file__.startswith("/"): + base = os.path.dirname(__file__) + else: + base = os.path.dirname('./%s' % __file__) + + if os.access('%s/../../src/kimchi/config.py' % base, os.F_OK): + return True + + return False + + +def check_in_packaged_directory(): + # FIXME + # 1. We can not guarantee only one kimchid is running at the same time. + # Maybe a kimchid by make install is running, another kimchid by package + # isntall is also running with different http/https port and directory. + # 2. Even kimchid is installed by package, we can still stop it, and run + # kimchid in make install directory + try: + cmd = ["rpm", "-qa", "kimchi"] + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, error = proc.communicate() + if out != "" and proc.returncode == 0: + return True + except OSError: + cmd = ["dpkg", "--get-selections", "kimchi"] + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, error = proc.communicate() + if "install" in out and proc.returncode == 0: + return True + + return False + + +def get_version(): + if check_in_source_directory() or not check_in_packaged_directory(): + return "-".join([__version__, __release__]) + + return __version__ + + def find_qemu_binary(find_emulator=False): try: connect = libvirt.open('qemu:///system') -- 1.8.5.3