##// END OF EJS Templates
some fixes to whoosh indexer daemon
marcink -
r411:9b67cebe default
parent child Browse files
Show More
@@ -25,25 +25,26 b' A deamon will read from task table and r'
25 25 """
26 26 import sys
27 27 import os
28 from pidlock import LockHeld, DaemonLock
29 import traceback
30
31 28 from os.path import dirname as dn
32 29 from os.path import join as jn
33 30
34 31 #to get the pylons_app import
35 sys.path.append(dn(dn(dn(dn(os.path.realpath(__file__))))))
32 project_path = dn(dn(dn(dn(os.path.realpath(__file__)))))
33 sys.path.append(project_path)
36 34
35 from pidlock import LockHeld, DaemonLock
36 import traceback
37 37 from pylons_app.config.environment import load_environment
38 38 from pylons_app.model.hg_model import HgModel
39 39 from whoosh.index import create_in, open_dir
40 40 from shutil import rmtree
41 from pylons_app.lib.indexers import ANALYZER, EXCLUDE_EXTENSIONS, IDX_LOCATION, SCHEMA, IDX_NAME
41 from pylons_app.lib.indexers import ANALYZER, EXCLUDE_EXTENSIONS, IDX_LOCATION, \
42 SCHEMA, IDX_NAME
43
42 44 import logging
43 log = logging.getLogger(__name__)
44
45
46 location = '/home/marcink/python_workspace_dirty/*'
45 import logging.config
46 logging.config.fileConfig(jn(project_path, 'development.ini'))
47 log = logging.getLogger('whooshIndexer')
47 48
48 49 def scan_paths(root_location):
49 50 return HgModel.repo_scan('/', root_location, None, True)
@@ -51,9 +52,9 b' def scan_paths(root_location):'
51 52 class WhooshIndexingDaemon(object):
52 53 """Deamon for atomic jobs"""
53 54
54 def __init__(self, indexname='HG_INDEX'):
55 def __init__(self, indexname='HG_INDEX', repo_location=None):
55 56 self.indexname = indexname
56
57 self.repo_location = repo_location
57 58
58 59 def get_paths(self, root_dir):
59 60 """recursive walk in root dir and return a set of all path in that dir
@@ -97,7 +98,7 b' class WhooshIndexingDaemon(object):'
97 98 idx = create_in(IDX_LOCATION, SCHEMA, indexname=IDX_NAME)
98 99 writer = idx.writer()
99 100
100 for cnt, repo in enumerate(scan_paths(location).values()):
101 for cnt, repo in enumerate(scan_paths(self.repo_location).values()):
101 102 log.debug('building index @ %s' % repo.path)
102 103
103 104 for idx_path in self.get_paths(repo.path):
@@ -149,7 +150,7 b' class WhooshIndexingDaemon(object):'
149 150 # Loop over the files in the filesystem
150 151 # Assume we have a function that gathers the filenames of the
151 152 # documents to be indexed
152 for repo in scan_paths(location).values():
153 for repo in scan_paths(self.repo_location).values():
153 154 for path in self.get_paths(repo.path):
154 155 if path in to_index or path not in indexed_paths:
155 156 # This is either a file that's changed, or a new file
@@ -169,12 +170,11 b' class WhooshIndexingDaemon(object):'
169 170 self.update_index()
170 171
171 172 if __name__ == "__main__":
173 repo_location = '/home/marcink/python_workspace_dirty/*'
172 174
173 #config = load_environment()
174 #print config
175 175 try:
176 176 l = DaemonLock()
177 WhooshIndexingDaemon().run(full_index=True)
177 WhooshIndexingDaemon(repo_location=repo_location).run(full_index=True)
178 178 l.release()
179 179 except LockHeld:
180 180 sys.exit(1)
General Comments 0
You need to be logged in to leave comments. Login now