This patch is first from series which implements version control in LNST.
The are two types of versions - LNST Major Version and git HEAD commit
hash. LNST Major Version is used when LNST is installed and run from
RPM and git commit hash is used when LNST is run from devel git repo.
LNSTMajorVersion variable in Config.py will have to be manully
incremented each time new release is made.
Used version is stored in Config.version attribute.
Getting git HEAD commit hash is done in following steps:
1) Save cwd
2) Change cwd to directory where Config.py file is located
3) Try running git rev-parse HEAD, which returns commit hash
4) If git command execution was successful, use hash as version
5) Else use value of LNSTMajorVersion as version
6) Return to original working directory
If we didn't change cwd, we would have problems with running LNST installed
from RPM in any git repo folder.
Signed-off-by: Jiri Prochazka <jprochaz(a)redhat.com>
---
lnst/Common/Config.py | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/lnst/Common/Config.py b/lnst/Common/Config.py
index 31481b2..7b4d17e 100644
--- a/lnst/Common/Config.py
+++ b/lnst/Common/Config.py
@@ -13,12 +13,15 @@ olichtne(a)redhat.com (Ondrej Lichtner)
import os
import sys
import re
+import subprocess
from lnst.Common.Utils import bool_it
from lnst.Common.NetUtils import verify_mac_address
from lnst.Common.Colours import get_preset_conf
DefaultRPCPort = 9999
+LNSTMajorVersion = '11'
+
class ConfigError(Exception):
pass
@@ -28,6 +31,21 @@ class Config():
def __init__(self):
self._options = dict()
+ self.version = self._get_version()
+
+ def _get_version(self):
+ # Check if I'm in git
+ try:
+ cwd = os.getcwd()
+ abspath = os.path.abspath(__file__)
+ dname = os.path.dirname(abspath)
+ os.chdir(dname)
+ head = subprocess.check_output(['git', 'rev-parse',
'HEAD']).strip()
+ return head
+ except subprocess.CalledProcessError:
+ return LNSTMajorVersion
+ finally:
+ os.chdir(cwd)
def controller_init(self):
self._options['environment'] = dict()
--
2.4.11
Show replies by date