Mercurial > kallithea
changeset 7356:39bdf0ab2862
hooks: use os.environ directly for KALLITHEA_EXTRAS instead of sometimes passing it as parameter
It is better to be consistent ... even if that means always using the global
environment that is hard to avoid.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Wed, 08 Aug 2018 02:23:11 +0200 |
parents | efe7ed15e12c |
children | 939dfe77df58 |
files | kallithea/config/post_receive_tmpl.py kallithea/config/pre_receive_tmpl.py kallithea/lib/hooks.py kallithea/lib/utils2.py |
diffstat | 4 files changed, 10 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/config/post_receive_tmpl.py Wed Aug 08 02:23:11 2018 +0200 +++ b/kallithea/config/post_receive_tmpl.py Wed Aug 08 02:23:11 2018 +0200 @@ -28,7 +28,7 @@ def main(): repo_path = os.path.abspath('.') git_stdin_lines = sys.stdin.readlines() - sys.exit(kallithea.lib.hooks.handle_git_post_receive(repo_path, git_stdin_lines, os.environ)) + sys.exit(kallithea.lib.hooks.handle_git_post_receive(repo_path, git_stdin_lines)) if __name__ == '__main__':
--- a/kallithea/config/pre_receive_tmpl.py Wed Aug 08 02:23:11 2018 +0200 +++ b/kallithea/config/pre_receive_tmpl.py Wed Aug 08 02:23:11 2018 +0200 @@ -28,7 +28,7 @@ def main(): repo_path = os.path.abspath('.') git_stdin_lines = sys.stdin.readlines() - sys.exit(kallithea.lib.hooks.handle_git_pre_receive(repo_path, git_stdin_lines, os.environ)) + sys.exit(kallithea.lib.hooks.handle_git_pre_receive(repo_path, git_stdin_lines)) if __name__ == '__main__':
--- a/kallithea/lib/hooks.py Wed Aug 08 02:23:11 2018 +0200 +++ b/kallithea/lib/hooks.py Wed Aug 08 02:23:11 2018 +0200 @@ -357,7 +357,7 @@ return 0 -def _hook_environment(repo_path, env): +def _hook_environment(repo_path): """ Create a light-weight environment for stand-alone scripts and return an UI and the db repository. @@ -371,7 +371,7 @@ from kallithea.config.environment import load_environment from kallithea.model.base import init_model - extras = _extract_extras(env) + extras = _extract_extras() path, ini_name = os.path.split(extras['config']) conf = appconfig('config:%s' % ini_name, relative_to=path) conf = load_environment(conf.global_conf, conf.local_conf) @@ -395,16 +395,16 @@ return baseui, repo -def handle_git_pre_receive(repo_path, git_stdin_lines, env): +def handle_git_pre_receive(repo_path, git_stdin_lines): """Called from Git pre-receive hook""" - baseui, repo = _hook_environment(repo_path, env) + baseui, repo = _hook_environment(repo_path) scm_repo = repo.scm_instance push_lock_handling(baseui, scm_repo) -def handle_git_post_receive(repo_path, git_stdin_lines, env): +def handle_git_post_receive(repo_path, git_stdin_lines): """Called from Git post-receive hook""" - baseui, repo = _hook_environment(repo_path, env) + baseui, repo = _hook_environment(repo_path) # the post push hook should never use the cached instance scm_repo = repo.scm_instance_no_cache()
--- a/kallithea/lib/utils2.py Wed Aug 08 02:23:11 2018 +0200 +++ b/kallithea/lib/utils2.py Wed Aug 08 02:23:11 2018 +0200 @@ -538,16 +538,13 @@ return req.host_url + req.script_name -def _extract_extras(env=None): +def _extract_extras(): """ Extracts the Kallithea extras data from os.environ, and wraps it into named AttributeDict object """ - if not env: - env = os.environ - try: - extras = json.loads(env['KALLITHEA_EXTRAS']) + extras = json.loads(os.environ['KALLITHEA_EXTRAS']) except KeyError: raise Exception("Environment variable KALLITHEA_EXTRAS not found")