# HG changeset patch # User Marcin Kuzminski # Date 1282153268 -7200 # Node ID 9b67cebe660906e77a61d696c55738c2954a511c # Parent 9a7ae16ff53ef818806daab1902a11793ac0b601 some fixes to whoosh indexer daemon diff -r 9a7ae16ff53e -r 9b67cebe6609 pylons_app/lib/indexers/daemon.py --- a/pylons_app/lib/indexers/daemon.py Wed Aug 18 16:24:27 2010 +0200 +++ b/pylons_app/lib/indexers/daemon.py Wed Aug 18 19:41:08 2010 +0200 @@ -25,25 +25,26 @@ """ import sys import os -from pidlock import LockHeld, DaemonLock -import traceback - from os.path import dirname as dn from os.path import join as jn #to get the pylons_app import -sys.path.append(dn(dn(dn(dn(os.path.realpath(__file__)))))) +project_path = dn(dn(dn(dn(os.path.realpath(__file__))))) +sys.path.append(project_path) +from pidlock import LockHeld, DaemonLock +import traceback from pylons_app.config.environment import load_environment from pylons_app.model.hg_model import HgModel from whoosh.index import create_in, open_dir from shutil import rmtree -from pylons_app.lib.indexers import ANALYZER, EXCLUDE_EXTENSIONS, IDX_LOCATION, SCHEMA, IDX_NAME +from pylons_app.lib.indexers import ANALYZER, EXCLUDE_EXTENSIONS, IDX_LOCATION, \ +SCHEMA, IDX_NAME + import logging -log = logging.getLogger(__name__) - - -location = '/home/marcink/python_workspace_dirty/*' +import logging.config +logging.config.fileConfig(jn(project_path, 'development.ini')) +log = logging.getLogger('whooshIndexer') def scan_paths(root_location): return HgModel.repo_scan('/', root_location, None, True) @@ -51,9 +52,9 @@ class WhooshIndexingDaemon(object): """Deamon for atomic jobs""" - def __init__(self, indexname='HG_INDEX'): + def __init__(self, indexname='HG_INDEX', repo_location=None): self.indexname = indexname - + self.repo_location = repo_location def get_paths(self, root_dir): """recursive walk in root dir and return a set of all path in that dir @@ -97,7 +98,7 @@ idx = create_in(IDX_LOCATION, SCHEMA, indexname=IDX_NAME) writer = idx.writer() - for cnt, repo in enumerate(scan_paths(location).values()): + for cnt, repo in enumerate(scan_paths(self.repo_location).values()): log.debug('building index @ %s' % repo.path) for idx_path in self.get_paths(repo.path): @@ -149,7 +150,7 @@ # Loop over the files in the filesystem # Assume we have a function that gathers the filenames of the # documents to be indexed - for repo in scan_paths(location).values(): + for repo in scan_paths(self.repo_location).values(): for path in self.get_paths(repo.path): if path in to_index or path not in indexed_paths: # This is either a file that's changed, or a new file @@ -169,12 +170,11 @@ self.update_index() if __name__ == "__main__": + repo_location = '/home/marcink/python_workspace_dirty/*' - #config = load_environment() - #print config try: l = DaemonLock() - WhooshIndexingDaemon().run(full_index=True) + WhooshIndexingDaemon(repo_location=repo_location).run(full_index=True) l.release() except LockHeld: sys.exit(1)