annotate rhodecode/model/hg.py @ 661:673de12e6bf6 beta

added option to enable/disable of logger hooks from admin panel. some docs/setup updates
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 06 Nov 2010 00:37:21 +0100
parents ffd07396d315
children 070f32743632
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
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
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 535
diff changeset
27 from rhodecode.lib import helpers as h
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 535
diff changeset
28 from rhodecode.lib.utils import invalidate_cache
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 535
diff changeset
29 from rhodecode.lib.auth import HasRepoPermissionAny
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 535
diff changeset
30 from rhodecode.model import meta
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 535
diff changeset
31 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
32 from sqlalchemy.orm import joinedload
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
195
7109d15c6813 cleared prints leftoovers, and changed current user fetching in login controller
Marcin Kuzminski <marcin@python-works.com>
parents: 136
diff changeset
35 import sys
633
fcf599cd3404 Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
36 import time
fcf599cd3404 Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
37
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
38 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
39
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
40 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
41 from vcs.backends.hg import MercurialRepository
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
42 from vcs.backends.git import GitRepository
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
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
51 return HgModel().repo_scan(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
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
59 return HgModel().repo_scan(g.paths[0][1], g.baseui)
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
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,))
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
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):
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
77 """
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
78 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
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
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
81 def __init__(self, sa=None):
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
82 if not sa:
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
83 self.sa = meta.Session()
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
84 else:
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
85 self.sa = sa
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
86
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
87 def repo_scan(self, 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
88 """
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 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
90 repository itself. Return a dictionary of repository objects
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
91
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
92 :param repos_path: path to directory containing repositories
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
93 :param baseui
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
94 :param initial: initial scann
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
95 """
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
96 log.info('scanning for repositories in %s', repos_path)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
97
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
98 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
99 baseui = ui.ui()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
100
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
101 from rhodecode.lib.utils import get_repos
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
102 repos = get_repos(repos_path)
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
103
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
104
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
105 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
106 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
107 try:
248
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
108 #name = name.split('/')[-1]
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
109 if repos_list.has_key(name):
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
110 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
111 ' %s' % (name, path))
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
112 else:
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
113 if path[0] == 'hg':
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
114 repos_list[name] = MercurialRepository(path[1], baseui=baseui)
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
115 repos_list[name].name = name
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
116
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
117 if path[0] == 'git':
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
118 repos_list[name] = GitRepository(path[1])
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
119 repos_list[name].name = name
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
120
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
121 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
122 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
123 #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
124 #have db repos yet.
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
125 dbrepo = self.sa.query(Repository)\
531
6fc59ac322ca added info about forked repository in few places
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
126 .options(joinedload(Repository.fork))\
6fc59ac322ca added info about forked repository in few places
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
127 .filter(Repository.repo_name == name)\
6fc59ac322ca added info about forked repository in few places
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
128 .scalar()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
129
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
130 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
131 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
132 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
133 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
134 if dbrepo.user:
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 373
diff changeset
135 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
136 else:
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
137 repos_list[name].contact = self.sa.query(User)\
376
7fbf81447c6c Fixes #18, removing user, who owns some repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 373
diff changeset
138 .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
139 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
140 continue
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
141
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
142 return repos_list
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
143
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
144 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
145 for name, repo in _get_repos_cached().items():
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
146
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
147 if isinstance(repo, MercurialRepository) and repo._get_hidden():
73
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
148 #skip hidden web repository
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
149 continue
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
150
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
151 last_change = repo.last_change
450
c3236d7febad fixed, empty cs bug.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
152 tip = h.get_changeset_safe(repo, 'tip')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
153
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
154 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
155 tmp_d['name'] = repo.name
222
f7dadd356c79 fixed sorting of repos with big letters
Marcin Kuzminski <marcin@python-works.com>
parents: 195
diff changeset
156 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
157 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
158 tmp_d['description_sort'] = tmp_d['description']
80
928416088790 reimplemented summary page,
Marcin Kuzminski <marcin@python-blog.com>
parents: 74
diff changeset
159 tmp_d['last_change'] = last_change
633
fcf599cd3404 Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
160 tmp_d['last_change_sort'] = time.mktime(last_change.timetuple())
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 633
diff changeset
161 tmp_d['tip'] = tip.raw_id
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
162 tmp_d['tip_sort'] = tip.revision
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
163 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
164 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
165 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
166 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
167 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
168 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
169 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
170
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
171 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
172 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
173 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
174 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
175 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
176 #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
177 #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
178 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
179 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
180 return repo
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
181
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
182
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
183