# HG changeset patch # User Marcin Kuzminski # Date 1369864876 -7200 # Node ID a42bfe8a933529bf59ad2a2172a850c588c71fa6 # Parent 424b6c711a7f63680abd1474b66ddf42c0345a16 moved make-index command to paster_commands module - optimized imports and code diff -r 424b6c711a7f -r a42bfe8a9335 rhodecode/controllers/changelog.py --- a/rhodecode/controllers/changelog.py Wed May 29 12:13:02 2013 +0200 +++ b/rhodecode/controllers/changelog.py Thu May 30 00:01:16 2013 +0200 @@ -132,7 +132,7 @@ 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) diff -r 424b6c711a7f -r a42bfe8a9335 rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py Wed May 29 12:13:02 2013 +0200 +++ b/rhodecode/lib/helpers.py Thu May 30 00:01:16 2013 +0200 @@ -900,13 +900,15 @@ 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('' % 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): diff -r 424b6c711a7f -r a42bfe8a9335 rhodecode/lib/indexers/__init__.py --- a/rhodecode/lib/indexers/__init__.py Wed May 29 12:13:02 2013 +0200 +++ b/rhodecode/lib/indexers/__init__.py Thu May 30 00:01:16 2013 +0200 @@ -24,32 +24,17 @@ # along with this program. If not, see . 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 @@ ) -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 @@ 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 @@ 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, diff -r 424b6c711a7f -r a42bfe8a9335 rhodecode/lib/paster_commands/cache_keys.py --- a/rhodecode/lib/paster_commands/cache_keys.py Wed May 29 12:13:02 2013 +0200 +++ b/rhodecode/lib/paster_commands/cache_keys.py Thu May 30 00:01:16 2013 +0200 @@ -29,15 +29,14 @@ 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__) diff -r 424b6c711a7f -r a42bfe8a9335 rhodecode/lib/paster_commands/cleanup.py --- a/rhodecode/lib/paster_commands/cleanup.py Wed May 29 12:13:02 2013 +0200 +++ b/rhodecode/lib/paster_commands/cleanup.py Thu May 30 00:01:16 2013 +0200 @@ -32,15 +32,14 @@ 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__) diff -r 424b6c711a7f -r a42bfe8a9335 rhodecode/lib/paster_commands/ishell.py --- a/rhodecode/lib/paster_commands/ishell.py Wed May 29 12:13:02 2013 +0200 +++ b/rhodecode/lib/paster_commands/ishell.py Thu May 30 00:01:16 2013 +0200 @@ -29,12 +29,12 @@ 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__) diff -r 424b6c711a7f -r a42bfe8a9335 rhodecode/lib/paster_commands/make_rcextensions.py --- a/rhodecode/lib/paster_commands/make_rcextensions.py Wed May 29 12:13:02 2013 +0200 +++ b/rhodecode/lib/paster_commands/make_rcextensions.py Thu May 30 00:01:16 2013 +0200 @@ -26,17 +26,16 @@ 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 @@ 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]') diff -r 424b6c711a7f -r a42bfe8a9335 rhodecode/lib/paster_commands/repo_scan.py --- a/rhodecode/lib/paster_commands/repo_scan.py Wed May 29 12:13:02 2013 +0200 +++ b/rhodecode/lib/paster_commands/repo_scan.py Thu May 30 00:01:16 2013 +0200 @@ -29,17 +29,13 @@ 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__) diff -r 424b6c711a7f -r a42bfe8a9335 rhodecode/lib/paster_commands/setup_rhodecode.py --- a/rhodecode/lib/paster_commands/setup_rhodecode.py Wed May 29 12:13:02 2013 +0200 +++ b/rhodecode/lib/paster_commands/setup_rhodecode.py Thu May 30 00:01:16 2013 +0200 @@ -4,8 +4,8 @@ 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) diff -r 424b6c711a7f -r a42bfe8a9335 rhodecode/lib/paster_commands/update_repoinfo.py --- a/rhodecode/lib/paster_commands/update_repoinfo.py Wed May 29 12:13:02 2013 +0200 +++ b/rhodecode/lib/paster_commands/update_repoinfo.py Thu May 30 00:01:16 2013 +0200 @@ -29,16 +29,16 @@ 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__) diff -r 424b6c711a7f -r a42bfe8a9335 setup.py --- a/setup.py Wed May 29 12:13:02 2013 +0200 +++ b/setup.py Thu May 30 00:01:16 2013 +0200 @@ -167,7 +167,7 @@ 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 """,