Mercurial > kallithea
annotate rhodecode/model/scm.py @ 1459:6691d4097344 beta
added author to main page tooltip
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 09 Sep 2011 19:54:23 +0300 |
parents | 7a46d67c263c |
children | 7b67b0dcad6d |
rev | line source |
---|---|
757
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
1 # -*- coding: utf-8 -*- |
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
2 """ |
811 | 3 rhodecode.model.scm |
4 ~~~~~~~~~~~~~~~~~~~ | |
757
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
5 |
811 | 6 Scm model for RhodeCode |
7 | |
757
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
8 :created_on: Apr 9, 2010 |
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
9 :author: marcink |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
757
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
12 """ |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
16 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
17 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
18 # 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
|
19 # 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
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
21 # GNU General Public License for more details. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
22 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
757
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
25 import os |
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
26 import time |
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
27 import traceback |
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
28 import logging |
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
29 |
1022
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1005
diff
changeset
|
30 from sqlalchemy.exc import DatabaseError |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1005
diff
changeset
|
31 |
757
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
32 from vcs import get_backend |
1437
7a46d67c263c
added welcome message if no repositories are present in current view
Marcin Kuzminski <marcin@python-works.com>
parents:
1428
diff
changeset
|
33 from vcs.exceptions import RepositoryError |
757
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
34 from vcs.utils.lazy import LazyProperty |
1311
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
35 from vcs.nodes import FileNode |
757
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
36 |
710
e2f3c8e6939d
Disable git support due to large problems with dulwich.
Marcin Kuzminski <marcin@python-works.com>
parents:
693
diff
changeset
|
37 from rhodecode import BACKENDS |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
535
diff
changeset
|
38 from rhodecode.lib import helpers as h |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1380
diff
changeset
|
39 from rhodecode.lib import safe_str |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
535
diff
changeset
|
40 from rhodecode.lib.auth import HasRepoPermissionAny |
1038
5554aa9c2480
another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents:
1033
diff
changeset
|
41 from rhodecode.lib.utils import get_repos as get_filesystem_repos, make_ui, \ |
5554aa9c2480
another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents:
1033
diff
changeset
|
42 action_logger |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
747
diff
changeset
|
43 from rhodecode.model import BaseModel |
758 | 44 from rhodecode.model.user import UserModel |
45 from rhodecode.model.db import Repository, RhodeCodeUi, CacheInvalidation, \ | |
784
30d3161c6683
Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents:
767
diff
changeset
|
46 UserFollowing, UserLog |
757
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
47 |
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
|
48 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
|
49 |
757
c52e88b57bf4
rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents:
753
diff
changeset
|
50 |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
51 class UserTemp(object): |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
52 def __init__(self, user_id): |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
53 self.user_id = user_id |
901
765c2125e4d9
Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents:
878
diff
changeset
|
54 |
765c2125e4d9
Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents:
878
diff
changeset
|
55 def __repr__(self): |
765c2125e4d9
Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents:
878
diff
changeset
|
56 return "<%s('id:%s')>" % (self.__class__.__name__, self.user_id) |
765c2125e4d9
Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents:
878
diff
changeset
|
57 |
1213
68e34f5cf122
#150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
58 |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
59 class RepoTemp(object): |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
60 def __init__(self, repo_id): |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
61 self.repo_id = repo_id |
747
2f89beda06a1
Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
62 |
901
765c2125e4d9
Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents:
878
diff
changeset
|
63 def __repr__(self): |
765c2125e4d9
Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents:
878
diff
changeset
|
64 return "<%s('id:%s')>" % (self.__class__.__name__, self.repo_id) |
765c2125e4d9
Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents:
878
diff
changeset
|
65 |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
66 class CachedRepoList(object): |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
67 |
1428
e5467730682b
fixed some issues with cache invalidation, and simplified invalidation codes
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
68 def __init__(self, db_repo_list, repos_path, order_by=None): |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
69 self.db_repo_list = db_repo_list |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
70 self.repos_path = repos_path |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
71 self.order_by = order_by |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
72 self.reversed = (order_by or '').startswith('-') |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
73 |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
74 def __len__(self): |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
75 return len(self.db_repo_list) |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
76 |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
77 def __repr__(self): |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
78 return '<%s (%s)>' % (self.__class__.__name__, self.__len__()) |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
79 |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
80 def __iter__(self): |
1428
e5467730682b
fixed some issues with cache invalidation, and simplified invalidation codes
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
81 for dbr in self.db_repo_list: |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
82 |
1428
e5467730682b
fixed some issues with cache invalidation, and simplified invalidation codes
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
83 scmr = dbr.scm_instance_cached |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
84 |
1437
7a46d67c263c
added welcome message if no repositories are present in current view
Marcin Kuzminski <marcin@python-works.com>
parents:
1428
diff
changeset
|
85 # check permission at this level |
7a46d67c263c
added welcome message if no repositories are present in current view
Marcin Kuzminski <marcin@python-works.com>
parents:
1428
diff
changeset
|
86 if not HasRepoPermissionAny('repository.read', 'repository.write', |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
87 'repository.admin')(dbr.repo_name, |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
88 'get repo check'): |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
89 continue |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
90 |
1380
39ae0f0972b9
Fixed problem with new repos, and visibility on the main list.
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
91 if scmr is None: |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1370
diff
changeset
|
92 log.error('%s this repository is present in database but it ' |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1370
diff
changeset
|
93 'cannot be created as an scm instance', |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1370
diff
changeset
|
94 dbr.repo_name) |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
1370
diff
changeset
|
95 continue |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
96 |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
97 last_change = scmr.last_change |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
98 tip = h.get_changeset_safe(scmr, 'tip') |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
99 |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
100 tmp_d = {} |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
101 tmp_d['name'] = dbr.repo_name |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
102 tmp_d['name_sort'] = tmp_d['name'].lower() |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
103 tmp_d['description'] = dbr.description |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
104 tmp_d['description_sort'] = tmp_d['description'] |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
105 tmp_d['last_change'] = last_change |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
106 tmp_d['last_change_sort'] = time.mktime(last_change \ |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
107 .timetuple()) |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
108 tmp_d['tip'] = tip.raw_id |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
109 tmp_d['tip_sort'] = tip.revision |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
110 tmp_d['rev'] = tip.revision |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
111 tmp_d['contact'] = dbr.user.full_contact |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
112 tmp_d['contact_sort'] = tmp_d['contact'] |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
113 tmp_d['owner_sort'] = tmp_d['contact'] |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
114 tmp_d['repo_archives'] = list(scmr._get_archives()) |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
115 tmp_d['last_msg'] = tip.message |
1459
6691d4097344
added author to main page tooltip
Marcin Kuzminski <marcin@python-works.com>
parents:
1437
diff
changeset
|
116 tmp_d['author'] = tip.author |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
117 tmp_d['dbrepo'] = dbr.get_dict() |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
118 tmp_d['dbrepo_fork'] = dbr.fork.get_dict() if dbr.fork \ |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
119 else {} |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
120 yield tmp_d |
1213
68e34f5cf122
#150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
121 |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
747
diff
changeset
|
122 class ScmModel(BaseModel): |
811 | 123 """Generic Scm 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
|
124 """ |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
125 |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
126 @LazyProperty |
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
127 def repos_path(self): |
811 | 128 """Get's the repositories root path from database |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
129 """ |
811 | 130 |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
131 q = self.sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one() |
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
132 |
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
133 return q.ui_value |
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
134 |
1038
5554aa9c2480
another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents:
1033
diff
changeset
|
135 def repo_scan(self, repos_path=None): |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
136 """Listing of repositories in given path. This path should not be a |
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 repository itself. Return a dictionary of repository objects |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
138 |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
139 :param repos_path: path to directory containing repositories |
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 """ |
811 | 141 |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
142 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
|
143 |
1038
5554aa9c2480
another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents:
1033
diff
changeset
|
144 if repos_path is None: |
5554aa9c2480
another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents:
1033
diff
changeset
|
145 repos_path = self.repos_path |
5554aa9c2480
another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents:
1033
diff
changeset
|
146 |
5554aa9c2480
another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents:
1033
diff
changeset
|
147 baseui = make_ui('db') |
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 repos_list = {} |
690
4685f3eafd35
Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
149 |
877
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
851
diff
changeset
|
150 for name, path in get_filesystem_repos(repos_path, recursive=True): |
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 try: |
1213
68e34f5cf122
#150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
152 if name in repos_list: |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
153 raise RepositoryError('Duplicate repository name %s ' |
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
154 'found in %s' % (name, path)) |
248
fb7f066126cc
Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
155 else: |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
156 |
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
157 klass = get_backend(path[0]) |
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
158 |
710
e2f3c8e6939d
Disable git support due to large problems with dulwich.
Marcin Kuzminski <marcin@python-works.com>
parents:
693
diff
changeset
|
159 if path[0] == 'hg' and path[0] in BACKENDS.keys(): |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1380
diff
changeset
|
160 |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1380
diff
changeset
|
161 # for mercurial we need to have an str path |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1380
diff
changeset
|
162 repos_list[name] = klass(safe_str(path[1]), |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1380
diff
changeset
|
163 baseui=baseui) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
164 |
710
e2f3c8e6939d
Disable git support due to large problems with dulwich.
Marcin Kuzminski <marcin@python-works.com>
parents:
693
diff
changeset
|
165 if path[0] == 'git' and path[0] in BACKENDS.keys(): |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
166 repos_list[name] = klass(path[1]) |
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 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
|
168 continue |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
169 |
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
|
170 return repos_list |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
171 |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
172 def get_repos(self, all_repos=None, sort_key=None): |
1343
a04fe5986109
#47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1312
diff
changeset
|
173 """ |
a04fe5986109
#47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1312
diff
changeset
|
174 Get all repos from db and for each repo create it's |
1213
68e34f5cf122
#150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
175 backend instance and fill that backed with information from database |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
176 |
1343
a04fe5986109
#47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1312
diff
changeset
|
177 :param all_repos: list of repository names as strings |
a04fe5986109
#47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1312
diff
changeset
|
178 give specific repositories list, good for filtering |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
179 """ |
767
632b0761e617
bugfix, when user had no repos he would see all repos in my account, (correct commit)
Marcin Kuzminski <marcin@python-works.com>
parents:
758
diff
changeset
|
180 if all_repos is None: |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
181 all_repos = self.sa.query(Repository)\ |
1343
a04fe5986109
#47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1312
diff
changeset
|
182 .filter(Repository.group_id == None)\ |
1193
523382549c45
Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents:
1114
diff
changeset
|
183 .order_by(Repository.repo_name).all() |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
184 |
1428
e5467730682b
fixed some issues with cache invalidation, and simplified invalidation codes
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
185 repo_iter = CachedRepoList(all_repos, repos_path=self.repos_path, |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
186 order_by=sort_key) |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
187 |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1343
diff
changeset
|
188 return repo_iter |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
189 |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
190 def mark_for_invalidation(self, repo_name): |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
191 """Puts cache invalidation task into db for |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
192 further global cache invalidation |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
193 |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
194 :param repo_name: this repo that should invalidation take place |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
195 """ |
811 | 196 |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
197 log.debug('marking %s for invalidation', repo_name) |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
198 cache = self.sa.query(CacheInvalidation)\ |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
199 .filter(CacheInvalidation.cache_key == repo_name).scalar() |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
200 |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
201 if cache: |
1428
e5467730682b
fixed some issues with cache invalidation, and simplified invalidation codes
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
202 # mark this cache as inactive |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
203 cache.cache_active = False |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
204 else: |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
205 log.debug('cache key not found in invalidation db -> creating one') |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
206 cache = CacheInvalidation(repo_name) |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
207 |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
208 try: |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
209 self.sa.add(cache) |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
210 self.sa.commit() |
758 | 211 except (DatabaseError,): |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
212 log.error(traceback.format_exc()) |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
213 self.sa.rollback() |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
214 |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
215 def toggle_following_repo(self, follow_repo_id, user_id): |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
216 |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
217 f = self.sa.query(UserFollowing)\ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
218 .filter(UserFollowing.follows_repo_id == follow_repo_id)\ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
219 .filter(UserFollowing.user_id == user_id).scalar() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
220 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
221 if f is not None: |
747
2f89beda06a1
Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
222 |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
223 try: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
224 self.sa.delete(f) |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
225 self.sa.commit() |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
226 action_logger(UserTemp(user_id), |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
227 'stopped_following_repo', |
747
2f89beda06a1
Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
228 RepoTemp(follow_repo_id)) |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
229 return |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
230 except: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
231 log.error(traceback.format_exc()) |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
232 self.sa.rollback() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
233 raise |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
234 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
235 try: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
236 f = UserFollowing() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
237 f.user_id = user_id |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
238 f.follows_repo_id = follow_repo_id |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
239 self.sa.add(f) |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
240 self.sa.commit() |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
241 action_logger(UserTemp(user_id), |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
734
diff
changeset
|
242 'started_following_repo', |
747
2f89beda06a1
Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
243 RepoTemp(follow_repo_id)) |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
244 except: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
245 log.error(traceback.format_exc()) |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
246 self.sa.rollback() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
247 raise |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
248 |
1213
68e34f5cf122
#150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
249 def toggle_following_user(self, follow_user_id, user_id): |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
250 f = self.sa.query(UserFollowing)\ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
251 .filter(UserFollowing.follows_user_id == follow_user_id)\ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
252 .filter(UserFollowing.user_id == user_id).scalar() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
253 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
254 if f is not None: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
255 try: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
256 self.sa.delete(f) |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
257 self.sa.commit() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
258 return |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
259 except: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
260 log.error(traceback.format_exc()) |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
261 self.sa.rollback() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
262 raise |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
263 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
264 try: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
265 f = UserFollowing() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
266 f.user_id = user_id |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
267 f.follows_user_id = follow_user_id |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
268 self.sa.add(f) |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
269 self.sa.commit() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
270 except: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
271 log.error(traceback.format_exc()) |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
272 self.sa.rollback() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
273 raise |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
274 |
999
1951c35483ab
fixed following js snipet. It' can be called multiple times now next to each repository
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
275 def is_following_repo(self, repo_name, user_id, cache=False): |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
276 r = self.sa.query(Repository)\ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
277 .filter(Repository.repo_name == repo_name).scalar() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
278 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
279 f = self.sa.query(UserFollowing)\ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
280 .filter(UserFollowing.follows_repository == r)\ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
281 .filter(UserFollowing.user_id == user_id).scalar() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
282 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
283 return f is not None |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
284 |
999
1951c35483ab
fixed following js snipet. It' can be called multiple times now next to each repository
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
285 def is_following_user(self, username, user_id, cache=False): |
758 | 286 u = UserModel(self.sa).get_by_username(username) |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
287 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
288 f = self.sa.query(UserFollowing)\ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
289 .filter(UserFollowing.follows_user == u)\ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
290 .filter(UserFollowing.user_id == user_id).scalar() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
291 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
726
diff
changeset
|
292 return f is not None |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
293 |
747
2f89beda06a1
Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
294 def get_followers(self, repo_id): |
1282
faaadfc3c359
fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1265
diff
changeset
|
295 if not isinstance(repo_id, int): |
faaadfc3c359
fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1265
diff
changeset
|
296 repo_id = getattr(Repository.by_repo_name(repo_id), 'repo_id') |
faaadfc3c359
fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1265
diff
changeset
|
297 |
faaadfc3c359
fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1265
diff
changeset
|
298 return self.sa.query(UserFollowing)\ |
faaadfc3c359
fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1265
diff
changeset
|
299 .filter(UserFollowing.follows_repo_id == repo_id).count() |
747
2f89beda06a1
Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
300 |
2f89beda06a1
Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
301 def get_forks(self, repo_id): |
1282
faaadfc3c359
fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1265
diff
changeset
|
302 if not isinstance(repo_id, int): |
faaadfc3c359
fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1265
diff
changeset
|
303 repo_id = getattr(Repository.by_repo_name(repo_id), 'repo_id') |
faaadfc3c359
fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1265
diff
changeset
|
304 |
faaadfc3c359
fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1265
diff
changeset
|
305 return self.sa.query(Repository)\ |
747
2f89beda06a1
Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
306 .filter(Repository.fork_id == repo_id).count() |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
307 |
1114
4de3fa6290a7
#109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
308 def pull_changes(self, repo_name, username): |
1370
ef9a30e22ea6
Fixed remote pull command from todays code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
309 dbrepo = Repository.by_repo_name(repo_name) |
ef9a30e22ea6
Fixed remote pull command from todays code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
310 repo = dbrepo.scm_instance |
1114
4de3fa6290a7
#109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
311 try: |
1213
68e34f5cf122
#150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
312 extras = {'ip': '', |
68e34f5cf122
#150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
313 'username': username, |
68e34f5cf122
#150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
314 'action': 'push_remote', |
68e34f5cf122
#150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
315 'repository': repo_name} |
1114
4de3fa6290a7
#109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
316 |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
317 #inject ui extra param to log this action via push logger |
1114
4de3fa6290a7
#109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
318 for k, v in extras.items(): |
4de3fa6290a7
#109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
319 repo._repo.ui.setconfig('rhodecode_extras', k, v) |
4de3fa6290a7
#109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
320 |
4de3fa6290a7
#109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
321 repo.pull(dbrepo.clone_uri) |
4de3fa6290a7
#109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
322 self.mark_for_invalidation(repo_name) |
4de3fa6290a7
#109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
323 except: |
4de3fa6290a7
#109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
324 log.error(traceback.format_exc()) |
4de3fa6290a7
#109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
325 raise |
4de3fa6290a7
#109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
326 |
1311
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
327 |
1312
70a5a9a57864
logged local commit with special action via action_logger,
Marcin Kuzminski <marcin@python-works.com>
parents:
1311
diff
changeset
|
328 def commit_change(self, repo, repo_name, cs, user, author, message, content, |
1311
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
329 f_path): |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
330 |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
331 if repo.alias == 'hg': |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
332 from vcs.backends.hg import MercurialInMemoryChangeset as IMC |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
333 elif repo.alias == 'git': |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
334 from vcs.backends.git import GitInMemoryChangeset as IMC |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
335 |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
336 # decoding here will force that we have proper encoded values |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
337 # in any other case this will throw exceptions and deny commit |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1380
diff
changeset
|
338 content = safe_str(content) |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1380
diff
changeset
|
339 message = safe_str(message) |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1380
diff
changeset
|
340 path = safe_str(f_path) |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1380
diff
changeset
|
341 author = safe_str(author) |
1311
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
342 m = IMC(repo) |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
343 m.change(FileNode(path, content)) |
1312
70a5a9a57864
logged local commit with special action via action_logger,
Marcin Kuzminski <marcin@python-works.com>
parents:
1311
diff
changeset
|
344 tip = m.commit(message=message, |
1311
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
345 author=author, |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
346 parents=[cs], branch=cs.branch) |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
347 |
1312
70a5a9a57864
logged local commit with special action via action_logger,
Marcin Kuzminski <marcin@python-works.com>
parents:
1311
diff
changeset
|
348 new_cs = tip.short_id |
70a5a9a57864
logged local commit with special action via action_logger,
Marcin Kuzminski <marcin@python-works.com>
parents:
1311
diff
changeset
|
349 action = 'push_local:%s' % new_cs |
70a5a9a57864
logged local commit with special action via action_logger,
Marcin Kuzminski <marcin@python-works.com>
parents:
1311
diff
changeset
|
350 |
70a5a9a57864
logged local commit with special action via action_logger,
Marcin Kuzminski <marcin@python-works.com>
parents:
1311
diff
changeset
|
351 action_logger(user, action, repo_name) |
70a5a9a57864
logged local commit with special action via action_logger,
Marcin Kuzminski <marcin@python-works.com>
parents:
1311
diff
changeset
|
352 |
1311
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
353 self.mark_for_invalidation(repo_name) |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
354 |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1282
diff
changeset
|
355 |
784
30d3161c6683
Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents:
767
diff
changeset
|
356 def get_unread_journal(self): |
30d3161c6683
Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents:
767
diff
changeset
|
357 return self.sa.query(UserLog).count() |
30d3161c6683
Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents:
767
diff
changeset
|
358 |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
359 def _should_invalidate(self, repo_name): |
811 | 360 """Looks up database for invalidation signals for this repo_name |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
361 |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
362 :param repo_name: |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
363 """ |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
364 |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
365 ret = self.sa.query(CacheInvalidation)\ |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
366 .filter(CacheInvalidation.cache_key == repo_name)\ |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
367 .filter(CacheInvalidation.cache_active == False)\ |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
368 .scalar() |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
369 |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
370 return ret |