[PATCH 1 of 3 v2] hooks: add intermediate function _get_python_executable
Thomas De Schampheleire
patrickdepinguin at gmail.com
Wed Apr 3 20:28:29 UTC 2019
# HG changeset patch
# User Thomas De Schampheleire <thomas.de_schampheleire at nokia.com>
# Date 1554320638 -7200
# Wed Apr 03 21:43:58 2019 +0200
# Branch stable
# Node ID 8d7e20c6980cd4e27eeafa15f574d929d836dd76
# Parent 953047e8c88a9c5ccaa4ddc1bb417622de37f01f
hooks: add intermediate function _get_python_executable
... to avoid code duplication.
diff --git a/kallithea/model/scm.py b/kallithea/model/scm.py
--- a/kallithea/model/scm.py
+++ b/kallithea/model/scm.py
@@ -720,6 +720,10 @@ class ScmModel(object):
return choices, hist_l
+ def _get_python_executable(self):
+ """Return a Python executable for use in hooks."""
+ return sys.executable or 'python2'
+
def install_git_hooks(self, repo, force_create=False):
"""
Creates a kallithea hook inside a git repository
@@ -734,11 +738,11 @@ class ScmModel(object):
if not os.path.isdir(loc):
os.makedirs(loc)
- tmpl_post = "#!/usr/bin/env %s\n" % sys.executable or 'python2'
+ tmpl_post = "#!/usr/bin/env %s\n" % self._get_python_executable()
tmpl_post += pkg_resources.resource_string(
'kallithea', os.path.join('config', 'post_receive_tmpl.py')
)
- tmpl_pre = "#!/usr/bin/env %s\n" % sys.executable or 'python2'
+ tmpl_pre = "#!/usr/bin/env %s\n" % self._get_python_executable()
tmpl_pre += pkg_resources.resource_string(
'kallithea', os.path.join('config', 'pre_receive_tmpl.py')
)
More information about the kallithea-general
mailing list