Mercurial > kallithea
comparison pylons_app/model/hg_model.py @ 368:e9a6783f5502
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators
Small fix for hg model and injecting dbrepo into cached repos
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 27 Jul 2010 14:54:41 +0200 |
parents | 664a5b8c551a |
children | 3171614c0067 |
comparison
equal
deleted
inserted
replaced
367:a26f48ad7a8a | 368:e9a6783f5502 |
---|---|
15 # | 15 # |
16 # You should have received a copy of the GNU General Public License | 16 # You should have received a copy of the GNU General Public License |
17 # along with this program; if not, write to the Free Software | 17 # along with this program; if not, write to the Free Software |
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
19 # MA 02110-1301, USA. | 19 # MA 02110-1301, USA. |
20 | |
21 """ | 20 """ |
22 Created on April 9, 2010 | 21 Created on April 9, 2010 |
23 Model for hg app | 22 Model for hg app |
24 @author: marcink | 23 @author: marcink |
25 """ | 24 """ |
26 | |
27 from beaker.cache import cache_region | 25 from beaker.cache import cache_region |
28 from mercurial import ui | 26 from mercurial import ui |
29 from mercurial.hgweb.hgwebdir_mod import findrepos | 27 from mercurial.hgweb.hgwebdir_mod import findrepos |
30 from vcs.exceptions import RepositoryError, VCSError | 28 from vcs.exceptions import RepositoryError, VCSError |
31 from pylons_app.model import meta | 29 from pylons_app.model import meta |
40 from vcs.backends.hg import MercurialRepository | 38 from vcs.backends.hg import MercurialRepository |
41 except ImportError: | 39 except ImportError: |
42 sys.stderr.write('You have to import vcs module') | 40 sys.stderr.write('You have to import vcs module') |
43 raise Exception('Unable to import vcs') | 41 raise Exception('Unable to import vcs') |
44 | 42 |
45 def _get_repos_cached_initial(app_globals): | 43 def _get_repos_cached_initial(app_globals, initial): |
46 """ | 44 """ |
47 return cached dict with repos | 45 return cached dict with repos |
48 """ | 46 """ |
49 g = app_globals | 47 g = app_globals |
50 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) | 48 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui, initial) |
51 | 49 |
52 @cache_region('long_term', 'cached_repo_list') | 50 @cache_region('long_term', 'cached_repo_list') |
53 def _get_repos_cached(): | 51 def _get_repos_cached(): |
54 """ | 52 """ |
55 return cached dict with repos | 53 return cached dict with repos |
72 """ | 70 """ |
73 Constructor | 71 Constructor |
74 """ | 72 """ |
75 | 73 |
76 @staticmethod | 74 @staticmethod |
77 def repo_scan(repos_prefix, repos_path, baseui): | 75 def repo_scan(repos_prefix, repos_path, baseui, initial=False): |
78 """ | 76 """ |
79 Listing of repositories in given path. This path should not be a | 77 Listing of repositories in given path. This path should not be a |
80 repository itself. Return a dictionary of repository objects | 78 repository itself. Return a dictionary of repository objects |
81 :param repos_path: path to directory it could take syntax with | 79 :param repos_path: path to directory it could take syntax with |
82 * or ** for deep recursive displaying repositories | 80 * or ** for deep recursive displaying repositories |
113 ' %s' % (name, path)) | 111 ' %s' % (name, path)) |
114 else: | 112 else: |
115 | 113 |
116 repos_list[name] = MercurialRepository(path, baseui=baseui) | 114 repos_list[name] = MercurialRepository(path, baseui=baseui) |
117 repos_list[name].name = name | 115 repos_list[name].name = name |
118 dbrepo = sa.query(Repository).get(name) | 116 |
117 dbrepo = None | |
118 if not initial: | |
119 dbrepo = sa.query(Repository)\ | |
120 .filter(Repository.repo_name == name).scalar() | |
121 | |
119 if dbrepo: | 122 if dbrepo: |
123 log.info('Adding db instance to cached list') | |
120 repos_list[name].dbrepo = dbrepo | 124 repos_list[name].dbrepo = dbrepo |
121 repos_list[name].description = dbrepo.description | 125 repos_list[name].description = dbrepo.description |
122 repos_list[name].contact = dbrepo.user.full_contact | 126 repos_list[name].contact = dbrepo.user.full_contact |
123 except OSError: | 127 except OSError: |
124 continue | 128 continue |