##// END OF EJS Templates
fixes #90 + docs update
fixes #90 + docs update

File last commit:

r894:1fed3c91 beta
r894:1fed3c91 beta
Show More
__init__.py
203 lines | 7.0 KiB | text/x-python | PythonLexer
Hacking for git support,and new faster repo scan
r631 import os
import sys
complete rewrite of paster commands,...
r785 import traceback
renamed project to rhodecode
r547 from os.path import dirname as dn, join as jn
Hacking for git support,and new faster repo scan
r631
#to get the rhodecode import
sys.path.append(dn(dn(dn(os.path.realpath(__file__)))))
fixes #90 + docs update
r894 from string import strip
complete rewrite of paster commands,...
r785 from rhodecode.model import init_model
from rhodecode.model.scm import ScmModel
renamed project to rhodecode
r547 from rhodecode.config.environment import load_environment
complete rewrite of paster commands,...
r785 from rhodecode.lib.utils import BasePasterCommand, Command, add_cache
renamed project to rhodecode
r547 from shutil import rmtree
from webhelpers.html.builder import escape
from vcs.utils.lazy import LazyProperty
complete rewrite of paster commands,...
r785 from sqlalchemy import engine_from_config
renamed project to rhodecode
r547 from whoosh.analysis import RegexTokenizer, LowercaseFilter, StopFilter
from whoosh.fields import TEXT, ID, STORED, Schema, FieldType
from whoosh.index import create_in, open_dir
from whoosh.formats import Characters
Hacking for git support,and new faster repo scan
r631 from whoosh.highlight import highlight, SimpleFragmenter, HtmlFormatter
renamed project to rhodecode
r547
#EXTENSIONS WE WANT TO INDEX CONTENT OFF
INDEX_EXTENSIONS = ['action', 'adp', 'ashx', 'asmx', 'aspx', 'asx', 'axd', 'c',
'cfg', 'cfm', 'cpp', 'cs', 'css', 'diff', 'do', 'el', 'erl',
'h', 'htm', 'html', 'ini', 'java', 'js', 'jsp', 'jspx', 'lisp',
'lua', 'm', 'mako', 'ml', 'pas', 'patch', 'php', 'php3',
'php4', 'phtml', 'pm', 'py', 'rb', 'rst', 's', 'sh', 'sql',
'tpl', 'txt', 'vim', 'wss', 'xhtml', 'xml', 'xsl', 'xslt',
'yaws']
#CUSTOM ANALYZER wordsplit + lowercase filter
ANALYZER = RegexTokenizer(expression=r"\w+") | LowercaseFilter()
#INDEX SCHEMA DEFINITION
SCHEMA = Schema(owner=TEXT(),
repository=TEXT(stored=True),
Added searching for file names within the repository in rhodecode
r556 path=TEXT(stored=True),
renamed project to rhodecode
r547 content=FieldType(format=Characters(ANALYZER),
scorable=True, stored=True),
modtime=STORED(), extension=TEXT(stored=True))
IDX_NAME = 'HG_INDEX'
Hacking for git support,and new faster repo scan
r631 FORMATTER = HtmlFormatter('span', between='\n<span class="break">...</span>\n')
renamed project to rhodecode
r547 FRAGMENTER = SimpleFragmenter(200)
Hacking for git support,and new faster repo scan
r631
complete rewrite of paster commands,...
r785 class MakeIndex(BasePasterCommand):
Hacking for git support,and new faster repo scan
r631
max_args = 1
min_args = 1
usage = "CONFIG_FILE"
summary = "Creates index for full text search given configuration file"
Implemented whoosh index building as paster command....
r683 group_name = "RhodeCode"
takes_config_file = -1
complete rewrite of paster commands,...
r785 parser = Command.standard_parser(verbose=True)
Hacking for git support,and new faster repo scan
r631 def command(self):
Implemented whoosh index building as paster command....
r683
complete rewrite of paster commands,...
r785 from pylons import config
add_cache(config)
engine = engine_from_config(config, 'sqlalchemy.db1.')
init_model(engine)
index_location = config['index_dir']
Implemented whoosh index building as paster command....
r683 repo_location = self.options.repo_location
fixes #90 + docs update
r894 repo_list = map(strip, self.options.repo_list.split(','))
Hacking for git support,and new faster repo scan
r631
Implemented whoosh index building as paster command....
r683 #======================================================================
Hacking for git support,and new faster repo scan
r631 # WHOOSH DAEMON
Implemented whoosh index building as paster command....
r683 #======================================================================
Hacking for git support,and new faster repo scan
r631 from rhodecode.lib.pidlock import LockHeld, DaemonLock
from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon
try:
l = DaemonLock()
Implemented whoosh index building as paster command....
r683 WhooshIndexingDaemon(index_location=index_location,
fixes #90 + docs update
r894 repo_location=repo_location,
repo_list=repo_list)\
Hacking for git support,and new faster repo scan
r631 .run(full_index=self.options.full_index)
l.release()
except LockHeld:
sys.exit(1)
complete rewrite of paster commands,...
r785 def update_parser(self):
self.parser.add_option('--repo-location',
action='store',
dest='repo_location',
help="Specifies repositories location to index REQUIRED",
)
fixes #90 + docs update
r894 self.parser.add_option('--index-only',
action='store',
dest='repo_list',
help="Specifies a comma separated list of repositores "
"to build index on OPTIONAL",
)
complete rewrite of paster commands,...
r785 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)
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 class ResultWrapper(object):
Added searching for file names within the repository in rhodecode
r556 def __init__(self, search_type, searcher, matcher, highlight_items):
self.search_type = search_type
renamed project to rhodecode
r547 self.searcher = searcher
self.matcher = matcher
self.highlight_items = highlight_items
self.fragment_size = 200 / 2
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 @LazyProperty
def doc_ids(self):
docs_id = []
while self.matcher.is_active():
docnum = self.matcher.id()
chunks = [offsets for offsets in self.get_chunks()]
docs_id.append([docnum, chunks])
self.matcher.next()
Hacking for git support,and new faster repo scan
r631 return docs_id
renamed project to rhodecode
r547 def __str__(self):
return '<%s at %s>' % (self.__class__.__name__, len(self.doc_ids))
def __repr__(self):
return self.__str__()
def __len__(self):
return len(self.doc_ids)
def __iter__(self):
"""
Allows Iteration over results,and lazy generate content
*Requires* implementation of ``__getitem__`` method.
"""
for docid in self.doc_ids:
yield self.get_full_content(docid)
def __getslice__(self, i, j):
"""
Slicing of resultWrapper
"""
slice = []
for docid in self.doc_ids[i:j]:
slice.append(self.get_full_content(docid))
Hacking for git support,and new faster repo scan
r631 return slice
renamed project to rhodecode
r547
def get_full_content(self, docid):
res = self.searcher.stored_fields(docid[0])
f_path = res['path'][res['path'].find(res['repository']) \
+ len(res['repository']):].lstrip('/')
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 content_short = self.get_short_content(res, docid[1])
res.update({'content_short':content_short,
'content_short_hl':self.highlight(content_short),
'f_path':f_path})
Hacking for git support,and new faster repo scan
r631
return res
renamed project to rhodecode
r547 def get_short_content(self, res, chunks):
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 return ''.join([res['content'][chunk[0]:chunk[1]] for chunk in chunks])
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 def get_chunks(self):
"""
Smart function that implements chunking the content
but not overlap chunks so it doesn't highlight the same
Added searching for file names within the repository in rhodecode
r556 close occurrences twice.
Hacking for git support,and new faster repo scan
r631 @param matcher:
@param size:
renamed project to rhodecode
r547 """
memory = [(0, 0)]
for span in self.matcher.spans():
start = span.startchar or 0
end = span.endchar or 0
start_offseted = max(0, start - self.fragment_size)
end_offseted = end + self.fragment_size
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 if start_offseted < memory[-1][1]:
start_offseted = memory[-1][1]
Hacking for git support,and new faster repo scan
r631 memory.append((start_offseted, end_offseted,))
yield (start_offseted, end_offseted,)
renamed project to rhodecode
r547 def highlight(self, content, top=5):
Added searching for file names within the repository in rhodecode
r556 if self.search_type != 'content':
return ''
renamed project to rhodecode
r547 hl = highlight(escape(content),
self.highlight_items,
analyzer=ANALYZER,
fragmenter=FRAGMENTER,
formatter=FORMATTER,
top=top)
Hacking for git support,and new faster repo scan
r631 return hl