Mercurial > kallithea
annotate rhodecode/model/repo.py @ 723:bf26b46e82d6 beta
some tests update
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 18 Nov 2010 23:11:51 +0100 |
parents | b9bbc0d6e9f3 |
children | dbec976d9975 |
rev | line source |
---|---|
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 # encoding: utf-8 |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 # model for handling repositories actions |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 # This program is free software; you can redistribute it and/or |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 # modify it under the terms of the GNU General Public License |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 # as published by the Free Software Foundation; version 2 |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 # of the License or (at your opinion) any later version of the license. |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 # |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 # This program is distributed in the hope that it will be useful, |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # GNU General Public License for more details. |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # You should have received a copy of the GNU General Public License |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # along with this program; if not, write to the Free Software |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # MA 02110-1301, USA. |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 """ |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 Created on Jun 5, 2010 |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 model for handling repositories actions |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
22 :author: marcink |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 """ |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
651
diff
changeset
|
24 from vcs.backends import get_repo, get_backend |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
25 from datetime import datetime |
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
26 from pylons import app_globals as g |
708
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
27 from rhodecode.model.db import Repository, RepoToPerm, User, Permission, \ |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
28 Statistics |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
530
diff
changeset
|
29 from rhodecode.model.meta import Session |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
30 from rhodecode.model.user import UserModel |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
31 from rhodecode.model.caching_query import FromCache |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
32 import logging |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 import os |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
34 import shutil |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
35 import traceback |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 log = logging.getLogger(__name__) |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 class RepoModel(object): |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
39 |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
668
diff
changeset
|
40 def __init__(self): |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
668
diff
changeset
|
41 self.sa = Session() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
42 |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
43 def get(self, repo_id, cache=False): |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
44 repo = self.sa.query(Repository)\ |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
45 .filter(Repository.repo_name == repo_id) |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
46 |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
47 if cache: |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
48 repo = repo.options(FromCache("sql_cache_short", |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
49 "get_repo_%s" % repo)) |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
50 return repo.scalar() |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
51 |
298
15e96b5a2685
autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents:
296
diff
changeset
|
52 def get_users_js(self): |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
53 |
328
cec5cbc956c0
Repository managment permissions, fixed found bugs updated js, added extra checks for doubled users and non active ones
Marcin Kuzminski <marcin@python-works.com>
parents:
299
diff
changeset
|
54 users = self.sa.query(User).filter(User.active == True).all() |
298
15e96b5a2685
autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents:
296
diff
changeset
|
55 u_tmpl = '''{id:%s, fname:"%s", lname:"%s", nname:"%s"},''' |
15e96b5a2685
autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents:
296
diff
changeset
|
56 users_array = '[%s];' % '\n'.join([u_tmpl % (u.user_id, u.name, |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
57 u.lastname, u.username) |
298
15e96b5a2685
autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents:
296
diff
changeset
|
58 for u in users]) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
59 return users_array |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
60 |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
61 |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
62 def update(self, repo_name, form_data): |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 try: |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
64 |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
65 #update permissions |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
66 for username, perm in form_data['perms_updates']: |
399
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
67 r2p = self.sa.query(RepoToPerm)\ |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
668
diff
changeset
|
68 .filter(RepoToPerm.user == UserModel().get_by_username(username, cache=False))\ |
399
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
69 .filter(RepoToPerm.repository == self.get(repo_name))\ |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
70 .one() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
71 |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
72 r2p.permission_id = self.sa.query(Permission).filter( |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
73 Permission.permission_name == |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
74 perm).one().permission_id |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
75 self.sa.add(r2p) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
76 |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
77 #set new permissions |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
78 for username, perm in form_data['perms_new']: |
399
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
79 r2p = RepoToPerm() |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
80 r2p.repository = self.get(repo_name) |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
668
diff
changeset
|
81 r2p.user = UserModel().get_by_username(username, cache=False) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
82 |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
83 r2p.permission_id = self.sa.query(Permission).filter( |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
84 Permission.permission_name == perm)\ |
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
85 .one().permission_id |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
86 self.sa.add(r2p) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
87 |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
88 #update current repo |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
89 cur_repo = self.get(repo_name, cache=False) |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
90 |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
91 for k, v in form_data.items(): |
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
92 if k == 'user': |
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
93 cur_repo.user_id = v |
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
94 else: |
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
95 setattr(cur_repo, k, v) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
96 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 self.sa.add(cur_repo) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
98 |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
99 if repo_name != form_data['repo_name']: |
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
100 #rename our data |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
101 self.__rename_repo(repo_name, form_data['repo_name']) |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
102 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 self.sa.commit() |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
104 except: |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
105 log.error(traceback.format_exc()) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
106 self.sa.rollback() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
107 raise |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
108 |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
109 def create(self, form_data, cur_user, just_db=False, fork=False): |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
110 try: |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
111 if fork: |
651
ae292c3b94ed
some css updates.
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
112 #force str since hg doesn't go with unicode |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
113 repo_name = str(form_data['fork_name']) |
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
114 org_name = str(form_data['repo_name']) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
115 |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
116 else: |
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
117 org_name = repo_name = str(form_data['repo_name']) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
118 new_repo = Repository() |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 for k, v in form_data.items(): |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
120 if k == 'repo_name': |
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
121 v = repo_name |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
122 setattr(new_repo, k, v) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
123 |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
124 if fork: |
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
125 parent_repo = self.sa.query(Repository)\ |
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
126 .filter(Repository.repo_name == org_name).scalar() |
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
127 new_repo.fork = parent_repo |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
128 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 new_repo.user_id = cur_user.user_id |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 self.sa.add(new_repo) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
131 |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
132 #create default permission |
399
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
133 repo_to_perm = RepoToPerm() |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
399
diff
changeset
|
134 default = 'repository.read' |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
668
diff
changeset
|
135 for p in UserModel().get_by_username('default', cache=False).user_perms: |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
399
diff
changeset
|
136 if p.permission.permission_name.startswith('repository.'): |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
399
diff
changeset
|
137 default = p.permission.permission_name |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
399
diff
changeset
|
138 break |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
139 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
399
diff
changeset
|
140 default_perm = 'repository.none' if form_data['private'] else default |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
141 |
399
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
142 repo_to_perm.permission_id = self.sa.query(Permission)\ |
299
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
298
diff
changeset
|
143 .filter(Permission.permission_name == default_perm)\ |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
144 .one().permission_id |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
145 |
399
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
146 repo_to_perm.repository_id = new_repo.repo_id |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
668
diff
changeset
|
147 repo_to_perm.user_id = UserModel().get_by_username('default', cache=False).user_id |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
148 |
399
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
149 self.sa.add(repo_to_perm) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
150 self.sa.commit() |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
151 if not just_db: |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
651
diff
changeset
|
152 self.__create_repo(repo_name, form_data['repo_type']) |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
153 except: |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
154 log.error(traceback.format_exc()) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
155 self.sa.rollback() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
156 raise |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
157 |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
158 def create_fork(self, form_data, cur_user): |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
159 from rhodecode.lib.celerylib import tasks, run_task |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
160 run_task(tasks.create_repo_fork, form_data, cur_user) |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
161 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
162 def delete(self, repo): |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 try: |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
164 self.sa.delete(repo) |
668
dff6d5cb8bba
fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
165 self.__delete_repo(repo) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
166 self.sa.commit() |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
167 except: |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
168 log.error(traceback.format_exc()) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
169 self.sa.rollback() |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
170 raise |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
171 |
299
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
298
diff
changeset
|
172 def delete_perm_user(self, form_data, repo_name): |
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
298
diff
changeset
|
173 try: |
399
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
174 self.sa.query(RepoToPerm)\ |
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
175 .filter(RepoToPerm.repository == self.get(repo_name))\ |
f5c1eec9f376
rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
176 .filter(RepoToPerm.user_id == form_data['user_id']).delete() |
299
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
298
diff
changeset
|
177 self.sa.commit() |
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
298
diff
changeset
|
178 except: |
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
298
diff
changeset
|
179 log.error(traceback.format_exc()) |
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
298
diff
changeset
|
180 self.sa.rollback() |
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
298
diff
changeset
|
181 raise |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
182 |
708
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
183 def delete_stats(self, repo_name): |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
184 try: |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
185 self.sa.query(Statistics)\ |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
186 .filter(Statistics.repository == self.get(repo_name)).delete() |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
187 self.sa.commit() |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
188 except: |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
189 log.error(traceback.format_exc()) |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
190 self.sa.rollback() |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
191 raise |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
192 |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
193 |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
651
diff
changeset
|
194 def __create_repo(self, repo_name, alias): |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
195 from rhodecode.lib.utils import check_repo |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
196 repo_path = os.path.join(g.base_path, repo_name) |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
197 if check_repo(repo_name, g.base_path): |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
198 log.info('creating repo %s in %s', repo_name, repo_path) |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
651
diff
changeset
|
199 backend = get_backend(alias) |
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
651
diff
changeset
|
200 backend(repo_path, create=True) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
201 |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
202 def __rename_repo(self, old, new): |
356
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
328
diff
changeset
|
203 log.info('renaming repo from %s to %s', old, new) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
204 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
205 old_path = os.path.join(g.base_path, old) |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
206 new_path = os.path.join(g.base_path, new) |
356
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
328
diff
changeset
|
207 if os.path.isdir(new_path): |
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
328
diff
changeset
|
208 raise Exception('Was trying to rename to already existing dir %s', |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
209 new_path) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
210 shutil.move(old_path, new_path) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
211 |
668
dff6d5cb8bba
fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
212 def __delete_repo(self, repo): |
dff6d5cb8bba
fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
213 rm_path = os.path.join(g.base_path, repo.repo_name) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
214 log.info("Removing %s", rm_path) |
668
dff6d5cb8bba
fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
215 #disable hg/git |
dff6d5cb8bba
fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
216 alias = repo.repo_type |
dff6d5cb8bba
fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
217 shutil.move(os.path.join(rm_path, '.%s' % alias), |
dff6d5cb8bba
fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
218 os.path.join(rm_path, 'rm__.%s' % alias)) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
219 #disable repo |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
220 shutil.move(rm_path, os.path.join(g.base_path, 'rm__%s__%s' \ |
668
dff6d5cb8bba
fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
221 % (datetime.today(), repo.repo_name))) |