comparison rhodecode/model/repos_group.py @ 1538:27be8f94c207 beta

implements #226 repo groups available by path fixes #259 Groups with the same name but with different parent group
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 10 Oct 2011 02:09:52 +0200
parents 526120c77a38
children bd604cf75c5a
comparison
equal deleted inserted replaced
1537:c307c920f94c 1538:27be8f94c207
48 """ 48 """
49 49
50 q = RhodeCodeUi.get_by_key('/').one() 50 q = RhodeCodeUi.get_by_key('/').one()
51 return q.ui_value 51 return q.ui_value
52 52
53 def __create_group(self, group_name, parent_id): 53 def __create_group(self, group_name):
54 """ 54 """
55 makes repositories group on filesystem 55 makes repositories group on filesystem
56 56
57 :param repo_name: 57 :param repo_name:
58 :param parent_id: 58 :param parent_id:
59 """ 59 """
60 60
61 if parent_id: 61 create_path = os.path.join(self.repos_path, group_name)
62 paths = Group.get(parent_id).full_path.split(Group.url_sep())
63 parent_path = os.sep.join(paths)
64 else:
65 parent_path = ''
66
67 create_path = os.path.join(self.repos_path, parent_path, group_name)
68 log.debug('creating new group in %s', create_path) 62 log.debug('creating new group in %s', create_path)
69 63
70 if os.path.isdir(create_path): 64 if os.path.isdir(create_path):
71 raise Exception('That directory already exists !') 65 raise Exception('That directory already exists !')
72 66
73
74 os.makedirs(create_path) 67 os.makedirs(create_path)
75 68
76 69 def __rename_group(self, old, new):
77 def __rename_group(self, old, old_parent_id, new, new_parent_id):
78 """ 70 """
79 Renames a group on filesystem 71 Renames a group on filesystem
80 72
81 :param group_name: 73 :param group_name:
82 """ 74 """
75
76 if old == new:
77 log.debug('skipping group rename')
78 return
79
83 log.debug('renaming repos group from %s to %s', old, new) 80 log.debug('renaming repos group from %s to %s', old, new)
84 81
85 if new_parent_id:
86 paths = Group.get(new_parent_id).full_path.split(Group.url_sep())
87 new_parent_path = os.sep.join(paths)
88 else:
89 new_parent_path = ''
90 82
91 if old_parent_id: 83 old_path = os.path.join(self.repos_path, old)
92 paths = Group.get(old_parent_id).full_path.split(Group.url_sep()) 84 new_path = os.path.join(self.repos_path, new)
93 old_parent_path = os.sep.join(paths)
94 else:
95 old_parent_path = ''
96
97 old_path = os.path.join(self.repos_path, old_parent_path, old)
98 new_path = os.path.join(self.repos_path, new_parent_path, new)
99 85
100 log.debug('renaming repos paths from %s to %s', old_path, new_path) 86 log.debug('renaming repos paths from %s to %s', old_path, new_path)
101 87
102 if os.path.isdir(new_path): 88 if os.path.isdir(new_path):
103 raise Exception('Was trying to rename to already ' 89 raise Exception('Was trying to rename to already '
117 os.rmdir(rm_path) 103 os.rmdir(rm_path)
118 104
119 def create(self, form_data): 105 def create(self, form_data):
120 try: 106 try:
121 new_repos_group = Group() 107 new_repos_group = Group()
122 new_repos_group.group_name = form_data['group_name'] 108 new_repos_group.group_description = form_data['group_description']
123 new_repos_group.group_description = \ 109 new_repos_group.parent_group = Group.get(form_data['group_parent_id'])
124 form_data['group_description'] 110 new_repos_group.group_name = new_repos_group.get_new_name(form_data['group_name'])
125 new_repos_group.group_parent_id = form_data['group_parent_id']
126 111
127 self.sa.add(new_repos_group) 112 self.sa.add(new_repos_group)
128 113
129 self.__create_group(form_data['group_name'], 114 self.__create_group(new_repos_group.group_name)
130 form_data['group_parent_id'])
131 115
132 self.sa.commit() 116 self.sa.commit()
117 return new_repos_group
133 except: 118 except:
134 log.error(traceback.format_exc()) 119 log.error(traceback.format_exc())
135 self.sa.rollback() 120 self.sa.rollback()
136 raise 121 raise
137 122
138 def update(self, repos_group_id, form_data): 123 def update(self, repos_group_id, form_data):
139 124
140 try: 125 try:
141 repos_group = Group.get(repos_group_id) 126 repos_group = Group.get(repos_group_id)
142 old_name = repos_group.group_name 127 old_path = repos_group.full_path
143 old_parent_id = repos_group.group_parent_id
144 128
145 repos_group.group_name = form_data['group_name'] 129 #change properties
146 repos_group.group_description = \ 130 repos_group.group_description = form_data['group_description']
147 form_data['group_description'] 131 repos_group.parent_group = Group.get(form_data['group_parent_id'])
148 repos_group.group_parent_id = form_data['group_parent_id'] 132 repos_group.group_name = repos_group.get_new_name(form_data['group_name'])
133
134 new_path = repos_group.full_path
149 135
150 self.sa.add(repos_group) 136 self.sa.add(repos_group)
151 137
152 if old_name != form_data['group_name'] or (old_parent_id != 138 self.__rename_group(old_path, new_path)
153 form_data['group_parent_id']):
154 self.__rename_group(old=old_name, old_parent_id=old_parent_id,
155 new=form_data['group_name'],
156 new_parent_id=form_data['group_parent_id'])
157 139
158 self.sa.commit() 140 self.sa.commit()
141 return repos_group
159 except: 142 except:
160 log.error(traceback.format_exc()) 143 log.error(traceback.format_exc())
161 self.sa.rollback() 144 self.sa.rollback()
162 raise 145 raise
163 146