comparison rhodecode/model/repos_group.py @ 1345:3bce31f026b8 beta

#47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods. Added new db unique key for Group
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 23 May 2011 02:22:00 +0200
parents
children cf78d302d441
comparison
equal deleted inserted replaced
1344:eef7a1b953e8 1345:3bce31f026b8
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.model.user_group
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 users groups model for RhodeCode
7
8 :created_on: Jan 25, 2011
9 :author: marcink
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26 import os
27 import logging
28 import traceback
29
30 from pylons.i18n.translation import _
31
32 from vcs.utils.lazy import LazyProperty
33
34 from rhodecode.model import BaseModel
35 from rhodecode.model.caching_query import FromCache
36 from rhodecode.model.db import Group, RhodeCodeUi
37
38 log = logging.getLogger(__name__)
39
40
41 class ReposGroupModel(BaseModel):
42
43 @LazyProperty
44 def repos_path(self):
45 """
46 Get's the repositories root path from database
47 """
48
49 q = RhodeCodeUi.get_by_key('/').one()
50 return q.ui_value
51
52 def __create_group(self, group_name, parent_id):
53 """
54 makes repositories group on filesystem
55
56 :param repo_name:
57 :param parent_id:
58 """
59
60 if parent_id:
61 parent_group_name = Group.get(parent_id).group_name
62 else:
63 parent_group_name = ''
64
65 create_path = os.path.join(self.repos_path, parent_group_name,
66 group_name)
67 log.debug('creating new group in %s', create_path)
68
69 if os.path.isdir(create_path):
70 raise Exception('That directory already exists !')
71
72
73 os.makedirs(create_path)
74
75
76 def __rename_group(self, group_name):
77 """
78 Renames a group on filesystem
79
80 :param group_name:
81 """
82 pass
83
84 def __delete_group(self, group_name):
85 """
86 Deletes a group from a filesystem
87
88 :param group_name:
89 """
90 pass
91
92 def create(self, form_data):
93 try:
94 new_repos_group = Group()
95 new_repos_group.group_name = form_data['repos_group_name']
96 new_repos_group.group_description = \
97 form_data['repos_group_description']
98 new_repos_group.group_parent_id = form_data['repos_group_parent']
99
100 self.sa.add(new_repos_group)
101
102 self.__create_group(form_data['repos_group_name'],
103 form_data['repos_group_parent'])
104
105 self.sa.commit()
106 except:
107 log.error(traceback.format_exc())
108 self.sa.rollback()
109 raise
110
111 def update(self, repos_group_id, form_data):
112
113 try:
114 repos_group = Group.get(repos_group_id)
115
116
117
118 self.sa.add(repos_group)
119 self.sa.commit()
120 except:
121 log.error(traceback.format_exc())
122 self.sa.rollback()
123 raise
124
125 def delete(self, users_group_id):
126 try:
127 users_group = self.get(users_group_id, cache=False)
128 self.sa.delete(users_group)
129 self.sa.commit()
130 except:
131 log.error(traceback.format_exc())
132 self.sa.rollback()
133 raise