Changeset - a42bfe8a9335
[Not reviewed]
beta
0 11 0
Marcin Kuzminski - 12 years ago 2013-05-30 00:01:16
marcin@python-works.com
moved make-index command to paster_commands module

- optimized imports and code
11 files changed with 38 insertions and 129 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/changelog.py
Show inline comments
 
@@ -132,7 +132,7 @@ class ChangelogController(BaseRepoContro
 
            c.total_cs = len(collection)
 

	
 
            c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
 
                                    items_per_page=c.size, branch=branch_name)
 
                                    items_per_page=c.size, branch=branch_name,)
 
            collection = list(c.pagination)
 
            page_revisions = [x.raw_id for x in c.pagination]
 
            c.comments = c.rhodecode_db_repo.get_comments(page_revisions)
rhodecode/lib/helpers.py
Show inline comments
 
@@ -900,13 +900,15 @@ class Page(_Page):
 
        if self.page != self.last_page and rightmost_page < self.last_page:
 
            nav_items.append(self._pagerlink(self.last_page, self.last_page))
 

	
 
        ## prerender links
 
        nav_items.append(literal('<link rel="prerender" href="/rhodecode/changelog/1?page=%s">' % str(int(self.page)+1)))
 
        return self.separator.join(nav_items)
 

	
 
    def pager(self, format='~2~', page_param='page', partial_param='partial',
 
        show_if_single_page=False, separator=' ', onclick=None,
 
        symbol_first='<<', symbol_last='>>',
 
        symbol_previous='<', symbol_next='>',
 
        link_attr={'class': 'pager_link'},
 
        link_attr={'class': 'pager_link', 'rel': 'prerender'},
 
        curpage_attr={'class': 'pager_curpage'},
 
        dotdot_attr={'class': 'pager_dotdot'}, **kwargs):
 

	
rhodecode/lib/indexers/__init__.py
Show inline comments
 
@@ -24,32 +24,17 @@
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
import os
 
import sys
 
import traceback
 
import logging
 
from os.path import dirname as dn, join as jn
 

	
 
#to get the rhodecode import
 
sys.path.append(dn(dn(dn(os.path.realpath(__file__)))))
 

	
 
from string import strip
 
from shutil import rmtree
 

	
 
from whoosh.analysis import RegexTokenizer, LowercaseFilter, StopFilter
 
from whoosh.fields import TEXT, ID, STORED, NUMERIC, BOOLEAN, Schema, FieldType, DATETIME
 
from whoosh.index import create_in, open_dir
 
from whoosh.formats import Characters
 
from whoosh.highlight import highlight, HtmlFormatter, ContextFragmenter
 

	
 
from webhelpers.html.builder import escape, literal
 
from sqlalchemy import engine_from_config
 

	
 
from rhodecode.model import init_model
 
from rhodecode.model.scm import ScmModel
 
from rhodecode.model.repo import RepoModel
 
from rhodecode.config.environment import load_environment
 
from whoosh.highlight import highlight as whoosh_highlight, HtmlFormatter, ContextFragmenter
 
from rhodecode.lib.utils2 import LazyProperty
 
from rhodecode.lib.utils import BasePasterCommand, Command, add_cache,\
 
    load_rcextensions
 

	
 
log = logging.getLogger(__name__)
 

	
 
@@ -99,74 +84,6 @@ JOURNAL_SCHEMA = Schema(
 
)
 

	
 

	
 
