Mercurial > kallithea
annotate rhodecode/model/hg_model.py @ 602:8d970b568c13
more tags fixing
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 12 Oct 2010 23:19:29 +0200 |
parents | 000b675e7c1d |
children |
rev | line source |
---|---|
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
2 # encoding: utf-8 |
569
000b675e7c1d
bumped version, some spelling fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
3 # Model for RhodeCode |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
373
3171614c0067
Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents:
368
diff
changeset
|
5 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
6 # This program is free software; you can redistribute it and/or |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
7 # modify it under the terms of the GNU General Public License |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
8 # as published by the Free Software Foundation; version 2 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
9 # of the License or (at your opinion) any later version of the license. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
10 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
14 # GNU General Public License for more details. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
15 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
16 # You should have received a copy of the GNU General Public License |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
17 # along with this program; if not, write to the Free Software |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
19 # MA 02110-1301, USA. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
20 """ |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
21 Created on April 9, 2010 |
569
000b675e7c1d
bumped version, some spelling fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
22 Model for RhodeCode |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
23 @author: marcink |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
24 """ |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
25 from beaker.cache import cache_region |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
26 from mercurial import ui |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
27 from mercurial.hgweb.hgwebdir_mod import findrepos |
373
3171614c0067
Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents:
368
diff
changeset
|
28 from pylons.i18n.translation import _ |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
535
diff
changeset
|
29 from rhodecode.lib import helpers as h |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
535
diff
changeset
|
30 from rhodecode.lib.utils import invalidate_cache |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
535
diff
changeset
|
31 from rhodecode.lib.auth import HasRepoPermissionAny |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
535
diff
changeset
|
32 from rhodecode.model import meta |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
535
diff
changeset
|
33 from rhodecode.model.db import Repository, User |
535
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
34 from sqlalchemy.orm import joinedload |
373
3171614c0067
Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents:
368
diff
changeset
|
35 from vcs.exceptions import RepositoryError, VCSError |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
36 import logging |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
37 import os |
195
7109d15c6813
cleared prints leftoovers, and changed current user fetching in login controller
Marcin Kuzminski <marcin@python-works.com>
parents:
136
diff
changeset
|
38 import sys |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
39 log = logging.getLogger(__name__) |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
40 |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
41 try: |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
42 from vcs.backends.hg import MercurialRepository |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
43 except ImportError: |
195
7109d15c6813
cleared prints leftoovers, and changed current user fetching in login controller
Marcin Kuzminski <marcin@python-works.com>
parents:
136
diff
changeset
|
44 sys.stderr.write('You have to import vcs module') |
95
a214462101d2
Change logic for more vcs based.
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
45 raise Exception('Unable to import vcs') |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
46 |
368
e9a6783f5502
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
47 def _get_repos_cached_initial(app_globals, initial): |
482
7afbc45aab28
added caching queries to hg-app
Marcin Kuzminski <marcin@python-works.com>
parents:
477
diff
changeset
|
48 """return cached dict with repos |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
49 """ |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
50 g = app_globals |
368
e9a6783f5502
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
51 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui, initial) |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
52 |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
53 @cache_region('long_term', 'cached_repo_list') |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
54 def _get_repos_cached(): |
482
7afbc45aab28
added caching queries to hg-app
Marcin Kuzminski <marcin@python-works.com>
parents:
477
diff
changeset
|
55 """return cached dict with repos |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
56 """ |
276
5e59f29edf66
changed way of getting repository in changelog. + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
57 log.info('getting all repositories list') |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
58 from pylons import app_globals as g |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
59 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
60 |
373
3171614c0067
Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents:
368
diff
changeset
|
61 @cache_region('super_short_term', 'cached_repos_switcher_list') |
3171614c0067
Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents:
368
diff
changeset
|
62 def _get_repos_switcher_cached(cached_repo_list): |
3171614c0067
Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents:
368
diff
changeset
|
63 repos_lst = [] |
488
853b9425742a
fixed sorting in repo list switcher and removed lower() since repo names can be have capital letters now
Marcin Kuzminski <marcin@python-works.com>
parents:
482
diff
changeset
|
64 for repo in [x for x in cached_repo_list.values()]: |
482
7afbc45aab28
added caching queries to hg-app
Marcin Kuzminski <marcin@python-works.com>
parents:
477
diff
changeset
|
65 if HasRepoPermissionAny('repository.write', 'repository.read', |
511
0fce1f9e4dce
removed .lower() from permission checking of cached repos list since repos can have capital letters now
Marcin Kuzminski <marcin@python-works.com>
parents:
488
diff
changeset
|
66 'repository.admin')(repo.name, 'main page check'): |
488
853b9425742a
fixed sorting in repo list switcher and removed lower() since repo names can be have capital letters now
Marcin Kuzminski <marcin@python-works.com>
parents:
482
diff
changeset
|
67 repos_lst.append((repo.name, repo.dbrepo.private,)) |
373
3171614c0067
Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents:
368
diff
changeset
|
68 |
511
0fce1f9e4dce
removed .lower() from permission checking of cached repos list since repos can have capital letters now
Marcin Kuzminski <marcin@python-works.com>
parents:
488
diff
changeset
|
69 return sorted(repos_lst, key=lambda k:k[0].lower()) |
373
3171614c0067
Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents:
368
diff
changeset
|
70 |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
71 @cache_region('long_term', 'full_changelog') |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
72 def _full_changelog_cached(repo_name): |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
73 log.info('getting full changelog for %s', repo_name) |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
74 return list(reversed(list(HgModel().get_repo(repo_name)))) |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
75 |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
76 class HgModel(object): |
482
7afbc45aab28
added caching queries to hg-app
Marcin Kuzminski <marcin@python-works.com>
parents:
477
diff
changeset
|
77 """Mercurial Model |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
78 """ |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
79 |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
80 def __init__(self): |
482
7afbc45aab28
added caching queries to hg-app
Marcin Kuzminski <marcin@python-works.com>
parents:
477
diff
changeset
|
81 pass |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
82 |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
83 @staticmethod |
368
e9a6783f5502
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
84 def repo_scan(repos_prefix, repos_path, baseui, initial=False): |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
85 """ |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
86 Listing of repositories in given path. This path should not be a |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
87 repository itself. Return a dictionary of repository objects |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
88 :param repos_path: path to directory it could take syntax with |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
89 * or ** for deep recursive displaying repositories |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
90 """ |
350
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
325
diff
changeset
|
91 sa = meta.Session() |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
92 def check_repo_dir(path): |
482
7afbc45aab28
added caching queries to hg-app
Marcin Kuzminski <marcin@python-works.com>
parents:
477
diff
changeset
|
93 """Checks the repository |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
94 :param path: |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
95 """ |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
96 repos_path = path.split('/') |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
97 if repos_path[-1] in ['*', '**']: |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
98 repos_path = repos_path[:-1] |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
99 if repos_path[0] != '/': |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
100 repos_path[0] = '/' |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
101 if not os.path.isdir(os.path.join(*repos_path)): |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
450
diff
changeset
|
102 raise RepositoryError('Not a valid repository in %s' % path) |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
103 if not repos_path.endswith('*'): |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
104 raise VCSError('You need to specify * or ** at the end of path ' |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
105 'for recursive scanning') |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
106 |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
107 check_repo_dir(repos_path) |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
108 log.info('scanning for repositories in %s', repos_path) |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
109 repos = findrepos([(repos_prefix, repos_path)]) |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
110 if not isinstance(baseui, ui.ui): |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
111 baseui = ui.ui() |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
112 |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
113 repos_list = {} |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
114 for name, path in repos: |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
115 try: |
248
fb7f066126cc
Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
116 #name = name.split('/')[-1] |
fb7f066126cc
Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
117 if repos_list.has_key(name): |
fb7f066126cc
Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
118 raise RepositoryError('Duplicate repository name %s found in' |
fb7f066126cc
Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
119 ' %s' % (name, path)) |
fb7f066126cc
Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
120 else: |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
121 |
248
fb7f066126cc
Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
122 repos_list[name] = MercurialRepository(path, baseui=baseui) |
fb7f066126cc
Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
123 repos_list[name].name = name |
368
e9a6783f5502
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
124 |
e9a6783f5502
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
125 dbrepo = None |
e9a6783f5502
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
126 if not initial: |
535
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
127 #for initial scann on application first run we don't |
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
128 #have db repos yet. |
368
e9a6783f5502
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
129 dbrepo = sa.query(Repository)\ |
531
6fc59ac322ca
added info about forked repository in few places
Marcin Kuzminski <marcin@python-works.com>
parents:
512
diff
changeset
|
130 .options(joinedload(Repository.fork))\ |
6fc59ac322ca
added info about forked repository in few places
Marcin Kuzminski <marcin@python-works.com>
parents:
512
diff
changeset
|
131 .filter(Repository.repo_name == name)\ |
6fc59ac322ca
added info about forked repository in few places
Marcin Kuzminski <marcin@python-works.com>
parents:
512
diff
changeset
|
132 .scalar() |
368
e9a6783f5502
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
133 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
134 if dbrepo: |
368
e9a6783f5502
fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
135 log.info('Adding db instance to cached list') |
303
3a66e7421a99
db model fix, added repo instance to cached repos list
Marcin Kuzminski <marcin@python-works.com>
parents:
281
diff
changeset
|
136 repos_list[name].dbrepo = dbrepo |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
137 repos_list[name].description = dbrepo.description |
376
7fbf81447c6c
Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
373
diff
changeset
|
138 if dbrepo.user: |
7fbf81447c6c
Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
373
diff
changeset
|
139 repos_list[name].contact = dbrepo.user.full_contact |
7fbf81447c6c
Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
373
diff
changeset
|
140 else: |
7fbf81447c6c
Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
373
diff
changeset
|
141 repos_list[name].contact = sa.query(User)\ |
7fbf81447c6c
Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
373
diff
changeset
|
142 .filter(User.admin == True).first().full_contact |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
143 except OSError: |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
144 continue |
350
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
325
diff
changeset
|
145 meta.Session.remove() |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
146 return repos_list |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
147 |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
148 def get_repos(self): |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
149 for name, repo in _get_repos_cached().items(): |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
150 if repo._get_hidden(): |
73
55d7f2502dfb
Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents:
68
diff
changeset
|
151 #skip hidden web repository |
55d7f2502dfb
Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents:
68
diff
changeset
|
152 continue |
55d7f2502dfb
Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents:
68
diff
changeset
|
153 |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
154 last_change = repo.last_change |
450
c3236d7febad
fixed, empty cs bug.
Marcin Kuzminski <marcin@python-works.com>
parents:
376
diff
changeset
|
155 tip = h.get_changeset_safe(repo, 'tip') |
136
36102488d634
Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents:
95
diff
changeset
|
156 |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
157 tmp_d = {} |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
158 tmp_d['name'] = repo.name |
222
f7dadd356c79
fixed sorting of repos with big letters
Marcin Kuzminski <marcin@python-works.com>
parents:
195
diff
changeset
|
159 tmp_d['name_sort'] = tmp_d['name'].lower() |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
160 tmp_d['description'] = repo.description |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
161 tmp_d['description_sort'] = tmp_d['description'] |
80
928416088790
reimplemented summary page,
Marcin Kuzminski <marcin@python-blog.com>
parents:
74
diff
changeset
|
162 tmp_d['last_change'] = last_change |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
163 tmp_d['last_change_sort'] = last_change[1] - last_change[0] |
512
d945c95ba4ac
refactoring for new vcs implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
511
diff
changeset
|
164 tmp_d['tip'] = tip.short_id |
136
36102488d634
Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents:
95
diff
changeset
|
165 tmp_d['tip_sort'] = tip.revision |
36102488d634
Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents:
95
diff
changeset
|
166 tmp_d['rev'] = tip.revision |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
167 tmp_d['contact'] = repo.contact |
73
55d7f2502dfb
Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents:
68
diff
changeset
|
168 tmp_d['contact_sort'] = tmp_d['contact'] |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
222
diff
changeset
|
169 tmp_d['repo_archives'] = list(repo._get_archives()) |
281
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
276
diff
changeset
|
170 tmp_d['last_msg'] = tip.message |
303
3a66e7421a99
db model fix, added repo instance to cached repos list
Marcin Kuzminski <marcin@python-works.com>
parents:
281
diff
changeset
|
171 tmp_d['repo'] = repo |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
172 yield tmp_d |
74
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
73
diff
changeset
|
173 |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
73
diff
changeset
|
174 def get_repo(self, repo_name): |
535
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
175 try: |
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
176 repo = _get_repos_cached()[repo_name] |
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
177 return repo |
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
178 except KeyError: |
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
179 #i we're here and we got key errors let's try to invalidate the |
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
180 #cahce and try again |
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
181 invalidate_cache('cached_repo_list') |
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
182 repo = _get_repos_cached()[repo_name] |
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
183 return repo |
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
184 |
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
185 |
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
531
diff
changeset
|
186 |