Changeset - e3d8f4bc3ce7
[Not reviewed]
default
1 5 1
Thomas De Schampheleire - 5 years ago 2020-10-06 20:14:59
thomas.de_schampheleire@nokia.com
extensions: rename 'rcextensions' into 'extensions' but provide compatibility

The 'rc' prefix is legacy.
Rename 'rcextensions' into 'extensions', updating all references.
Compatibility with the old name will be retained for a while, and removed in
a later release. Migrating is as simple as renaming a file.
6 files changed with 29 insertions and 19 deletions:
0 comments (0 inline, 0 general)
docs/upgrade.rst
Show inline comments
 
@@ -30,26 +30,26 @@ the upgrade.
 
2. Create a backup of both database and configuration
 
-----------------------------------------------------
 

	
 
You are of course strongly recommended to make backups regularly, but it
 
is *especially* important to make a full database and configuration
 
backup before performing a Kallithea upgrade.
 

	
 
Back up your configuration
 
^^^^^^^^^^^^^^^^^^^^^^^^^^
 

	
 
Make a copy of your Kallithea configuration (``.ini``) file.
 

	
 
If you are using :ref:`rcextensions <customization>`, you should also
 
make a copy of the entire ``rcextensions`` directory.
 
If you are using custom :ref:`extensions <customization>`, you should also
 
make a copy of the ``extensions.py`` file.
 

	
 
Back up your database
 
^^^^^^^^^^^^^^^^^^^^^
 

	
 
If using SQLite, simply make a copy of the Kallithea database (``.db``)
 
file.
 

	
 
If using PostgreSQL, please consult the documentation for the ``pg_dump``
 
utility.
 

	
 
If using MariaDB/MySQL, please consult the documentation for the ``mysqldump``
 
utility.
docs/usage/customization.rst
Show inline comments
 
@@ -30,42 +30,48 @@ file to override the default style. For 
 
