changeset 8682:d332fca29474

config: move various py templates to kallithea/templates/py/ For some reason, we had some python templates in kallithea/config . kallithea.config is mainly the TG entry point, and thus a high level controller thing - not a place to store templates. Instead, use the templates directory and introduce a new py subdirectory. With git hook templates in a templates directory, there is no need for tmpl in the name.
author Mads Kiilerich <mads@kiilerich.com>
date Sat, 10 Oct 2020 21:05:12 +0200
parents f66a13a8ab99
children e410c43aec42
files .coveragerc kallithea/bin/kallithea_cli_extensions.py kallithea/config/extensions/extensions.py kallithea/config/post_receive_tmpl.py kallithea/config/pre_receive_tmpl.py kallithea/model/scm.py kallithea/templates/py/extensions.py kallithea/templates/py/git_post_receive_hook.py kallithea/templates/py/git_pre_receive_hook.py
diffstat 9 files changed, 298 insertions(+), 304 deletions(-) [+]
line wrap: on
line diff
--- a/.coveragerc	Sat Oct 10 21:33:42 2020 +0200
+++ b/.coveragerc	Sat Oct 10 21:05:12 2020 +0200
@@ -8,9 +8,6 @@
     kallithea/lib/dbmigrate/*
     # the tests themselves should not be part of the coverage report
     kallithea/tests/*
-    # the scm hooks are not run in the kallithea process
-    kallithea/config/post_receive_tmpl.py
-    kallithea/config/pre_receive_tmpl.py
 
 # same omit lines should be present in sections 'run' and 'report'
 [report]
@@ -23,9 +20,6 @@
     kallithea/lib/dbmigrate/*
     # the tests themselves should not be part of the coverage report
     kallithea/tests/*
-    # the scm hooks are not run in the kallithea process
-    kallithea/config/post_receive_tmpl.py
-    kallithea/config/pre_receive_tmpl.py
 
 [paths]
 source =
--- a/kallithea/bin/kallithea_cli_extensions.py	Sat Oct 10 21:33:42 2020 +0200
+++ b/kallithea/bin/kallithea_cli_extensions.py	Sat Oct 10 21:05:12 2020 +0200
@@ -39,7 +39,7 @@
     """
     here = kallithea.CONFIG['here']
     content = pkg_resources.resource_string(
-        'kallithea', os.path.join('config', 'extensions', 'extensions.py')
+        'kallithea', os.path.join('templates', 'py', 'extensions.py')
     )
     ext_file = os.path.join(here, 'extensions.py')
     if os.path.exists(ext_file):
--- a/kallithea/config/extensions/extensions.py	Sat Oct 10 21:33:42 2020 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,221 +0,0 @@
-# Additional mappings that are not present in the pygments lexers
-# used for building stats
-# format is {'ext':['Names']} eg. {'py':['Python']} note: there can be
-# more than one name for extension
-# NOTE: that this will overide any mappings in LANGUAGES_EXTENSIONS_MAP
-# build by pygments
-EXTRA_MAPPINGS = {}
-
-# additional lexer definitions for custom files
-# it's overrides pygments lexers, and uses defined name of lexer to colorize the
-# files. Format is {'ext': 'lexer_name'}
-# List of lexers can be printed running:
-# python -c "import pprint;from pygments import lexers;pprint.pprint([(x[0], x[1]) for x in lexers.get_all_lexers()]);"
-
-EXTRA_LEXERS = {}
-
-#==============================================================================
-# WHOOSH INDEX EXTENSIONS
-#==============================================================================
-# if INDEX_EXTENSIONS is [] it'll use pygments lexers extensions by default.
-# To set your own just add to this list extensions to index with content
-INDEX_EXTENSIONS = []
-
-# additional extensions for indexing besides the default from pygments
-# those gets added to INDEX_EXTENSIONS
-EXTRA_INDEX_EXTENSIONS = []
-
-
-#==============================================================================
-# POST CREATE REPOSITORY HOOK
-#==============================================================================
-# this function will be executed after each repository is created
-def CREATE_REPO_HOOK(*args, **kwargs):
-    """
-    Post create repository HOOK
-    kwargs available:
-     :param repo_name:
-     :param repo_type:
-     :param description:
-     :param private:
-     :param created_on:
-     :param enable_downloads:
-     :param repo_id:
-     :param owner_id:
-     :param enable_statistics:
-     :param clone_uri:
-     :param fork_id:
-     :param group_id:
-     :param created_by:
-    """
-
-
-#==============================================================================
-# PRE CREATE USER HOOK
-#==============================================================================
-# this function will be executed before each user is created
-def PRE_CREATE_USER_HOOK(*args, **kwargs):
-    """
-    Pre create user HOOK, it returns a tuple of bool, reason.
-    If bool is False the user creation will be stopped and reason
-    will be displayed to the user.
-    kwargs available:
-    :param username:
-    :param password:
-    :param email:
-    :param firstname:
-    :param lastname:
-    :param active:
-    :param admin:
-    :param created_by:
-    """
-    reason = 'allowed'
-    return True, reason
-
-
-#==============================================================================
-# POST CREATE USER HOOK
-#==============================================================================
-# this function will be executed after each user is created
-def CREATE_USER_HOOK(*args, **kwargs):
-    """
-    Post create user HOOK
-    kwargs available:
-      :param username:
-      :param full_name_or_username:
-      :param full_contact:
-      :param user_id:
-      :param name:
-      :param firstname:
-      :param short_contact:
-      :param admin:
-      :param lastname:
-      :param ip_addresses:
-      :param ldap_dn:
-      :param email:
-      :param api_key:
-      :param last_login:
-      :param full_name:
-      :param active:
-      :param password:
-      :param emails:
-      :param created_by:
-    """
-
-
-#==============================================================================
-# POST CREATE PULLREQUEST HOOK
-#==============================================================================
-# this function will be executed after a pull request is created
-def CREATE_PULLREQUEST_HOOK(*args, **kwargs):
-    """
-    Post create pull request HOOK
-    kwargs available:
-      :param pull_request_id:
-      :param title:
-      :param description:
-      :param created_on:
-      :param org_repo_id:
-      :param org_ref:
-      :param other_repo_id:
-      :param other_ref:
-      :param created_by:
-    There are other fields in 'class PullRequest' (kallithea/model/db.py) which
-    may or may not be useful for this hook.
-    """
-
-
-#==============================================================================
-# POST DELETE REPOSITORY HOOK
-#==============================================================================
-# this function will be executed after each repository deletion
-def DELETE_REPO_HOOK(*args, **kwargs):
-    """
-    Post delete repository HOOK
-    kwargs available:
-     :param repo_name:
-     :param repo_type:
-     :param description:
-     :param private:
-     :param created_on:
-     :param enable_downloads:
-     :param repo_id:
-     :param owner_id:
-     :param enable_statistics:
-     :param clone_uri:
-     :param fork_id:
-     :param group_id:
-     :param deleted_by:
-     :param deleted_on:
-    """
-
-
-#==============================================================================
-# POST DELETE USER HOOK
-#==============================================================================
-# this function will be executed after each user is deleted
-def DELETE_USER_HOOK(*args, **kwargs):
-    """
-    Post delete user HOOK
-    kwargs available:
-      :param username:
-      :param full_name_or_username:
-      :param full_contact:
-      :param user_id:
-      :param name:
-      :param firstname:
-      :param short_contact:
-      :param admin:
-      :param lastname:
-      :param ip_addresses:
-      :param ldap_dn:
-      :param email:
-      :param api_key:
-      :param last_login:
-      :param full_name:
-      :param active:
-      :param password:
-      :param emails:
-      :param deleted_by:
-    """
-
-
-#==============================================================================
-# POST PUSH HOOK
-#==============================================================================
-
-# this function will be executed after each push it's executed after the
-# build-in hook that Kallithea uses for logging pushes
-def PUSH_HOOK(*args, **kwargs):
-    """
-    Post push hook
-    kwargs available:
-
-      :param config: path to .ini config used
-      :param scm: type of VS 'git' or 'hg'
-      :param username: name of user who pushed
-      :param ip: ip of who pushed
-      :param action: push
-      :param repository: repository name
-      :param pushed_revs: list of pushed revisions
-    """
-
-
-#==============================================================================
-# POST PULL HOOK
-#==============================================================================
-
-# this function will be executed after each push it's executed after the
-# build-in hook that Kallithea uses for logging pulls
-def PULL_HOOK(*args, **kwargs):
-    """
-    Post pull hook
-    kwargs available::
-
-      :param config: path to .ini config used
-      :param scm: type of VS 'git' or 'hg'
-      :param username: name of user who pulled
-      :param ip: ip of who pulled
-      :param action: pull
-      :param repository: repository name
-    """
--- a/kallithea/config/post_receive_tmpl.py	Sat Oct 10 21:33:42 2020 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-"""Kallithea Git hook
-
-This hook is installed and maintained by Kallithea. It will be overwritten
-by Kallithea - don't customize it manually!
-
-When Kallithea invokes Git, the KALLITHEA_EXTRAS environment variable will
-contain additional info like the Kallithea instance and user info that this
-hook will use.
-"""
-
-import os
-import sys
-
-import kallithea.lib.hooks
-
-
-# Set output mode on windows to binary for stderr.
-# This prevents python (or the windows console) from replacing \n with \r\n.
-# Git doesn't display remote output lines that contain \r,
-# and therefore without this modification git would display empty lines
-# instead of the exception output.
-if sys.platform == "win32":
-    import msvcrt
-    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
-
-KALLITHEA_HOOK_VER = '_TMPL_'
-os.environ['KALLITHEA_HOOK_VER'] = KALLITHEA_HOOK_VER
-
-
-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))
-
-
-if __name__ == '__main__':
-    main()
--- a/kallithea/config/pre_receive_tmpl.py	Sat Oct 10 21:33:42 2020 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-"""Kallithea Git hook
-
-This hook is installed and maintained by Kallithea. It will be overwritten
-by Kallithea - don't customize it manually!
-
-When Kallithea invokes Git, the KALLITHEA_EXTRAS environment variable will
-contain additional info like the Kallithea instance and user info that this
-hook will use.
-"""
-
-import os
-import sys
-
-import kallithea.lib.hooks
-
-
-# Set output mode on windows to binary for stderr.
-# This prevents python (or the windows console) from replacing \n with \r\n.
-# Git doesn't display remote output lines that contain \r,
-# and therefore without this modification git would display empty lines
-# instead of the exception output.
-if sys.platform == "win32":
-    import msvcrt
-    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
-
-KALLITHEA_HOOK_VER = '_TMPL_'
-os.environ['KALLITHEA_HOOK_VER'] = KALLITHEA_HOOK_VER
-
-
-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))
-
-
-if __name__ == '__main__':
-    main()
--- a/kallithea/model/scm.py	Sat Oct 10 21:33:42 2020 +0200
+++ b/kallithea/model/scm.py	Sat Oct 10 21:05:12 2020 +0200
@@ -705,11 +705,11 @@
 
         tmpl_post = b"#!%s\n" % safe_bytes(self._get_git_hook_interpreter())
         tmpl_post += pkg_resources.resource_string(
-            'kallithea', os.path.join('config', 'post_receive_tmpl.py')
+            'kallithea', os.path.join('templates', 'py', 'git_post_receive_hook.py')
         )
         tmpl_pre = b"#!%s\n" % safe_bytes(self._get_git_hook_interpreter())
         tmpl_pre += pkg_resources.resource_string(
-            'kallithea', os.path.join('config', 'pre_receive_tmpl.py')
+            'kallithea', os.path.join('templates', 'py', 'git_pre_receive_hook.py')
         )
 
         for h_type, tmpl in [('pre', tmpl_pre), ('post', tmpl_post)]:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kallithea/templates/py/extensions.py	Sat Oct 10 21:05:12 2020 +0200
@@ -0,0 +1,221 @@
+# Additional mappings that are not present in the pygments lexers
+# used for building stats
+# format is {'ext':['Names']} eg. {'py':['Python']} note: there can be
+# more than one name for extension
+# NOTE: that this will overide any mappings in LANGUAGES_EXTENSIONS_MAP
+# build by pygments
+EXTRA_MAPPINGS = {}
+
+# additional lexer definitions for custom files
+# it's overrides pygments lexers, and uses defined name of lexer to colorize the
+# files. Format is {'ext': 'lexer_name'}
+# List of lexers can be printed running:
+# python -c "import pprint;from pygments import lexers;pprint.pprint([(x[0], x[1]) for x in lexers.get_all_lexers()]);"
+
+EXTRA_LEXERS = {}
+
+#==============================================================================
+# WHOOSH INDEX EXTENSIONS
+#==============================================================================
+# if INDEX_EXTENSIONS is [] it'll use pygments lexers extensions by default.
+# To set your own just add to this list extensions to index with content
+INDEX_EXTENSIONS = []
+
+# additional extensions for indexing besides the default from pygments
+# those gets added to INDEX_EXTENSIONS
+EXTRA_INDEX_EXTENSIONS = []
+
+
+#==============================================================================
+# POST CREATE REPOSITORY HOOK
+#==============================================================================
+# this function will be executed after each repository is created
+def CREATE_REPO_HOOK(*args, **kwargs):
+    """
+    Post create repository HOOK
+    kwargs available:
+     :param repo_name:
+     :param repo_type:
+     :param description:
+     :param private:
+     :param created_on:
+     :param enable_downloads:
+     :param repo_id:
+     :param owner_id:
+     :param enable_statistics:
+     :param clone_uri:
+     :param fork_id:
+     :param group_id:
+     :param created_by:
+    """
+
+
+#==============================================================================
+# PRE CREATE USER HOOK
+#==============================================================================
+# this function will be executed before each user is created
+def PRE_CREATE_USER_HOOK(*args, **kwargs):
+    """
+    Pre create user HOOK, it returns a tuple of bool, reason.
+    If bool is False the user creation will be stopped and reason
+    will be displayed to the user.
+    kwargs available:
+    :param username:
+    :param password:
+    :param email:
+    :param firstname:
+    :param lastname:
+    :param active:
+    :param admin:
+    :param created_by:
+    """
+    reason = 'allowed'
+    return True, reason
+
+
+#==============================================================================
+# POST CREATE USER HOOK
+#==============================================================================
+# this function will be executed after each user is created
+def CREATE_USER_HOOK(*args, **kwargs):
+    """
+    Post create user HOOK
+    kwargs available:
+      :param username:
+      :param full_name_or_username:
+      :param full_contact:
+      :param user_id:
+      :param name:
+      :param firstname:
+      :param short_contact:
+      :param admin:
+      :param lastname:
+      :param ip_addresses:
+      :param ldap_dn:
+      :param email:
+      :param api_key:
+      :param last_login:
+      :param full_name:
+      :param active:
+      :param password:
+      :param emails:
+      :param created_by:
+    """
+
+
+#==============================================================================
+# POST CREATE PULLREQUEST HOOK
+#==============================================================================
+# this function will be executed after a pull request is created
+def CREATE_PULLREQUEST_HOOK(*args, **kwargs):
+    """
+    Post create pull request HOOK
+    kwargs available:
+      :param pull_request_id:
+      :param title:
+      :param description:
+      :param created_on:
+      :param org_repo_id:
+      :param org_ref:
+      :param other_repo_id:
+      :param other_ref:
+      :param created_by:
+    There are other fields in 'class PullRequest' (kallithea/model/db.py) which
+    may or may not be useful for this hook.
+    """
+
+
+#==============================================================================
+# POST DELETE REPOSITORY HOOK
+#==============================================================================
+# this function will be executed after each repository deletion
+def DELETE_REPO_HOOK(*args, **kwargs):
+    """
+    Post delete repository HOOK
+    kwargs available:
+     :param repo_name:
+     :param repo_type:
+     :param description:
+     :param private:
+     :param created_on:
+     :param enable_downloads:
+     :param repo_id:
+     :param owner_id:
+     :param enable_statistics:
+     :param clone_uri:
+     :param fork_id:
+     :param group_id:
+     :param deleted_by:
+     :param deleted_on:
+    """
+
+
+#==============================================================================
+# POST DELETE USER HOOK
+#==============================================================================
+# this function will be executed after each user is deleted
+def DELETE_USER_HOOK(*args, **kwargs):
+    """
+    Post delete user HOOK
+    kwargs available:
+      :param username:
+      :param full_name_or_username:
+      :param full_contact:
+      :param user_id:
+      :param name:
+      :param firstname:
+      :param short_contact:
+      :param admin:
+      :param lastname:
+      :param ip_addresses:
+      :param ldap_dn:
+      :param email:
+      :param api_key:
+      :param last_login:
+      :param full_name:
+      :param active:
+      :param password:
+      :param emails:
+      :param deleted_by:
+    """
+
+
+#==============================================================================
+# POST PUSH HOOK
+#==============================================================================
+
+# this function will be executed after each push it's executed after the
+# build-in hook that Kallithea uses for logging pushes
+def PUSH_HOOK(*args, **kwargs):
+    """
+    Post push hook
+    kwargs available:
+
+      :param config: path to .ini config used
+      :param scm: type of VS 'git' or 'hg'
+      :param username: name of user who pushed
+      :param ip: ip of who pushed
+      :param action: push
+      :param repository: repository name
+      :param pushed_revs: list of pushed revisions
+    """
+
+
+#==============================================================================
+# POST PULL HOOK
+#==============================================================================
+
+# this function will be executed after each push it's executed after the
+# build-in hook that Kallithea uses for logging pulls
+def PULL_HOOK(*args, **kwargs):
+    """
+    Post pull hook
+    kwargs available::
+
+      :param config: path to .ini config used
+      :param scm: type of VS 'git' or 'hg'
+      :param username: name of user who pulled
+      :param ip: ip of who pulled
+      :param action: pull
+      :param repository: repository name
+    """
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kallithea/templates/py/git_post_receive_hook.py	Sat Oct 10 21:05:12 2020 +0200
@@ -0,0 +1,37 @@
+"""Kallithea Git hook
+
+This hook is installed and maintained by Kallithea. It will be overwritten
+by Kallithea - don't customize it manually!
+
+When Kallithea invokes Git, the KALLITHEA_EXTRAS environment variable will
+contain additional info like the Kallithea instance and user info that this
+hook will use.
+"""
+
+import os
+import sys
+
+import kallithea.lib.hooks
+
+
+# Set output mode on windows to binary for stderr.
+# This prevents python (or the windows console) from replacing \n with \r\n.
+# Git doesn't display remote output lines that contain \r,
+# and therefore without this modification git would display empty lines
+# instead of the exception output.
+if sys.platform == "win32":
+    import msvcrt
+    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
+
+KALLITHEA_HOOK_VER = '_TMPL_'
+os.environ['KALLITHEA_HOOK_VER'] = KALLITHEA_HOOK_VER
+
+
+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))
+
+
+if __name__ == '__main__':
+    main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kallithea/templates/py/git_pre_receive_hook.py	Sat Oct 10 21:05:12 2020 +0200
@@ -0,0 +1,37 @@
+"""Kallithea Git hook
+
+This hook is installed and maintained by Kallithea. It will be overwritten
+by Kallithea - don't customize it manually!
+
+When Kallithea invokes Git, the KALLITHEA_EXTRAS environment variable will
+contain additional info like the Kallithea instance and user info that this
+hook will use.
+"""
+
+import os
+import sys
+
+import kallithea.lib.hooks
+
+
+# Set output mode on windows to binary for stderr.
+# This prevents python (or the windows console) from replacing \n with \r\n.
+# Git doesn't display remote output lines that contain \r,
+# and therefore without this modification git would display empty lines
+# instead of the exception output.
+if sys.platform == "win32":
+    import msvcrt
+    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
+
+KALLITHEA_HOOK_VER = '_TMPL_'
+os.environ['KALLITHEA_HOOK_VER'] = KALLITHEA_HOOK_VER
+
+
+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))
+
+
+if __name__ == '__main__':
+    main()