Mercurial > kallithea
changeset 8655:e3d8f4bc3ce7
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.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Tue, 06 Oct 2020 20:14:59 +0200 |
parents | 2228102b99ab |
children | 56451a7ca82f |
files | docs/upgrade.rst docs/usage/customization.rst kallithea/bin/kallithea_cli_extensions.py kallithea/config/extensions/extensions.py kallithea/config/rcextensions/__init__.py kallithea/lib/pygmentsutils.py kallithea/lib/utils.py |
diffstat | 7 files changed, 250 insertions(+), 240 deletions(-) [+] |
line wrap: on
line diff
--- a/docs/upgrade.rst Fri Oct 09 13:59:52 2020 +0200 +++ b/docs/upgrade.rst Tue Oct 06 20:14:59 2020 +0200 @@ -39,8 +39,8 @@ 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 ^^^^^^^^^^^^^^^^^^^^^
--- a/docs/usage/customization.rst Fri Oct 09 13:59:52 2020 +0200 +++ b/docs/usage/customization.rst Tue Oct 06 20:14:59 2020 +0200 @@ -39,13 +39,14 @@ .. _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 @@ -55,9 +56,14 @@ 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
--- a/kallithea/bin/kallithea_cli_extensions.py Fri Oct 09 13:59:52 2020 +0200 +++ b/kallithea/bin/kallithea_cli_extensions.py Tue Oct 06 20:14:59 2020 +0200 @@ -33,15 +33,15 @@ 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kallithea/config/extensions/extensions.py Tue Oct 06 20:14:59 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 + """
--- a/kallithea/config/rcextensions/__init__.py Fri Oct 09 13:59:52 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/lib/pygmentsutils.py Fri Oct 09 13:59:52 2020 +0200 +++ b/kallithea/lib/pygmentsutils.py Tue Oct 06 20:14:59 2020 +0200 @@ -69,7 +69,7 @@ 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
--- a/kallithea/lib/utils.py Fri Oct 09 13:59:52 2020 +0200 +++ b/kallithea/lib/utils.py Tue Oct 06 20:14:59 2020 +0200 @@ -522,11 +522,15 @@ 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