Changeset - bb1154b80789
[Not reviewed]
default
0 2 0
Mads Kiilerich - 6 years ago 2019-07-21 23:26:24
mads@kiilerich.com
Grafted from: 151e2ec7319d
refactor: use string methods instead of class functions and map

Python 3 has no lower or strip functions - only string methods.
2 files changed with 3 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/bin/kallithea_cli_index.py
Show inline comments
 
@@ -14,49 +14,48 @@
 
"""
 
This file was forked by the Kallithea project in July 2014 and later moved.
 
Original author and date, and relevant copyright and licensing information is below:
 
:created_on: Aug 17, 2010
 
:author: marcink
 
:copyright: (c) 2013 RhodeCode GmbH, and others.
 
:license: GPLv3, see LICENSE.md for more details.
 
"""
 
import click
 
import kallithea.bin.kallithea_cli_base as cli_base
 

	
 
import os
 
from string import strip
 
import sys
 

	
 
import kallithea
 
from kallithea.lib.indexers.daemon import WhooshIndexingDaemon
 
from kallithea.lib.pidlock import LockHeld, DaemonLock
 
from kallithea.lib.utils import load_rcextensions
 
from kallithea.model.repo import RepoModel
 

	
 
@cli_base.register_command(config_file_initialize_app=True)
 
@click.option('--repo-location', help='Base path of repositories to index. Default: all')
 
@click.option('--index-only', help='Comma-separated list of repositories to build index on. Default: all')
 
@click.option('--update-only', help='Comma-separated list of repositories to re-build index on. Default: all')
 
@click.option('-f', '--full', 'full_index', help='Recreate the index from scratch')
 
def index_create(repo_location, index_only, update_only, full_index):
 
    """Create or update full text search index"""
 

	
 
    index_location = kallithea.CONFIG['index_dir']
 
    load_rcextensions(kallithea.CONFIG['here'])
 

	
 
    if not repo_location:
 
        repo_location = RepoModel().repos_path
 
    repo_list = map(strip, index_only.split(',')) \
 
    repo_list = [x.strip() for x in index_only.split(',')] \
 
        if index_only else None
 
    repo_update_list = map(strip, update_only.split(',')) \
 
    repo_update_list = [x.strip() for x in update_only.split(',')] \
 
        if update_only else None
 

	
 
    try:
 
        l = DaemonLock(os.path.join(index_location, 'make_index.lock'))
 
        WhooshIndexingDaemon(index_location=index_location,
 
                             repo_location=repo_location,
 
                             repo_list=repo_list,
 
                             repo_update_list=repo_update_list) \
 
            .run(full_index=full_index)
 
        l.release()
 
    except LockHeld:
 
        sys.exit(1)
kallithea/lib/celerylib/tasks.py
Show inline comments
 
@@ -25,25 +25,24 @@ Original author and date, and relevant c
 
:copyright: (c) 2013 RhodeCode GmbH, and others.
 
:license: GPLv3, see LICENSE.md for more details.
 
"""
 

	
 
import os
 
import traceback
 
import logging
 
import rfc822
 

	
 
from collections import OrderedDict
 
from time import mktime
 
from operator import itemgetter
 
from string import lower
 

	
 
from tg import config
 

	
 
from kallithea import CELERY_ON
 
from kallithea.lib import celerylib
 
from kallithea.lib.helpers import person
 
from kallithea.lib.rcmail.smtp_mailer import SmtpMailer
 
from kallithea.lib.utils import action_logger
 
from kallithea.lib.utils2 import str2bool
 
from kallithea.lib.vcs.utils import author_email
 
from kallithea.lib.compat import json
 
from kallithea.lib.hooks import log_create_repository
 
@@ -482,22 +481,22 @@ def create_repo_fork(form_data, cur_user
 
    return True
 

	
 

	
 
def __get_codes_stats(repo_name):
 
    from kallithea.config.conf import LANGUAGES_EXTENSIONS_MAP
 
    repo = Repository.get_by_repo_name(repo_name).scm_instance
 

	
 
    tip = repo.get_changeset()
 
    code_stats = {}
 

	
 
    def aggregate(cs):
 
        for f in cs[2]:
 
            ext = lower(f.extension)
 
            ext = f.extension.lower()
 
            if ext in LANGUAGES_EXTENSIONS_MAP.keys() and not f.is_binary:
 
                if ext in code_stats:
 
                    code_stats[ext] += 1
 
                else:
 
                    code_stats[ext] = 1
 

	
 
    map(aggregate, tip.walk('/'))
 

	
 
    return code_stats or {}
0 comments (0 inline, 0 general)