comparison rhodecode/lib/indexers/daemon.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3ยง14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents 5293d4bbb1ea
children e9f6b533a8f6
comparison
equal deleted inserted replaced
4115:8b7294a804a0 4116:ffd45b185016
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.lib.indexers.daemon
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 A daemon will read from task table and run tasks
7
8 :created_on: Jan 26, 2010
9 :author: marcink
10 :copyright: (C) 2010-2012 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 2 # 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 3 # 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 4 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version. 5 # (at your option) any later version.
17 # 6 #
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details. 10 # GNU General Public License for more details.
22 # 11 #
23 # You should have received a copy of the GNU General Public License 12 # 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/>. 13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 """
15 rhodecode.lib.indexers.daemon
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17
18 A daemon will read from task table and run tasks
19
20 :created_on: Jan 26, 2010
21 :author: marcink
22 :copyright: (c) 2013 RhodeCode GmbH.
23 :license: GPLv3, see LICENSE for more details.
24 """
25
25 from __future__ import with_statement 26 from __future__ import with_statement
26 27
27 import os 28 import os
28 import sys 29 import sys
29 import logging 30 import logging
109 'index does not exist') 110 'index does not exist')
110 else: 111 else:
111 self.initial = False 112 self.initial = False
112 113
113 def _get_index_revision(self, repo): 114 def _get_index_revision(self, repo):
114 db_repo = Repository.get_by_repo_name(repo.name) 115 db_repo = Repository.get_by_repo_name(repo.name_unicode)
115 landing_rev = 'tip' 116 landing_rev = 'tip'
116 if db_repo: 117 if db_repo:
117 landing_rev = db_repo.landing_rev 118 _rev_type, _rev = db_repo.landing_rev
119 landing_rev = _rev
118 return landing_rev 120 return landing_rev
119 121
120 def _get_index_changeset(self, repo): 122 def _get_index_changeset(self, repo, index_rev=None):
121 index_rev = self._get_index_revision(repo) 123 if not index_rev:
124 index_rev = self._get_index_revision(repo)
122 cs = repo.get_changeset(index_rev) 125 cs = repo.get_changeset(index_rev)
123 return cs 126 return cs
124 127
125 def get_paths(self, repo): 128 def get_paths(self, repo):
126 """ 129 """
137 except RepositoryError: 140 except RepositoryError:
138 log.debug(traceback.format_exc()) 141 log.debug(traceback.format_exc())
139 pass 142 pass
140 return index_paths_ 143 return index_paths_
141 144
142 def get_node(self, repo, path): 145 def get_node(self, repo, path, index_rev=None):
143 """ 146 """
144 gets a filenode based on given full path.It operates on string for 147 gets a filenode based on given full path.It operates on string for
145 hg git compatability. 148 hg git compatability.
146 149
147 :param repo: scm repo instance 150 :param repo: scm repo instance
148 :param path: full path including root location 151 :param path: full path including root location
149 :return: FileNode 152 :return: FileNode
150 """ 153 """
151 root_path = safe_str(repo.path)+'/' 154 root_path = safe_str(repo.path)+'/'
152 parts = safe_str(path).partition(root_path) 155 parts = safe_str(path).partition(root_path)
153 cs = self._get_index_changeset(repo) 156 cs = self._get_index_changeset(repo, index_rev=index_rev)
154 node = cs.get_node(parts[-1]) 157 node = cs.get_node(parts[-1])
155 return node 158 return node
156 159
157 def get_node_mtime(self, node): 160 def get_node_mtime(self, node):
158 return mktime(node.last_changeset.date.timetuple()) 161 return mktime(node.last_changeset.date.timetuple())
159 162
160 def add_doc(self, writer, path, repo, repo_name): 163 def add_doc(self, writer, path, repo, repo_name, index_rev=None):
161 """ 164 """
162 Adding doc to writer this function itself fetches data from 165 Adding doc to writer this function itself fetches data from
163 the instance of vcs backend 166 the instance of vcs backend
164 """ 167 """
165 168
166 node = self.get_node(repo, path) 169 node = self.get_node(repo, path, index_rev)
167 indexed = indexed_w_content = 0 170 indexed = indexed_w_content = 0
168 # we just index the content of chosen files, and skip binary files 171 # we just index the content of chosen files, and skip binary files
169 if node.extension in INDEX_EXTENSIONS and not node.is_binary: 172 if node.extension in INDEX_EXTENSIONS and not node.is_binary:
170 u_content = node.content 173 u_content = node.content
171 if not isinstance(u_content, unicode): 174 if not isinstance(u_content, unicode):
247 :param repo: instance of vcs repo 250 :param repo: instance of vcs repo
248 """ 251 """
249 i_cnt = iwc_cnt = 0 252 i_cnt = iwc_cnt = 0
250 log.debug('building index for %s @revision:%s' % (repo.path, 253 log.debug('building index for %s @revision:%s' % (repo.path,
251 self._get_index_revision(repo))) 254 self._get_index_revision(repo)))
255 index_rev = self._get_index_revision(repo)
252 for idx_path in self.get_paths(repo): 256 for idx_path in self.get_paths(repo):
253 i, iwc = self.add_doc(file_idx_writer, idx_path, repo, repo_name) 257 i, iwc = self.add_doc(file_idx_writer, idx_path, repo, repo_name, index_rev)
254 i_cnt += i 258 i_cnt += i
255 iwc_cnt += iwc 259 iwc_cnt += iwc
256 260
257 log.debug('added %s files %s with content for repo %s' % 261 log.debug('added %s files %s with content for repo %s' %
258 (i_cnt + iwc_cnt, iwc_cnt, repo.path)) 262 (i_cnt + iwc_cnt, iwc_cnt, repo.path))