Changeset - d332fca29474
[Not reviewed]
default
3 3 3
Mads Kiilerich (mads) - 5 years ago 2020-10-10 21:05:12
mads@kiilerich.com
Grafted from: 8615cedf87bd
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.
6 files changed with 3 insertions and 9 deletions:
0 comments (0 inline, 0 general)
.coveragerc
Show inline comments
 
[run]
 
omit =
 
    # the bin scripts are not part of the Kallithea web app
 
    kallithea/bin/*
 
    # we ship with no active extensions
 
    kallithea/config/rcextensions/*
 
    # dbmigrate is not a part of the Kallithea web app
 
    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]
 
omit =
 
    # the bin scripts are not part of the Kallithea web app
 
    kallithea/bin/*
 
    # we ship with no active extensions
 
    kallithea/config/rcextensions/*
 
    # dbmigrate is not a part of the Kallithea web app
 
    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 =
 
    kallithea/
 
    **/workspace/*/kallithea
kallithea/bin/kallithea_cli_extensions.py
Show inline comments
 
@@ -18,40 +18,40 @@ Original author and date, and relevant c
 
:author: marcink
 
:copyright: (c) 2013 RhodeCode GmbH, and others.
 
:license: GPLv3, see LICENSE.md for more details.
 
"""
 
import os
 

	
 
import click
 
import pkg_resources
 

	
 
import kallithea
 
import kallithea.bin.kallithea_cli_base as cli_base
 
from kallithea.lib.utils2 import ask_ok
 

	
 

	
 
@cli_base.register_command(needs_config_file=True)
 
def extensions_create():
 
    """Write template file for extending Kallithea in Python.
 

	
 
    Create a template `extensions.py` file next to the ini file. Local
 
    customizations in that file will survive upgrades. The file contains
 
    instructions on how it can be customized.
 
    """
 
    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):
 
        msg = ('Extension file %s already exists, do you want '
 
               'to overwrite it ? [y/n] ') % ext_file
 
        if not ask_ok(msg):
 
            click.echo('Nothing done, exiting...')
 
            return
 

	
 
    dirname = os.path.dirname(ext_file)
 
    if not os.path.isdir(dirname):
 
        os.makedirs(dirname)
 
    with open(ext_file, 'wb') as f:
 
        f.write(content)
 
        click.echo('Wrote new extensions file to %s' % ext_file)
kallithea/model/scm.py
Show inline comments
 
@@ -684,53 +684,53 @@ class ScmModel(object):
 
        """
 
        # Note: sys.executable might not point at a usable Python interpreter. For
 
        # example, when using uwsgi, it will point at the uwsgi program itself.
 
        # FIXME This may not work on Windows and may need a shell wrapper script.
 
        return (kallithea.CONFIG.get('git_hook_interpreter')
 
                or sys.executable
 
                or '/usr/bin/env python3')
 

	
 
    def install_git_hooks(self, repo, force=False):
 
        """
 
        Creates a kallithea hook inside a git repository
 

	
 
        :param repo: Instance of VCS repo
 
        :param force: Overwrite existing non-Kallithea hooks
 
        """
 

	
 
        hooks_path = os.path.join(repo.path, 'hooks')
 
        if not repo.bare:
 
            hooks_path = os.path.join(repo.path, '.git', 'hooks')
 
        if not os.path.isdir(hooks_path):
 
            os.makedirs(hooks_path)
 

	
 
        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)]:
 
            hook_file = os.path.join(hooks_path, '%s-receive' % h_type)
 
            other_hook = False
 
            log.debug('Installing git hook in repo %s', repo)
 
            if os.path.exists(hook_file):
 
                # let's take a look at this hook, maybe it's kallithea ?
 
                log.debug('hook exists, checking if it is from kallithea')
 
                with open(hook_file, 'rb') as f:
 
                    data = f.read()
 
                    matches = re.search(br'^KALLITHEA_HOOK_VER\s*=\s*(.*)$', data, flags=re.MULTILINE)
 
                    if matches:
 
                        ver = matches.groups()[0]
 
                        log.debug('Found Kallithea hook - it has KALLITHEA_HOOK_VER %r', ver)
 
                    else:
 
                        log.debug('Found non-Kallithea hook at %s', hook_file)
 
                        other_hook = True
 

	
 
            if other_hook and not force:
 
                log.warning('skipping overwriting hook file %s', hook_file)
 
            else:
 
                log.debug('writing %s hook file !', h_type)
 
                try:
kallithea/templates/py/extensions.py
Show inline comments
 
file renamed from kallithea/config/extensions/extensions.py to kallithea/templates/py/extensions.py
kallithea/templates/py/git_post_receive_hook.py
Show inline comments
 
file renamed from kallithea/config/post_receive_tmpl.py to kallithea/templates/py/git_post_receive_hook.py
kallithea/templates/py/git_pre_receive_hook.py
Show inline comments
 
file renamed from kallithea/config/pre_receive_tmpl.py to kallithea/templates/py/git_pre_receive_hook.py
0 comments (0 inline, 0 general)