Show More
@@ -0,0 +1,111 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | """ | |
|
3 | rhodecode.lib.paster_commands.make_index | |
|
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
|
5 | ||
|
6 | make-index paster command for RhodeCode | |
|
7 | ||
|
8 | :created_on: Aug 17, 2010 | |
|
9 | :author: marcink | |
|
10 | :copyright: (C) 2010-2013 Marcin Kuzminski <marcin@python-works.com> | |
|
11 | :license: GPLv3, see COPYING for more details. | |
|
12 | """ | |
|
13 | # This program is free software: you can redistribute it and/or modify | |
|
14 | # it under the terms of the GNU General Public License as published by | |
|
15 | # the Free Software Foundation, either version 3 of the License, or | |
|
16 | # (at your option) any later version. | |
|
17 | # | |
|
18 | # This program is distributed in the hope that it will be useful, | |
|
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
21 | # GNU General Public License for more details. | |
|
22 | # | |
|
23 | # You should have received a copy of the GNU General Public License | |
|
24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
|
25 | from __future__ import with_statement | |
|
26 | ||
|
27 | import os | |
|
28 | import sys | |
|
29 | import logging | |
|
30 | ||
|
31 | from rhodecode.lib.utils import BasePasterCommand | |
|
32 | from string import strip | |
|
33 | from shutil import rmtree | |
|
34 | from rhodecode.model.repo import RepoModel | |
|
35 | from rhodecode.lib.utils import BasePasterCommand, load_rcextensions | |
|
36 | ||
|
37 | # fix rhodecode import | |
|
38 | from os.path import dirname as dn | |
|
39 | rc_path = dn(dn(dn(os.path.realpath(__file__)))) | |
|
40 | sys.path.append(rc_path) | |
|
41 | ||
|
42 | ||
|
43 | class Command(BasePasterCommand): | |
|
44 | ||
|
45 | max_args = 1 | |
|
46 | min_args = 1 | |
|
47 | ||
|
48 | usage = "CONFIG_FILE" | |
|
49 | group_name = "RhodeCode" | |
|
50 | takes_config_file = -1 | |
|
51 | parser = BasePasterCommand.standard_parser(verbose=True) | |
|
52 | summary = "Creates or updates full text search index" | |
|
53 | ||
|
54 | def command(self): | |
|
55 | logging.config.fileConfig(self.path_to_ini_file) | |
|
56 | #get SqlAlchemy session | |
|
57 | self._init_session() | |
|
58 | from pylons import config | |
|
59 | index_location = config['index_dir'] | |
|
60 | load_rcextensions(config['here']) | |
|
61 | ||
|
62 | repo_location = self.options.repo_location \ | |
|
63 | if self.options.repo_location else RepoModel().repos_path | |
|
64 | repo_list = map(strip, self.options.repo_list.split(',')) \ | |
|
65 | if self.options.repo_list else None | |
|
66 | ||
|
67 | repo_update_list = map(strip, self.options.repo_update_list.split(',')) \ | |
|
68 | if self.options.repo_update_list else None | |
|
69 | ||
|
70 | #====================================================================== | |
|
71 | # WHOOSH DAEMON | |
|
72 | #====================================================================== | |
|
73 | from rhodecode.lib.pidlock import LockHeld, DaemonLock | |
|
74 | from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon | |
|
75 | try: | |
|
76 | l = DaemonLock(file_=os.path.join(dn(dn(index_location)), | |
|
77 | 'make_index.lock')) | |
|
78 | WhooshIndexingDaemon(index_location=index_location, | |
|
79 | repo_location=repo_location, | |
|
80 | repo_list=repo_list, | |
|
81 | repo_update_list=repo_update_list)\ | |
|
82 | .run(full_index=self.options.full_index) | |
|
83 | l.release() | |
|
84 | except LockHeld: | |
|
85 | sys.exit(1) | |
|
86 | ||
|
87 | def update_parser(self): | |
|
88 | self.parser.add_option('--repo-location', | |
|
89 | action='store', | |
|
90 | dest='repo_location', | |
|
91 | help="Specifies repositories location to index OPTIONAL", | |
|
92 | ) | |
|
93 | self.parser.add_option('--index-only', | |
|
94 | action='store', | |
|
95 | dest='repo_list', | |
|
96 | help="Specifies a comma separated list of repositores " | |
|
97 | "to build index on. If not given all repositories " | |
|
98 | "are scanned for indexing. OPTIONAL", | |
|
99 | ) | |
|
100 | self.parser.add_option('--update-only', | |
|
101 | action='store', | |
|
102 | dest='repo_update_list', | |
|
103 | help="Specifies a comma separated list of repositores " | |
|
104 | "to re-build index on. OPTIONAL", | |
|
105 | ) | |
|
106 | self.parser.add_option('-f', | |
|
107 | action='store_true', | |
|
108 | dest='full_index', | |
|
109 | help="Specifies that index should be made full i.e" | |
|
110 | " destroy old and build from scratch", | |
|
111 | default=False) |
General Comments 0
You need to be logged in to leave comments.
Login now