annotate pylons_app/model/hg_model.py @ 512:d945c95ba4ac

refactoring for new vcs implementation renamed all ._short and .raw_id into .short_id updated dependency for vcs to 0.1.6
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 28 Sep 2010 20:25:58 +0000
parents 0fce1f9e4dce
children 6fc59ac322ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
3 # Model for hg app
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
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
22 Model for hg app
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 _
3171614c0067 Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
29 from pylons_app.lib.auth import HasRepoPermissionAny
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 325
diff changeset
30 from pylons_app.model import meta
376
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 373
diff changeset
31 from pylons_app.model.db import Repository, User
450
c3236d7febad fixed, empty cs bug.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
32 from pylons_app.lib import helpers as h
373
3171614c0067 Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
33 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
34 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
35 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
36 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
37 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
38
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
39 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
40 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
41 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
42 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
43 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
44
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
45 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
46 """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
47 """
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
48 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
49 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
50
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
51 @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
52 def _get_repos_cached():
482
7afbc45aab28 added caching queries to hg-app
Marcin Kuzminski <marcin@python-works.com>
parents: 477
diff changeset
53 """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
54 """
276
5e59f29edf66 changed way of getting repository in changelog. + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
55 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
56 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
57 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
58
373
3171614c0067 Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
59 @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
60 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
61 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
62 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
63 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
64 '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
65 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
66
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
67 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
68
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
69 @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
70 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
71 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
72 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
73
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
74 class HgModel(object):
482
7afbc45aab28 added caching queries to hg-app
Marcin Kuzminski <marcin@python-works.com>
parents: 477
diff changeset
75 """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
76 """
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
77
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 def __init__(self):
482
7afbc45aab28 added caching queries to hg-app
Marcin Kuzminski <marcin@python-works.com>
parents: 477
diff changeset
79 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
80
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
81 @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
82 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
83 """
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
84 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
85 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
86 :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
87 * 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
88 """
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 325
diff changeset
89 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
90 def check_repo_dir(path):
482
7afbc45aab28 added caching queries to hg-app
Marcin Kuzminski <marcin@python-works.com>
parents: 477
diff changeset
91 """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
92 :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
93 """
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 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
95 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
96 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
97 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
98 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
99 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
100 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
101 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
102 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
103 '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
104
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 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
106 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
107 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
108 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
109 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
110
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 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
112 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
113 try:
248
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
114 #name = name.split('/')[-1]
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
115 if repos_list.has_key(name):
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
116 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
117 ' %s' % (name, path))
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
118 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
119
248
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
120 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
121 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
122
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
123 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
124 if not initial:
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 = sa.query(Repository)\
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 .filter(Repository.repo_name == name).scalar()
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
127
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
128 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
129 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
130 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
131 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
132 if dbrepo.user:
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 373
diff changeset
133 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
134 else:
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 373
diff changeset
135 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
136 .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
137 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
138 continue
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 325
diff changeset
139 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
140 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
141
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
142 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
143 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
144 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
145 #skip hidden web repository
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
146 continue
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
147
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
148 last_change = repo.last_change
450
c3236d7febad fixed, empty cs bug.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
149 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
150
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
151 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
152 tmp_d['name'] = repo.name
222
f7dadd356c79 fixed sorting of repos with big letters
Marcin Kuzminski <marcin@python-works.com>
parents: 195
diff changeset
153 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
154 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
155 tmp_d['description_sort'] = tmp_d['description']
80
928416088790 reimplemented summary page,
Marcin Kuzminski <marcin@python-blog.com>
parents: 74
diff changeset
156 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
157 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
158 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
159 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
160 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
161 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
162 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
163 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
164 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
165 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
166 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
167
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
168 def get_repo(self, repo_name):
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 return _get_repos_cached()[repo_name]