class MakeIndex(BasePasterCommand):
 

	
 
    max_args = 1
 
    min_args = 1
 

	
 
    usage = "CONFIG_FILE"
 
    summary = "Creates or update full text search index"
 
    group_name = "RhodeCode"
 
    takes_config_file = -1
 
    parser = Command.standard_parser(verbose=True)
 

	
 
    def command(self):
 
        logging.config.fileConfig(self.path_to_ini_file)
 
        from pylons import config
 
        add_cache(config)
 
        engine = engine_from_config(config, 'sqlalchemy.db1.')
 
        init_model(engine)
 
        index_location = config['index_dir']
 
        repo_location = self.options.repo_location \
 
            if self.options.repo_location else RepoModel().repos_path
 
        repo_list = map(strip, self.options.repo_list.split(',')) \
 
            if self.options.repo_list else None
 
        repo_update_list = map(strip, self.options.repo_update_list.split(',')) \
 
            if self.options.repo_update_list else None
 
        load_rcextensions(config['here'])
 
        #======================================================================
 
        # WHOOSH DAEMON
 
        #======================================================================
 
        from rhodecode.lib.pidlock import LockHeld, DaemonLock
 
        from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon
 
        try:
 
            l = DaemonLock(file_=jn(dn(dn(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=self.options.full_index)
 
            l.release()
 
        except LockHeld:
 
            sys.exit(1)
 

	
 
    def update_parser(self):
 
        self.parser.add_option('--repo-location',
 
                          action='store',
 
                          dest='repo_location',
 
                          help="Specifies repositories location to index OPTIONAL",
 
                          )
 
        self.parser.add_option('--index-only',
 
                          action='store',
 
                          dest='repo_list',
 
                          help="Specifies a comma separated list of repositores "
 
                                "to build index on. If not given all repositories "
 
                                "are scanned for indexing. OPTIONAL",
 
                          )
 
        self.parser.add_option('--update-only',
 
                          action='store',
 
                          dest='repo_update_list',
 
                          help="Specifies a comma separated list of repositores "
 
                                "to re-build index on. OPTIONAL",
 
                          )
 
        self.parser.add_option('-f',
 
                          action='store_true',
 
                          dest='full_index',
 
                          help="Specifies that index should be made full i.e"
 
                                " destroy old and build from scratch",
 
                          default=False)
 

	
 

	
 
class WhooshResultWrapper(object):
 
    def __init__(self, search_type, searcher, matcher, highlight_items,
 
                 repo_location):
 
@@ -249,9 +166,6 @@ class WhooshResultWrapper(object):
 
        Smart function that implements chunking the content
 
        but not overlap chunks so it doesn't highlight the same
 
        close occurrences twice.
 

	
 
        :param matcher:
 
        :param size:
 
        """
 
        memory = [(0, 0)]
 
        if self.matcher.supports('positions'):
 
@@ -269,7 +183,7 @@ class WhooshResultWrapper(object):
 
    def highlight(self, content, top=5):
 
        if self.search_type not in ['content', 'message']:
 
            return ''
 
        hl = highlight(
 
        hl = whoosh_highlight(
 
            text=content,
 
            terms=self.highlight_items,
 
            analyzer=ANALYZER,
rhodecode/lib/paster_commands/cache_keys.py
Show inline comments
 
@@ -29,15 +29,14 @@ import os
 
import sys
 
import logging
 

	
 
from os.path import dirname as dn, join as jn
 
from rhodecode.model.meta import Session
 
#to get the rhodecode import
 
from rhodecode.lib.utils import BasePasterCommand
 
from rhodecode.model.db import CacheInvalidation
 

	
 
# fix rhodecode import
 
from os.path import dirname as dn
 
rc_path = dn(dn(dn(os.path.realpath(__file__))))
 
sys.path.append(rc_path)
 
from rhodecode.lib.utils import BasePasterCommand
 

	
 
from rhodecode.model.db import CacheInvalidation
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
rhodecode/lib/paster_commands/cleanup.py
Show inline comments
 
@@ -32,15 +32,14 @@ import shutil
 
import logging
 
import datetime
 

	
 
from os.path import dirname as dn, join as jn
 
#to get the rhodecode import
 
rc_path = dn(dn(dn(os.path.realpath(__file__))))
 
sys.path.append(rc_path)
 
from rhodecode.lib.utils import BasePasterCommand, ask_ok, REMOVED_REPO_PAT
 

	
 
from rhodecode.lib.utils2 import safe_str
 
from rhodecode.model.db import RhodeCodeUi
 

	
 
# fix rhodecode import
 
from os.path import dirname as dn
 
rc_path = dn(dn(dn(os.path.realpath(__file__))))
 
sys.path.append(rc_path)
 

	
 
log = logging.getLogger(__name__)
 

	
rhodecode/lib/paster_commands/ishell.py
Show inline comments
 
@@ -29,12 +29,12 @@ import os
 
import sys
 
import logging
 

	
 
from os.path import dirname as dn, join as jn
 
#to get the rhodecode import
 
from rhodecode.lib.utils import BasePasterCommand
 

	
 
# fix rhodecode import
 
from os.path import dirname as dn
 
rc_path = dn(dn(dn(os.path.realpath(__file__))))
 
sys.path.append(rc_path)
 
from rhodecode.lib.utils import BasePasterCommand
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
rhodecode/lib/paster_commands/make_rcextensions.py
Show inline comments
 
@@ -26,17 +26,16 @@ from __future__ import with_statement
 

	
 
import os
 
import sys
 
import logging
 
import pkg_resources
 
import traceback
 
import logging
 

	
 
from rhodecode.lib.utils import BasePasterCommand, ask_ok
 

	
 
from os.path import dirname as dn, join as jn
 
#to get the rhodecode import
 
# fix rhodecode import
 
from os.path import dirname as dn
 
rc_path = dn(dn(dn(os.path.realpath(__file__))))
 
sys.path.append(rc_path)
 

	
 
from rhodecode.lib.utils import BasePasterCommand, ask_ok
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
@@ -65,9 +64,9 @@ class Command(BasePasterCommand):
 

	
 
        here = config['here']
 
        tmpl = pkg_resources.resource_string(
 
            'rhodecode', jn('config', 'rcextensions', '__init__.py')
 
            'rhodecode', os.path.join('config', 'rcextensions', '__init__.py')
 
        )
 
        ext_file = jn(here, 'rcextensions', '__init__.py')
 
        ext_file = os.path.join(here, 'rcextensions', '__init__.py')
 
        if os.path.exists(ext_file):
 
            msg = ('Extension file already exists, do you want '
 
                   'to overwrite it ? [y/n]')
rhodecode/lib/paster_commands/repo_scan.py
Show inline comments
 
@@ -29,17 +29,13 @@ import os
 
import sys
 
import logging
 

	
 
from os.path import dirname as dn, join as jn
 
from rhodecode.model.scm import ScmModel
 
#to get the rhodecode import
 
from rhodecode.lib.utils import BasePasterCommand, repo2db_mapper
 

	
 
# fix rhodecode import
 
from os.path import dirname as dn
 
rc_path = dn(dn(dn(os.path.realpath(__file__))))
 
sys.path.append(rc_path)
 
from rhodecode.lib.utils import BasePasterCommand, repo2db_mapper
 

	
 
from rhodecode.model.db import Repository
 
from rhodecode.model.repo import RepoModel
 
from rhodecode.model.meta import Session
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
rhodecode/lib/paster_commands/setup_rhodecode.py
Show inline comments
 
@@ -4,8 +4,8 @@ from paste.script.appinstall import Abst
 
from paste.script.command import BadCommand
 
from paste.deploy import appconfig
 

	
 
from os.path import dirname as dn, join as jn
 
#to get the rhodecode import
 
# fix rhodecode import
 
from os.path import dirname as dn
 
rc_path = dn(dn(dn(os.path.realpath(__file__))))
 
sys.path.append(rc_path)
 

	
rhodecode/lib/paster_commands/update_repoinfo.py
Show inline comments
 
@@ -29,16 +29,16 @@ import sys
 
import logging
 
import string
 

	
 
from os.path import dirname as dn, join as jn
 
#to get the rhodecode import
 
rc_path = dn(dn(dn(os.path.realpath(__file__))))
 
sys.path.append(rc_path)
 
from rhodecode.lib.utils import BasePasterCommand
 

	
 
from rhodecode.model.db import Repository
 
from rhodecode.model.repo import RepoModel
 
from rhodecode.model.meta import Session
 

	
 
# fix rhodecode import
 
from os.path import dirname as dn
 
rc_path = dn(dn(dn(os.path.realpath(__file__))))
 
sys.path.append(rc_path)
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
setup.py
Show inline comments
 
@@ -167,7 +167,7 @@ setup(
 
    repo-scan=rhodecode.lib.paster_commands.repo_scan:Command
 
    cache-keys=rhodecode.lib.paster_commands.cache_keys:Command
 
    ishell=rhodecode.lib.paster_commands.ishell:Command
 
    make-index=rhodecode.lib.indexers:MakeIndex
 
    make-index=rhodecode.lib.paster_commands.make_index:Command
 
    upgrade-db=rhodecode.lib.dbmigrate:UpgradeDb
 
    celeryd=rhodecode.lib.celerypylons.commands:CeleryDaemonCommand
 
    """,
0 comments (0 inline, 0 general)