# HG changeset patch # User Marcin Kuzminski # Date 1348685977 -7200 # Node ID ccbdff90e5a0883213f285433b0aef1db3fc54cc # Parent 4982f5b06e2bf9949c9a9ffe717e63eaa8641465 fix for issue #578 git hooks sometimes cannot be executed due to different python they runned under, this commit tries to fix that by altering the PATH env variable using current python that rhodecode is running diff -r 4982f5b06e2b -r ccbdff90e5a0 rhodecode/lib/middleware/simplegit.py --- a/rhodecode/lib/middleware/simplegit.py Sun Sep 23 23:34:09 2012 +0200 +++ b/rhodecode/lib/middleware/simplegit.py Wed Sep 26 20:59:37 2012 +0200 @@ -79,7 +79,7 @@ from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError, \ HTTPBadRequest, HTTPNotAcceptable -from rhodecode.lib.utils2 import safe_str +from rhodecode.lib.utils2 import safe_str, fix_PATH from rhodecode.lib.base import BaseVCSController from rhodecode.lib.auth import get_container_username from rhodecode.lib.utils import is_valid_repo, make_ui @@ -220,6 +220,7 @@ 'locked_by': locked_by}) # set the environ variables for this request os.environ['RC_SCM_DATA'] = json.dumps(extras) + fix_PATH() log.debug('HOOKS extras is %s' % extras) baseui = make_ui('db') self.__inject_extras(repo_path, baseui, extras) diff -r 4982f5b06e2b -r ccbdff90e5a0 rhodecode/lib/middleware/simplehg.py --- a/rhodecode/lib/middleware/simplehg.py Sun Sep 23 23:34:09 2012 +0200 +++ b/rhodecode/lib/middleware/simplehg.py Wed Sep 26 20:59:37 2012 +0200 @@ -27,7 +27,6 @@ import os import logging import traceback -import urllib from mercurial.error import RepoError from mercurial.hgweb import hgweb_mod @@ -36,7 +35,7 @@ from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError, \ HTTPBadRequest, HTTPNotAcceptable -from rhodecode.lib.utils2 import safe_str +from rhodecode.lib.utils2 import safe_str, fix_PATH from rhodecode.lib.base import BaseVCSController from rhodecode.lib.auth import get_container_username from rhodecode.lib.utils import make_ui, is_valid_repo, ui_sections @@ -184,6 +183,7 @@ # set the environ variables for this request os.environ['RC_SCM_DATA'] = json.dumps(extras) + fix_PATH() log.debug('HOOKS extras is %s' % extras) baseui = make_ui('db') self.__inject_extras(repo_path, baseui, extras) diff -r 4982f5b06e2b -r ccbdff90e5a0 rhodecode/lib/utils2.py --- a/rhodecode/lib/utils2.py Sun Sep 23 23:34:09 2012 +0200 +++ b/rhodecode/lib/utils2.py Wed Sep 26 20:59:37 2012 +0200 @@ -481,3 +481,19 @@ return self.get(attr, None) __setattr__ = dict.__setitem__ __delattr__ = dict.__delitem__ + + +def fix_PATH(os_=None): + """ + Get current active python path, and append it to PATH variable to fix issues + of subprocess calls and different python versions + """ + import sys + if os_ is None: + import os + else: + os = os_ + + cur_path = os.path.split(sys.executable)[0] + if not os.environ['PATH'].startswith(cur_path): + os.environ['PATH'] = '%s:%s' % (cur_path, os.environ['PATH'])