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