[PATCH 1/2] config version API support: add a method to get kimchi version

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

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> update API.md, mockmodel, model and API.md Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- docs/API.md | 1 + src/kimchi/mockmodel.py | 3 ++- src/kimchi/model/config.py | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/API.md b/docs/API.md index 143c70c..fbcc597 100644 --- a/docs/API.md +++ b/docs/API.md @@ -557,6 +557,7 @@ Contains information about the application environment and configuration. * **GET**: Retrieve configuration information * http_port: The port number on which the server is listening * display_proxy_port: Port for vnc and spice's websocket proxy to listen on + * version: The version of the kimchi service * **POST**: *See Configuration Actions* **Actions (POST):** diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py index bf17975..e029ef0 100644 --- a/src/kimchi/mockmodel.py +++ b/src/kimchi/mockmodel.py @@ -832,7 +832,8 @@ class MockModel(object): def config_lookup(self, name): return {'http_port': cherrypy.server.socket_port, 'display_proxy_port': - kconfig.get('display', 'display_proxy_port')} + kconfig.get('display', 'display_proxy_port'), + 'version': config.get_version()} def packagesupdate_get_list(self): return self._mock_swupdate.getUpdates() diff --git a/src/kimchi/model/config.py b/src/kimchi/model/config.py index a6d00ab..7081373 100644 --- a/src/kimchi/model/config.py +++ b/src/kimchi/model/config.py @@ -23,7 +23,7 @@ import cherrypy from kimchi.basemodel import Singleton from kimchi.config import config as kconfig -from kimchi.config import find_qemu_binary +from kimchi.config import find_qemu_binary, get_version from kimchi.distroloader import DistroLoader from kimchi.exception import NotFoundError from kimchi.featuretests import FeatureTests @@ -41,7 +41,8 @@ class ConfigModel(object): def lookup(self, name): proxy_port = kconfig.get('display', 'display_proxy_port') return {'http_port': cherrypy.server.socket_port, - 'display_proxy_port': proxy_port} + 'display_proxy_port': proxy_port, + 'version': get_version()} class CapabilitiesModel(object): -- 1.8.5.3
participants (1)
-
shaohef@linux.vnet.ibm.com