Changeset - 2228102b99ab
[Not reviewed]
default
0 1 0
Thomas De Schampheleire - 5 years ago 2020-10-09 13:59:52
thomas.de_schampheleire@nokia.com
extensions: preparatory refactoring

Small refactoring:

- use 'try..except' rather than 'if-then', which removes the need for a
separate 'path' variable and is more 'pythonic'.
- promote log from 'debug' to 'info' and execute it immediately after
loading before anything else.
- clarify comments related to INDEX_EXTENSIONS
1 file changed with 15 insertions and 14 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/utils.py
Show inline comments
 
@@ -521,24 +521,25 @@ def repo2db_mapper(initial_repo_dict, re
 

	
 

	
 
def load_extensions(root_path):
 
    path = os.path.join(root_path, 'rcextensions', '__init__.py')
 
    if os.path.isfile(path):
 
        ext = create_module('rc', path)
 
        kallithea.EXTENSIONS = ext
 
        log.debug('Found rcextensions now loading %s...', ext)
 
    try:
 
        ext = create_module('rc', os.path.join(root_path, 'rcextensions', '__init__.py'))
 
    except FileNotFoundError:
 
        return
 

	
 
        # Additional mappings that are not present in the pygments lexers
 
        kallithea.config.conf.LANGUAGES_EXTENSIONS_MAP.update(getattr(ext, 'EXTRA_MAPPINGS', {}))
 
    log.info('Loaded rcextensions from %s', ext)
 
    kallithea.EXTENSIONS = ext
 

	
 
        # OVERRIDE OUR EXTENSIONS FROM RC-EXTENSIONS (if present)
 
    # Additional mappings that are not present in the pygments lexers
 
    kallithea.config.conf.LANGUAGES_EXTENSIONS_MAP.update(getattr(ext, 'EXTRA_MAPPINGS', {}))
 

	
 
        if getattr(ext, 'INDEX_EXTENSIONS', []):
 
            log.debug('settings custom INDEX_EXTENSIONS')
 
            kallithea.config.conf.INDEX_EXTENSIONS = getattr(ext, 'INDEX_EXTENSIONS', [])
 
    # 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 MAPPINGS
 
        log.debug('adding extra into INDEX_EXTENSIONS')
 
        kallithea.config.conf.INDEX_EXTENSIONS.extend(getattr(ext, 'EXTRA_INDEX_EXTENSIONS', []))
 
    # Additional INDEX_EXTENSIONS
 
    log.debug('adding extra into INDEX_EXTENSIONS')
 
    kallithea.config.conf.INDEX_EXTENSIONS.extend(getattr(ext, 'EXTRA_INDEX_EXTENSIONS', []))
 

	
 

	
 
#==============================================================================
0 comments (0 inline, 0 general)