Show More
@@ -1,135 +1,155 b'' | |||
|
1 | 1 | ################################################################################ |
|
2 | 2 | ################################################################################ |
|
3 | 3 | # pylons_app - Pylons environment configuration # |
|
4 | 4 | # # |
|
5 | 5 | # The %(here)s variable will be replaced with the parent directory of this file# |
|
6 | 6 | ################################################################################ |
|
7 | 7 | |
|
8 | 8 | [DEFAULT] |
|
9 | 9 | debug = true |
|
10 | 10 | ############################################ |
|
11 | 11 | ## Uncomment and replace with the address ## |
|
12 | 12 | ## which should receive any error reports ## |
|
13 | 13 | ############################################ |
|
14 | 14 | #email_to = admin@localhost |
|
15 | 15 | #smtp_server = mail.server.com |
|
16 | 16 | #error_email_from = paste_error@localhost |
|
17 | 17 | #smtp_username = |
|
18 | 18 | #smtp_password = |
|
19 | 19 | #error_message = 'mercurial crash !' |
|
20 | 20 | |
|
21 | 21 | [server:main] |
|
22 | 22 | ##nr of threads to spawn |
|
23 | 23 | threadpool_workers = 5 |
|
24 | 24 | |
|
25 | 25 | ##max request before |
|
26 | 26 | threadpool_max_requests = 2 |
|
27 | 27 | |
|
28 | 28 | ##option to use threads of process |
|
29 | 29 | use_threadpool = true |
|
30 | 30 | |
|
31 | 31 | use = egg:Paste#http |
|
32 | 32 | host = 127.0.0.1 |
|
33 | 33 | port = 5000 |
|
34 | 34 | |
|
35 | 35 | [app:main] |
|
36 | 36 | use = egg:pylons_app |
|
37 | 37 | full_stack = true |
|
38 | 38 | static_files = true |
|
39 | 39 | lang=en |
|
40 | 40 | cache_dir = %(here)s/data |
|
41 | 41 | |
|
42 | 42 | #################################### |
|
43 | 43 | ### BEAKER CACHE #### |
|
44 | 44 | #################################### |
|
45 | 45 | beaker.cache.data_dir=/%(here)s/data/cache/data |
|
46 | 46 | beaker.cache.lock_dir=/%(here)s/data/cache/lock |
|
47 | 47 | beaker.cache.regions=super_short_term,short_term,long_term |
|
48 | 48 | beaker.cache.long_term.type=memory |
|
49 | 49 | beaker.cache.long_term.expire=36000 |
|
50 | 50 | beaker.cache.short_term.type=memory |
|
51 | 51 | beaker.cache.short_term.expire=60 |
|
52 | 52 | beaker.cache.super_short_term.type=memory |
|
53 | 53 | beaker.cache.super_short_term.expire=10 |
|
54 | 54 | |
|
55 | #################################### | |
|
56 | ### BEAKER SESSION #### | |
|
57 | #################################### | |
|
58 | ## Type of storage used for the session, current types are | |
|
59 | ## βdbmβ, βfileβ, βmemcachedβ, βdatabaseβ, and βmemoryβ. | |
|
60 | ## The storage uses the Container API | |
|
61 | ##that is also used by the cache system. | |
|
62 | beaker.session.type = file | |
|
63 | ||
|
64 | beaker.session.key = hg-app | |
|
65 | beaker.session.secret = g654dcno0-9873jhgfreyu | |
|
66 | beaker.session.timeout = 36000 | |
|
67 | ||
|
68 | ##auto save the session to not to use .save() | |
|
69 | beaker.session.auto = False | |
|
70 | ||
|
71 | ##true exire at browser close | |
|
72 | #beaker.session.cookie_expires = 3600 | |
|
73 | ||
|
74 | ||
|
55 | 75 | ################################################################################ |
|
56 | 76 | ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ## |
|
57 | 77 | ## Debug mode will enable the interactive debugging tool, allowing ANYONE to ## |
|
58 | 78 | ## execute malicious code after an exception is raised. ## |
|
59 | 79 | ################################################################################ |
|
60 | 80 | #set debug = false |
|
61 | 81 | |
|
62 | 82 | ################################## |
|
63 | 83 | ### LOGVIEW CONFIG ### |
|
64 | 84 | ################################## |
|
65 | 85 | logview.sqlalchemy = #faa |
|
66 | 86 | logview.pylons.templating = #bfb |
|
67 | 87 | logview.pylons.util = #eee |
|
68 | 88 | |
|
69 | 89 | ######################################################### |
|
70 | 90 | ### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG ### |
|
71 | 91 | ######################################################### |
|
72 | 92 | sqlalchemy.db1.url = sqlite:///%(here)s/hg_app.db |
|
73 | 93 | #sqlalchemy.db1.echo = False |
|
74 | 94 | #sqlalchemy.db1.pool_recycle = 3600 |
|
75 | 95 | sqlalchemy.convert_unicode = true |
|
76 | 96 | |
|
77 | 97 | ################################ |
|
78 | 98 | ### LOGGING CONFIGURATION #### |
|
79 | 99 | ################################ |
|
80 | 100 | [loggers] |
|
81 | 101 | keys = root, routes, pylons_app, sqlalchemy |
|
82 | 102 | |
|
83 | 103 | [handlers] |
|
84 | 104 | keys = console |
|
85 | 105 | |
|
86 | 106 | [formatters] |
|
87 | 107 | keys = generic,color_formatter |
|
88 | 108 | |
|
89 | 109 | ############# |
|
90 | 110 | ## LOGGERS ## |
|
91 | 111 | ############# |
|
92 | 112 | [logger_root] |
|
93 | 113 | level = NOTSET |
|
94 | 114 | handlers = console |
|
95 | 115 | |
|
96 | 116 | [logger_routes] |
|
97 | 117 | level = DEBUG |
|
98 | 118 | handlers = console |
|
99 | 119 | qualname = routes.middleware |
|
100 | 120 | # "level = DEBUG" logs the route matched and routing variables. |
|
101 | 121 | |
|
102 | 122 | [logger_pylons_app] |
|
103 | 123 | level = DEBUG |
|
104 | 124 | handlers = console |
|
105 | 125 | qualname = pylons_app |
|
106 | 126 | propagate = 0 |
|
107 | 127 | |
|
108 | 128 | [logger_sqlalchemy] |
|
109 | 129 | level = ERROR |
|
110 | 130 | handlers = console |
|
111 | 131 | qualname = sqlalchemy.engine |
|
112 | 132 | propagate = 0 |
|
113 | 133 | |
|
114 | 134 | ############## |
|
115 | 135 | ## HANDLERS ## |
|
116 | 136 | ############## |
|
117 | 137 | |
|
118 | 138 | [handler_console] |
|
119 | 139 | class = StreamHandler |
|
120 | 140 | args = (sys.stderr,) |
|
121 | 141 | level = NOTSET |
|
122 | 142 | formatter = color_formatter |
|
123 | 143 | |
|
124 | 144 | ################ |
|
125 | 145 | ## FORMATTERS ## |
|
126 | 146 | ################ |
|
127 | 147 | |
|
128 | 148 | [formatter_generic] |
|
129 | 149 | format = %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s |
|
130 | 150 | datefmt = %Y-%m-%d %H:%M:%S |
|
131 | 151 | |
|
132 | 152 | [formatter_color_formatter] |
|
133 | 153 | class=pylons_app.lib.colored_formatter.ColorFormatter |
|
134 | 154 | format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s |
|
135 | 155 | datefmt = %Y-%m-%d %H:%M:%S No newline at end of file |
@@ -1,135 +1,155 b'' | |||
|
1 | 1 | ################################################################################ |
|
2 | 2 | ################################################################################ |
|
3 | 3 | # pylons_app - Pylons environment configuration # |
|
4 | 4 | # # |
|
5 | 5 | # The %(here)s variable will be replaced with the parent directory of this file# |
|
6 | 6 | ################################################################################ |
|
7 | 7 | |
|
8 | 8 | [DEFAULT] |
|
9 | 9 | debug = true |
|
10 | 10 | ############################################ |
|
11 | 11 | ## Uncomment and replace with the address ## |
|
12 | 12 | ## which should receive any error reports ## |
|
13 | 13 | ############################################ |
|
14 | 14 | #email_to = admin@localhost |
|
15 | 15 | #smtp_server = mail.server.com |
|
16 | 16 | #error_email_from = paste_error@localhost |
|
17 | 17 | #smtp_username = |
|
18 | 18 | #smtp_password = |
|
19 | 19 | #error_message = 'mercurial crash !' |
|
20 | 20 | |
|
21 | 21 | [server:main] |
|
22 | 22 | ##nr of threads to spawn |
|
23 | 23 | threadpool_workers = 5 |
|
24 | 24 | |
|
25 | 25 | ##max request before |
|
26 | 26 | threadpool_max_requests = 2 |
|
27 | 27 | |
|
28 | 28 | ##option to use threads of process |
|
29 | 29 | use_threadpool = true |
|
30 | 30 | |
|
31 | 31 | use = egg:Paste#http |
|
32 | 32 | host = 127.0.0.1 |
|
33 | 33 | port = 8001 |
|
34 | 34 | |
|
35 | 35 | [app:main] |
|
36 | 36 | use = egg:pylons_app |
|
37 | 37 | full_stack = true |
|
38 | 38 | static_files = false |
|
39 | 39 | lang=en |
|
40 | 40 | cache_dir = %(here)s/data |
|
41 | 41 | |
|
42 | 42 | #################################### |
|
43 | 43 | ### BEAKER CACHE #### |
|
44 | 44 | #################################### |
|
45 | 45 | beaker.cache.data_dir=/%(here)s/data/cache/data |
|
46 | 46 | beaker.cache.lock_dir=/%(here)s/data/cache/lock |
|
47 | 47 | beaker.cache.regions=super_short_term,short_term,long_term |
|
48 | 48 | beaker.cache.long_term.type=memory |
|
49 | 49 | beaker.cache.long_term.expire=36000 |
|
50 | 50 | beaker.cache.short_term.type=memory |
|
51 | 51 | beaker.cache.short_term.expire=60 |
|
52 | 52 | beaker.cache.super_short_term.type=memory |
|
53 | 53 | beaker.cache.super_short_term.expire=10 |
|
54 | 54 | |
|
55 | #################################### | |
|
56 | ### BEAKER SESSION #### | |
|
57 | #################################### | |
|
58 | ## Type of storage used for the session, current types are | |
|
59 | ## βdbmβ, βfileβ, βmemcachedβ, βdatabaseβ, and βmemoryβ. | |
|
60 | ## The storage uses the Container API | |
|
61 | ##that is also used by the cache system. | |
|
62 | beaker.session.type = file | |
|
63 | ||
|
64 | beaker.session.key = hg-app | |
|
65 | beaker.session.secret = g654dcno0-9873jhgfreyu | |
|
66 | beaker.session.timeout = 36000 | |
|
67 | ||
|
68 | ##auto save the session to not to use .save() | |
|
69 | beaker.session.auto = False | |
|
70 | ||
|
71 | ##true exire at browser close | |
|
72 | #beaker.session.cookie_expires = 3600 | |
|
73 | ||
|
74 | ||
|
55 | 75 | ################################################################################ |
|
56 | 76 | ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ## |
|
57 | 77 | ## Debug mode will enable the interactive debugging tool, allowing ANYONE to ## |
|
58 | 78 | ## execute malicious code after an exception is raised. ## |
|
59 | 79 | ################################################################################ |
|
60 | 80 | set debug = false |
|
61 | 81 | |
|
62 | 82 | ################################## |
|
63 | 83 | ### LOGVIEW CONFIG ### |
|
64 | 84 | ################################## |
|
65 | 85 | logview.sqlalchemy = #faa |
|
66 | 86 | logview.pylons.templating = #bfb |
|
67 | 87 | logview.pylons.util = #eee |
|
68 | 88 | |
|
69 | 89 | ######################################################### |
|
70 | 90 | ### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG ### |
|
71 | 91 | ######################################################### |
|
72 | 92 | sqlalchemy.db1.url = sqlite:///%(here)s/hg_app.db |
|
73 | 93 | #sqlalchemy.db1.echo = False |
|
74 | 94 | #sqlalchemy.db1.pool_recycle = 3600 |
|
75 | 95 | sqlalchemy.convert_unicode = true |
|
76 | 96 | |
|
77 | 97 | ################################ |
|
78 | 98 | ### LOGGING CONFIGURATION #### |
|
79 | 99 | ################################ |
|
80 | 100 | [loggers] |
|
81 | 101 | keys = root, routes, pylons_app, sqlalchemy |
|
82 | 102 | |
|
83 | 103 | [handlers] |
|
84 | 104 | keys = console |
|
85 | 105 | |
|
86 | 106 | [formatters] |
|
87 | 107 | keys = generic,color_formatter |
|
88 | 108 | |
|
89 | 109 | ############# |
|
90 | 110 | ## LOGGERS ## |
|
91 | 111 | ############# |
|
92 | 112 | [logger_root] |
|
93 | 113 | level = INFO |
|
94 | 114 | handlers = console |
|
95 | 115 | |
|
96 | 116 | [logger_routes] |
|
97 | 117 | level = INFO |
|
98 | 118 | handlers = console |
|
99 | 119 | qualname = routes.middleware |
|
100 | 120 | # "level = DEBUG" logs the route matched and routing variables. |
|
101 | 121 | |
|
102 | 122 | [logger_pylons_app] |
|
103 | 123 | level = DEBUG |
|
104 | 124 | handlers = console |
|
105 | 125 | qualname = pylons_app |
|
106 | 126 | propagate = 0 |
|
107 | 127 | |
|
108 | 128 | [logger_sqlalchemy] |
|
109 | 129 | level = ERROR |
|
110 | 130 | handlers = console |
|
111 | 131 | qualname = sqlalchemy.engine |
|
112 | 132 | propagate = 0 |
|
113 | 133 | |
|
114 | 134 | ############## |
|
115 | 135 | ## HANDLERS ## |
|
116 | 136 | ############## |
|
117 | 137 | |
|
118 | 138 | [handler_console] |
|
119 | 139 | class = StreamHandler |
|
120 | 140 | args = (sys.stderr,) |
|
121 | 141 | level = NOTSET |
|
122 | 142 | formatter = color_formatter |
|
123 | 143 | |
|
124 | 144 | ################ |
|
125 | 145 | ## FORMATTERS ## |
|
126 | 146 | ################ |
|
127 | 147 | |
|
128 | 148 | [formatter_generic] |
|
129 | 149 | format = %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s |
|
130 | 150 | datefmt = %Y-%m-%d %H:%M:%S |
|
131 | 151 | |
|
132 | 152 | [formatter_color_formatter] |
|
133 | 153 | class=pylons_app.lib.colored_formatter.ColorFormatter |
|
134 | 154 | format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s |
|
135 | 155 | datefmt = %Y-%m-%d %H:%M:%S No newline at end of file |
@@ -1,36 +1,41 b'' | |||
|
1 | 1 | import sys |
|
2 | 2 | import os |
|
3 | 3 | from pidlock import LockHeld, DaemonLock |
|
4 | 4 | import traceback |
|
5 | 5 | |
|
6 | 6 | from os.path import dirname as dn |
|
7 | 7 | from os.path import join as jn |
|
8 | 8 | |
|
9 | 9 | #to get the pylons_app import |
|
10 | 10 | sys.path.append(dn(dn(dn(os.path.realpath(__file__))))) |
|
11 | 11 | |
|
12 | 12 | from pylons_app.config.environment import load_environment |
|
13 | 13 | from pylons_app.model.hg_model import HgModel |
|
14 | 14 | from whoosh.analysis import RegexTokenizer, LowercaseFilter, StopFilter |
|
15 | 15 | from whoosh.fields import TEXT, ID, STORED, Schema |
|
16 | 16 | from whoosh.index import create_in, open_dir |
|
17 | 17 | from shutil import rmtree |
|
18 | 18 | |
|
19 | 19 | #LOCATION WE KEEP THE INDEX |
|
20 | 20 | IDX_LOCATION = jn(dn(dn(dn(dn(os.path.abspath(__file__))))), 'data', 'index') |
|
21 | 21 | |
|
22 |
#EXTENSION |
|
|
23 | EXCLUDE_EXTENSIONS = ['pyc', 'mo', 'png', 'jpg', 'jpeg', 'gif', 'swf', | |
|
24 | 'dll', 'ttf', 'psd', 'svg', 'pdf', 'bmp', 'dll'] | |
|
22 | #EXTENSIONS WE WANT TO INDEX CONTENT OFF | |
|
23 | INDEX_EXTENSIONS = ['action', 'adp', 'ashx', 'asmx', 'aspx', 'asx', 'axd', 'c', | |
|
24 | 'cfm', 'cpp', 'cs', 'css', 'diff', 'do', 'el', 'erl', 'h', | |
|
25 | 'htm', 'html', 'ini', 'java', 'js', 'jsp', 'jspx', 'lisp', | |
|
26 | 'lua', 'm', 'mako', 'ml', 'pas', 'patch', 'php', 'php3', | |
|
27 | 'php4', 'phtml', 'pm', 'py', 'rb', 'rst', 's', 'sh', 'sql', | |
|
28 | 'tpl', 'txt', 'vim', 'wss', 'xhtml', 'xml','xsl','xslt', | |
|
29 | 'yaws'] | |
|
25 | 30 | |
|
26 | 31 | #CUSTOM ANALYZER wordsplit + lowercase filter |
|
27 | ANALYZER = RegexTokenizer() | LowercaseFilter() | |
|
32 | ANALYZER = RegexTokenizer(expression=r"\w+") | LowercaseFilter() | |
|
28 | 33 | |
|
29 | 34 | #INDEX SCHEMA DEFINITION |
|
30 | 35 | SCHEMA = Schema(owner=TEXT(), |
|
31 | 36 | repository=TEXT(stored=True), |
|
32 | 37 | path=ID(stored=True, unique=True), |
|
33 | 38 | content=TEXT(stored=True, analyzer=ANALYZER), |
|
34 | modtime=STORED()) | |
|
39 | modtime=STORED(),extension=TEXT(stored=True)) | |
|
35 | 40 | |
|
36 |
IDX_NAME = 'HG_INDEX' |
|
|
41 | IDX_NAME = 'HG_INDEX' No newline at end of file |
@@ -1,181 +1,188 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | # whoosh indexer daemon for hg-app |
|
4 | 4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
5 | 5 | # |
|
6 | 6 | # This program is free software; you can redistribute it and/or |
|
7 | 7 | # modify it under the terms of the GNU General Public License |
|
8 | 8 | # as published by the Free Software Foundation; version 2 |
|
9 | 9 | # of the License or (at your opinion) any later version of the license. |
|
10 | 10 | # |
|
11 | 11 | # This program is distributed in the hope that it will be useful, |
|
12 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | 14 | # GNU General Public License for more details. |
|
15 | 15 | # |
|
16 | 16 | # You should have received a copy of the GNU General Public License |
|
17 | 17 | # along with this program; if not, write to the Free Software |
|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 | # MA 02110-1301, USA. |
|
20 | 20 | """ |
|
21 | 21 | Created on Jan 26, 2010 |
|
22 | 22 | |
|
23 | 23 | @author: marcink |
|
24 | 24 | A deamon will read from task table and run tasks |
|
25 | 25 | """ |
|
26 | 26 | import sys |
|
27 | 27 | import os |
|
28 | 28 | from os.path import dirname as dn |
|
29 | 29 | from os.path import join as jn |
|
30 | 30 | |
|
31 | 31 | #to get the pylons_app import |
|
32 | 32 | project_path = dn(dn(dn(dn(os.path.realpath(__file__))))) |
|
33 | 33 | sys.path.append(project_path) |
|
34 | 34 | |
|
35 | 35 | from pidlock import LockHeld, DaemonLock |
|
36 | 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, |
|
|
41 | from pylons_app.lib.indexers import ANALYZER, INDEX_EXTENSIONS, IDX_LOCATION, \ | |
|
42 | 42 | SCHEMA, IDX_NAME |
|
43 | 43 | |
|
44 | 44 | import logging |
|
45 | 45 | import logging.config |
|
46 | 46 | logging.config.fileConfig(jn(project_path, 'development.ini')) |
|
47 | 47 | log = logging.getLogger('whooshIndexer') |
|
48 | 48 | |
|
49 | 49 | def scan_paths(root_location): |
|
50 | 50 | return HgModel.repo_scan('/', root_location, None, True) |
|
51 | 51 | |
|
52 | 52 | class WhooshIndexingDaemon(object): |
|
53 | 53 | """Deamon for atomic jobs""" |
|
54 | 54 | |
|
55 | 55 | def __init__(self, indexname='HG_INDEX', repo_location=None): |
|
56 | 56 | self.indexname = indexname |
|
57 | 57 | self.repo_location = repo_location |
|
58 | 58 | |
|
59 | 59 | def get_paths(self, root_dir): |
|
60 | 60 | """recursive walk in root dir and return a set of all path in that dir |
|
61 | 61 | excluding files in .hg dir""" |
|
62 | 62 | index_paths_ = set() |
|
63 | 63 | for path, dirs, files in os.walk(root_dir): |
|
64 | 64 | if path.find('.hg') == -1: |
|
65 | 65 | for f in files: |
|
66 | 66 | index_paths_.add(jn(path, f)) |
|
67 | 67 | |
|
68 | 68 | return index_paths_ |
|
69 | 69 | |
|
70 | 70 | def add_doc(self, writer, path, repo): |
|
71 | 71 | """Adding doc to writer""" |
|
72 | 72 | |
|
73 | #we don't won't to read excluded file extensions just index them | |
|
74 | if path.split('/')[-1].split('.')[-1].lower() not in EXCLUDE_EXTENSIONS: | |
|
73 | ext = unicode(path.split('/')[-1].split('.')[-1].lower()) | |
|
74 | #we just index the content of choosen files | |
|
75 | if ext in INDEX_EXTENSIONS: | |
|
76 | log.debug(' >> %s [WITH CONTENT]' % path) | |
|
75 | 77 | fobj = open(path, 'rb') |
|
76 | 78 | content = fobj.read() |
|
77 | 79 | fobj.close() |
|
78 | 80 | try: |
|
79 | 81 | u_content = unicode(content) |
|
80 | 82 | except UnicodeDecodeError: |
|
81 | 83 | #incase we have a decode error just represent as byte string |
|
82 | 84 | u_content = unicode(str(content).encode('string_escape')) |
|
83 | 85 | else: |
|
86 | log.debug(' >> %s' % path) | |
|
87 | #just index file name without it's content | |
|
84 | 88 |
u_content = u'' |
|
89 | ||
|
85 | 90 | writer.add_document(owner=unicode(repo.contact), |
|
86 | 91 | repository=u"%s" % repo.name, |
|
87 | 92 | path=u"%s" % path, |
|
88 | 93 | content=u_content, |
|
89 |
modtime=os.path.getmtime(path) |
|
|
94 | modtime=os.path.getmtime(path), | |
|
95 | extension=ext) | |
|
90 | 96 | |
|
91 | 97 | def build_index(self): |
|
92 | 98 | if os.path.exists(IDX_LOCATION): |
|
99 | log.debug('removing previos index') | |
|
93 | 100 | rmtree(IDX_LOCATION) |
|
94 | 101 | |
|
95 | 102 | if not os.path.exists(IDX_LOCATION): |
|
96 | 103 | os.mkdir(IDX_LOCATION) |
|
97 | 104 | |
|
98 | 105 | idx = create_in(IDX_LOCATION, SCHEMA, indexname=IDX_NAME) |
|
99 | 106 | writer = idx.writer() |
|
100 | 107 | |
|
101 | 108 | for cnt, repo in enumerate(scan_paths(self.repo_location).values()): |
|
102 | 109 | log.debug('building index @ %s' % repo.path) |
|
103 | 110 | |
|
104 | 111 | for idx_path in self.get_paths(repo.path): |
|
105 | log.debug(' >> %s' % idx_path) | |
|
106 | 112 | self.add_doc(writer, idx_path, repo) |
|
107 | 113 | writer.commit(merge=True) |
|
108 | 114 | |
|
109 | 115 | log.debug('>>> FINISHED BUILDING INDEX <<<') |
|
110 | 116 | |
|
111 | 117 | |
|
112 | 118 | def update_index(self): |
|
113 | 119 | log.debug('STARTING INCREMENTAL INDEXING UPDATE') |
|
114 | 120 | |
|
115 | 121 | idx = open_dir(IDX_LOCATION, indexname=self.indexname) |
|
116 | 122 | # The set of all paths in the index |
|
117 | 123 | indexed_paths = set() |
|
118 | 124 | # The set of all paths we need to re-index |
|
119 | 125 | to_index = set() |
|
120 | 126 | |
|
121 | 127 | reader = idx.reader() |
|
122 | 128 | writer = idx.writer() |
|
123 | 129 | |
|
124 | 130 | # Loop over the stored fields in the index |
|
125 | 131 | for fields in reader.all_stored_fields(): |
|
126 | 132 | indexed_path = fields['path'] |
|
127 | 133 | indexed_paths.add(indexed_path) |
|
128 | 134 | |
|
129 | 135 | if not os.path.exists(indexed_path): |
|
130 | 136 | # This file was deleted since it was indexed |
|
131 | 137 | log.debug('removing from index %s' % indexed_path) |
|
132 | 138 | writer.delete_by_term('path', indexed_path) |
|
133 | 139 | |
|
134 | 140 | else: |
|
135 | 141 | # Check if this file was changed since it |
|
136 | 142 | # was indexed |
|
137 | 143 | indexed_time = fields['modtime'] |
|
138 | 144 | |
|
139 | 145 | mtime = os.path.getmtime(indexed_path) |
|
140 | 146 | |
|
141 | 147 | if mtime > indexed_time: |
|
142 | 148 | |
|
143 | 149 | # The file has changed, delete it and add it to the list of |
|
144 | 150 | # files to reindex |
|
145 | 151 | log.debug('adding to reindex list %s' % indexed_path) |
|
146 | 152 | writer.delete_by_term('path', indexed_path) |
|
147 | 153 | to_index.add(indexed_path) |
|
148 | 154 | #writer.commit() |
|
149 | 155 | |
|
150 | 156 | # Loop over the files in the filesystem |
|
151 | 157 | # Assume we have a function that gathers the filenames of the |
|
152 | 158 | # documents to be indexed |
|
153 | 159 | for repo in scan_paths(self.repo_location).values(): |
|
154 | 160 | for path in self.get_paths(repo.path): |
|
155 | 161 | if path in to_index or path not in indexed_paths: |
|
156 | 162 | # This is either a file that's changed, or a new file |
|
157 | 163 | # that wasn't indexed before. So index it! |
|
158 | 164 | self.add_doc(writer, path, repo) |
|
159 | 165 | log.debug('reindexing %s' % path) |
|
160 | 166 | |
|
161 | 167 | writer.commit(merge=True) |
|
162 | 168 | #idx.optimize() |
|
163 | 169 | log.debug('>>> FINISHED <<<') |
|
164 | 170 | |
|
165 | 171 | def run(self, full_index=False): |
|
166 | 172 | """Run daemon""" |
|
167 | 173 | if full_index: |
|
168 | 174 | self.build_index() |
|
169 | 175 | else: |
|
170 | 176 | self.update_index() |
|
171 | 177 | |
|
172 | 178 | if __name__ == "__main__": |
|
173 |
repo_location = '/home/marcink/ |
|
|
174 | ||
|
179 | repo_location = '/home/marcink/hg_repos/*' | |
|
180 | full_index = True # False means looking just for changes | |
|
175 | 181 | try: |
|
176 | 182 | l = DaemonLock() |
|
177 |
WhooshIndexingDaemon(repo_location=repo_location) |
|
|
183 | WhooshIndexingDaemon(repo_location=repo_location)\ | |
|
184 | .run(full_index=full_index) | |
|
178 | 185 | l.release() |
|
179 | 186 | except LockHeld: |
|
180 | 187 | sys.exit(1) |
|
181 | 188 |
General Comments 0
You need to be logged in to leave comments.
Login now