Method check_output used for getting hash of HEAD in git repo was
introduced in Python2.7 and it does not work for Python2.6 which is
default Python version for RHEL6.x.
This patch replaces method check_output with Popen which is available in
both 2.6 and 2.7.
Fixes #174
---
changes in v2:
prettier code
---
Signed-off-by: Jiri Prochazka <jprochaz(a)redhat.com>
Signed-off-by: Jiri Prochazka <jprochaz(a)redhat.com>
---
lnst/Common/Config.py | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/lnst/Common/Config.py b/lnst/Common/Config.py
index 5362da1..e20e566 100644
--- a/lnst/Common/Config.py
+++ b/lnst/Common/Config.py
@@ -34,19 +34,22 @@ class Config():
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)
- with open(os.devnull, 'w') as null:
- head = subprocess.check_output(['git', 'rev-parse',
'HEAD'],
- stderr=null).strip()
- return head
- except subprocess.CalledProcessError:
- return LNSTMajorVersion
- finally:
- os.chdir(cwd)
+ cwd = os.getcwd()
+ abspath = os.path.abspath(__file__)
+ dname = os.path.dirname(abspath)
+ os.chdir(dname)
+ with open(os.devnull, 'w') as null:
+ cmd = ['git', 'rev-parse', 'HEAD']
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=null)
+ data = proc.communicate()
+ # git command passed
+ if data[0] != '':
+ version = data[0].strip()
+ # git command failed
+ else:
+ version = LNSTMajorVersion
+ os.chdir(cwd)
+ return version
def controller_init(self):
self._options['environment'] = dict()
--
2.4.11