##// END OF EJS Templates
Updated docs, added apache proxy example config
Updated docs, added apache proxy example config

File last commit:

r777:aac24db5 beta
r881:68aaa0ac beta
Show More
daemon.py
215 lines | 7.3 KiB | text/x-python | PythonLexer
renamed project to rhodecode
r547 #!/usr/bin/env python
# encoding: utf-8
more renames for rhode code !!
r549 # whoosh indexer daemon for rhodecode
renamed project to rhodecode
r547 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License or (at your opinion) any later version of the license.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
"""
Created on Jan 26, 2010
@author: marcink
A deamon will read from task table and run tasks
"""
import sys
import os
from os.path import dirname as dn
from os.path import join as jn
#to get the rhodecode import
project_path = dn(dn(dn(dn(os.path.realpath(__file__)))))
sys.path.append(project_path)
Hacking for git support,and new faster repo scan
r631
Refactor codes for scm model...
r691 from rhodecode.model.scm import ScmModel
renamed project to rhodecode
r547 from rhodecode.lib.helpers import safe_unicode
from whoosh.index import create_in, open_dir
from shutil import rmtree
Hacking for git support,and new faster repo scan
r631 from rhodecode.lib.indexers import INDEX_EXTENSIONS, SCHEMA, IDX_NAME
renamed project to rhodecode
r547
rewrote whoosh indexing to run internal repository.walk() instead of filesystem....
r560 from time import mktime
fixed whoosh failure on new repository...
r567 from vcs.exceptions import ChangesetError, RepositoryError
rewrote whoosh indexing to run internal repository.walk() instead of filesystem....
r560
renamed project to rhodecode
r547 import logging
log = logging.getLogger('whooshIndexer')
# create logger
log.setLevel(logging.DEBUG)
log.propagate = False
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
log.addHandler(ch)
class WhooshIndexingDaemon(object):
rewrote whoosh indexing to run internal repository.walk() instead of filesystem....
r560 """
Deamon for atomic jobs
"""
renamed project to rhodecode
r547
Hacking for git support,and new faster repo scan
r631 def __init__(self, indexname='HG_INDEX', index_location=None,
fixed cache problem,...
r777 repo_location=None, sa=None):
renamed project to rhodecode
r547 self.indexname = indexname
Hacking for git support,and new faster repo scan
r631
self.index_location = index_location
if not index_location:
raise Exception('You have to provide index location')
renamed project to rhodecode
r547 self.repo_location = repo_location
Hacking for git support,and new faster repo scan
r631 if not repo_location:
raise Exception('You have to provide repositories location')
fixed cache problem,...
r777 self.repo_paths = ScmModel(sa).repo_scan(self.repo_location, None)
renamed project to rhodecode
r547 self.initial = False
Hacking for git support,and new faster repo scan
r631 if not os.path.isdir(self.index_location):
extended trending languages to more entries, implemented new faster and "fancy"...
r763 os.makedirs(self.index_location)
renamed project to rhodecode
r547 log.info('Cannot run incremental index since it does not'
' yet exist running full build')
self.initial = True
Hacking for git support,and new faster repo scan
r631
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 def get_paths(self, repo):
Implemented whoosh index building as paster command....
r683 """recursive walk in root dir and return a set of all path in that dir
rewrote whoosh indexing to run internal repository.walk() instead of filesystem....
r560 based on repository walk function
"""
renamed project to rhodecode
r547 index_paths_ = set()
fixed whoosh failure on new repository...
r567 try:
Hacking for git support,and new faster repo scan
r631 for topnode, dirs, files in repo.walk('/', 'tip'):
renamed project to rhodecode
r547 for f in files:
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 index_paths_.add(jn(repo.path, f.path))
fixed whoosh failure on new repository...
r567 for dir in dirs:
for f in files:
index_paths_.add(jn(repo.path, f.path))
Hacking for git support,and new faster repo scan
r631
fixed whoosh failure on new repository...
r567 except RepositoryError:
pass
Hacking for git support,and new faster repo scan
r631 return index_paths_
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 def get_node(self, repo, path):
n_path = path[len(repo.path) + 1:]
node = repo.get_changeset().get_node(n_path)
return node
Hacking for git support,and new faster repo scan
r631
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 def get_node_mtime(self, node):
return mktime(node.last_changeset.date.timetuple())
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 def add_doc(self, writer, path, repo):
Implemented whoosh index building as paster command....
r683 """Adding doc to writer this function itself fetches data from
the instance of vcs backend"""
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 node = self.get_node(repo, path)
rewrote whoosh indexing to run internal repository.walk() instead of filesystem....
r560
#we just index the content of chosen files
if node.extension in INDEX_EXTENSIONS:
renamed project to rhodecode
r547 log.debug(' >> %s [WITH CONTENT]' % path)
rewrote whoosh indexing to run internal repository.walk() instead of filesystem....
r560 u_content = node.content
renamed project to rhodecode
r547 else:
log.debug(' >> %s' % path)
#just index file name without it's content
u_content = u''
Hacking for git support,and new faster repo scan
r631
rewrote whoosh indexing to run internal repository.walk() instead of filesystem....
r560 writer.add_document(owner=unicode(repo.contact),
repository=safe_unicode(repo.name),
path=safe_unicode(path),
content=u_content,
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 modtime=self.get_node_mtime(node),
Hacking for git support,and new faster repo scan
r631 extension=node.extension)
renamed project to rhodecode
r547
def build_index(self):
Hacking for git support,and new faster repo scan
r631 if os.path.exists(self.index_location):
rewrote whoosh indexing to run internal repository.walk() instead of filesystem....
r560 log.debug('removing previous index')
Hacking for git support,and new faster repo scan
r631 rmtree(self.index_location)
if not os.path.exists(self.index_location):
os.mkdir(self.index_location)
idx = create_in(self.index_location, SCHEMA, indexname=IDX_NAME)
renamed project to rhodecode
r547 writer = idx.writer()
Hacking for git support,and new faster repo scan
r631
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 for cnt, repo in enumerate(self.repo_paths.values()):
renamed project to rhodecode
r547 log.debug('building index @ %s' % repo.path)
Hacking for git support,and new faster repo scan
r631
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 for idx_path in self.get_paths(repo):
renamed project to rhodecode
r547 self.add_doc(writer, idx_path, repo)
Hacking for git support,and new faster repo scan
r631
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 log.debug('>> COMMITING CHANGES <<')
renamed project to rhodecode
r547 writer.commit(merge=True)
log.debug('>>> FINISHED BUILDING INDEX <<<')
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 def update_index(self):
log.debug('STARTING INCREMENTAL INDEXING UPDATE')
Hacking for git support,and new faster repo scan
r631
idx = open_dir(self.index_location, indexname=self.indexname)
renamed project to rhodecode
r547 # The set of all paths in the index
indexed_paths = set()
# The set of all paths we need to re-index
to_index = set()
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 reader = idx.reader()
writer = idx.writer()
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 # Loop over the stored fields in the index
for fields in reader.all_stored_fields():
indexed_path = fields['path']
indexed_paths.add(indexed_path)
Hacking for git support,and new faster repo scan
r631
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 repo = self.repo_paths[fields['repository']]
Hacking for git support,and new faster repo scan
r631
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 try:
node = self.get_node(repo, indexed_path)
except ChangesetError:
renamed project to rhodecode
r547 # This file was deleted since it was indexed
log.debug('removing from index %s' % indexed_path)
writer.delete_by_term('path', indexed_path)
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 else:
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 # Check if this file was changed since it was indexed
renamed project to rhodecode
r547 indexed_time = fields['modtime']
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 mtime = self.get_node_mtime(node)
renamed project to rhodecode
r547 if mtime > indexed_time:
# The file has changed, delete it and add it to the list of
# files to reindex
log.debug('adding to reindex list %s' % indexed_path)
writer.delete_by_term('path', indexed_path)
to_index.add(indexed_path)
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 # Loop over the files in the filesystem
# Assume we have a function that gathers the filenames of the
# documents to be indexed
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 for repo in self.repo_paths.values():
for path in self.get_paths(repo):
renamed project to rhodecode
r547 if path in to_index or path not in indexed_paths:
# This is either a file that's changed, or a new file
# that wasn't indexed before. So index it!
self.add_doc(writer, path, repo)
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 log.debug('re indexing %s' % path)
Hacking for git support,and new faster repo scan
r631
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 log.debug('>> COMMITING CHANGES <<')
renamed project to rhodecode
r547 writer.commit(merge=True)
fixed reindexing, and made some optimizations to reuse repo instances from repo scann list.
r561 log.debug('>>> FINISHED REBUILDING INDEX <<<')
Hacking for git support,and new faster repo scan
r631
renamed project to rhodecode
r547 def run(self, full_index=False):
"""Run daemon"""
if full_index or self.initial:
self.build_index()
else:
self.update_index()