variables`_.
 

	
 
After creating the ``theme.less`` file, you need to regenerate the CSS files, by
 
running::
 

	
 
    kallithea-cli front-end-build --no-install-deps
 

	
 
.. _bootstrap 3: https://getbootstrap.com/docs/3.3/
 
.. _bootstrap variables: https://getbootstrap.com/docs/3.3/customize/#less-variables
 
.. _less: http://lesscss.org/
 

	
 

	
 
Behavioral customization: rcextensions
 
--------------------------------------
 
Behavioral customization: Kallithea extensions
 
----------------------------------------------
 

	
 
Some behavioral customization can be done in Python using ``rcextensions``, a
 
custom Python package that can extend Kallithea functionality.
 
Some behavioral customization can be done in Python using Kallithea
 
``extensions``, a custom Python file you can create to extend Kallithea
 
functionality.
 

	
 
With ``rcextensions`` it's possible to add additional mappings for Whoosh
 
With ``extensions`` it's possible to add additional mappings for Whoosh
 
indexing and statistics, to add additional code into the push/pull/create/delete
 
repository hooks (for example to send signals to build bots such as Jenkins) and
 
even to monkey-patch certain parts of the Kallithea source code (for example
 
overwrite an entire function, change a global variable, ...).
 

	
 
To generate a skeleton extensions package, run::
 

	
 
    kallithea-cli extensions-create -c my.ini
 

	
 
This will create an ``rcextensions`` package next to the specified ``ini`` file.
 
See the ``__init__.py`` file inside the generated ``rcextensions`` package
 
for more details.
 
This will create an ``extensions.py`` file next to the specified ``ini`` file.
 
You can find more details inside this file.
 

	
 
For compatibility with previous releases of Kallithea, a directory named
 
``rcextensions`` with a file ``__init__.py`` inside of it can also be used. If
 
both an ``extensions.py`` file and an ``rcextensions`` directory are found, only
 
``extensions.py`` will be loaded. Note that the name ``rcextensions`` is
 
deprecated and support for it will be removed in a future release.
 

	
 

	
 
Behavioral customization: code changes
 
--------------------------------------
 

	
 
As Kallithea is open-source software, you can make any changes you like directly
 
in the source code.
 

	
 
We encourage you to send generic improvements back to the
 
community so that Kallithea can become better. See :ref:`contributing` for more
 
details.
kallithea/bin/kallithea_cli_extensions.py
Show inline comments
 
@@ -24,33 +24,33 @@ 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.
 

	
 
    An rcextensions directory with a __init__.py file will be created next to
 
    the ini file. Local customizations in that file will survive upgrades.
 
    The file contains instructions on how it can be customized.
 
    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', 'rcextensions', '__init__.py')
 
        'kallithea', os.path.join('config', 'extensions', 'extensions.py')
 
    )
 
    ext_file = os.path.join(here, 'rcextensions', '__init__.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)
kallithea/config/extensions/extensions.py
Show inline comments
 
file renamed from kallithea/config/rcextensions/__init__.py to kallithea/config/extensions/extensions.py
kallithea/lib/pygmentsutils.py
Show inline comments
 
@@ -60,20 +60,20 @@ def get_index_filenames():
 
    """
 
    filenames = []
 
    for lx, t in sorted(lexers.LEXERS.items()):
 
        for f in t[-2]:
 
            if '*' not in f and '[' not in f:
 
                filenames.append(f)
 

	
 
    return filenames
 

	
 

	
 
def get_custom_lexer(extension):
 
    """
 
    returns a custom lexer if it's defined in rcextensions module, or None
 
    returns a custom lexer if it's defined in the extensions module, or None
 
    if there's no custom lexer defined
 
    """
 
    import kallithea
 
    lexer_name = getattr(kallithea.EXTENSIONS, 'EXTRA_LEXERS', {}).get(extension)
 
    if lexer_name is None:
 
        return None
 
    return lexers.get_lexer_by_name(lexer_name)
kallithea/lib/utils.py
Show inline comments
 
@@ -513,29 +513,33 @@ def repo2db_mapper(initial_repo_dict, re
 
                    RepoModel().delete(repo, forks='detach', fs_remove=False)
 
                    sa.commit()
 
                except Exception:
 
                    #don't hold further removals on error
 
                    log.error(traceback.format_exc())
 
                    sa.rollback()
 
            removed.append(repo.repo_name)
 
    return added, removed
 

	
 

	
 
def load_extensions(root_path):
 
    try:
 
        ext = create_module('rc', os.path.join(root_path, 'rcextensions', '__init__.py'))
 
        ext = create_module('extensions', os.path.join(root_path, 'extensions.py'))
 
    except FileNotFoundError:
 
        return
 
        try:
 
            ext = create_module('rc', os.path.join(root_path, 'rcextensions', '__init__.py'))
 
            log.warning('The name "rcextensions" is deprecated. Please use a file `extensions.py` instead of a directory `rcextensions`.')
 
        except FileNotFoundError:
 
            return
 

	
 
    log.info('Loaded rcextensions from %s', ext)
 
    log.info('Loaded Kallithea extensions from %s', ext)
 
    kallithea.EXTENSIONS = ext
 

	
 
    # Additional mappings that are not present in the pygments lexers
 
    kallithea.config.conf.LANGUAGES_EXTENSIONS_MAP.update(getattr(ext, 'EXTRA_MAPPINGS', {}))
 

	
 
    # Override any INDEX_EXTENSIONS
 
    if getattr(ext, 'INDEX_EXTENSIONS', []):
 
        log.debug('settings custom INDEX_EXTENSIONS')
 
        kallithea.config.conf.INDEX_EXTENSIONS = getattr(ext, 'INDEX_EXTENSIONS', [])
 

	
 
    # Additional INDEX_EXTENSIONS
 
    log.debug('adding extra into INDEX_EXTENSIONS')
0 comments (0 inline, 0 general)