# HG changeset patch # User Marcin Kuzminski # Date 2010-08-18 17:41:08 # Node ID 9b67cebe660906e77a61d696c55738c2954a511c # Parent 9a7ae16ff53ef818806daab1902a11793ac0b601 some fixes to whoosh indexer daemon diff --git a/pylons_app/lib/indexers/daemon.py b/pylons_app/lib/indexers/daemon.py --- a/pylons_app/lib/indexers/daemon.py +++ b/pylons_app/lib/indexers/daemon.py @@ -25,25 +25,26 @@ A deamon will read from task table and r """ 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 @@ def scan_paths(root_location): 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 @@ class WhooshIndexingDaemon(object): 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 @@ class WhooshIndexingDaemon(object): # 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 @@ class WhooshIndexingDaemon(object): 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)