[PATCH PoC] hacks: the concept of python files that will be loaded and can monkeypatch Kallithea internals

Thomas De Schampheleire patrickdepinguin at gmail.com
Tue Apr 21 06:34:43 EDT 2015


On Mon, Apr 20, 2015 at 11:28 PM, Mads Kiilerich <mads at kiilerich.com> wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski at unity3d.com>
> # Date 1429565291 -7200
> #      Mon Apr 20 23:28:11 2015 +0200
> # Node ID fcfd593347c8240544996f5516113595c0ff390a
> # Parent  7e5a0c784880bf8da968710948f3aa617403bf5a
> hacks: the concept of python files that will be loaded and can monkeypatch Kallithea internals
>
> diff --git a/kallithea/config/environment.py b/kallithea/config/environment.py
> --- a/kallithea/config/environment.py
> +++ b/kallithea/config/environment.py
> @@ -16,6 +16,8 @@
>  """
>
>  import os
> +import os.path

Why do you need this import since 'os' is already imported the line above?

> +import imp
>  import logging
>  import kallithea
>  import platform
> @@ -43,12 +45,25 @@ from kallithea.model.scm import ScmModel
>  log = logging.getLogger(__name__)
>
>
> +def load_hacks():
> +    """
> +    Load hacks - python files dropped in kallithea/hacks that will monkeypatch
> +    Kallithea internals
> +    """
> +    hacksdir = os.path.dirname(__file__) + '/../hacks'

This should better be

hacksdir = os.path.join(os.path.dirname(__file__), os.pardir, 'hacks')

> +    if os.path.isdir(hacksdir):
> +        for f in os.listdir(hacksdir):
> +            if not f.startswith('_') and f.endswith('.py'):
> +                _m = imp.load_source('hacks.%s' % f, hacksdir + '/' + f)
> +

_m = imp.load_source('hacks.%s' % f, os.path.join(hacksdir, f))

>  def load_environment(global_conf, app_conf, initial=False,
>                       test_env=None, test_index=None):
>      """
>      Configure the Pylons environment via the ``pylons.config``
>      object
>      """
> +    load_hacks()
> +
>      config = PylonsConfig()
>
>      # Pylons paths
> diff --git a/kallithea/hacks/nogit.py b/kallithea/hacks/nogit.py
> new file mode 100644
> --- /dev/null
> +++ b/kallithea/hacks/nogit.py
> @@ -0,0 +1,5 @@
> +"""
> +disable adding Git repos
> +"""
> +import kallithea
> +kallithea.BACKENDS.pop('git')


Thanks for this patch, looks nice! I will try it out.


More information about the kallithea-general mailing list