##// END OF EJS Templates
Extended repo2db mapper with group creation via directory structures...
marcink -
r878:859bc9e7 beta
parent child Browse files
Show More
@@ -44,7 +44,7 b' from vcs.utils.lazy import LazyProperty'
44
44
45 from rhodecode.model import meta
45 from rhodecode.model import meta
46 from rhodecode.model.caching_query import FromCache
46 from rhodecode.model.caching_query import FromCache
47 from rhodecode.model.db import Repository, User, RhodeCodeUi, UserLog
47 from rhodecode.model.db import Repository, User, RhodeCodeUi, UserLog, Group
48 from rhodecode.model.repo import RepoModel
48 from rhodecode.model.repo import RepoModel
49 from rhodecode.model.user import UserModel
49 from rhodecode.model.user import UserModel
50
50
@@ -296,8 +296,35 b' class EmptyChangeset(BaseChangeset):'
296 def get_file_size(self, path):
296 def get_file_size(self, path):
297 return 0
297 return 0
298
298
299 def map_groups(groups):
300 """Checks for groups existence, and creates groups structures.
301 It returns last group in structure
302
303 :param groups: list of groups structure
304 """
305 sa = meta.Session()
306
307 parent = None
308 group = None
309 for lvl, group_name in enumerate(groups[:-1]):
310 group = sa.query(Group).filter(Group.group_name == group_name).scalar()
311
312 if group is None:
313 group = Group(group_name, parent)
314 sa.add(group)
315 sa.commit()
316
317 parent = group
318
319 return group
320
299 def repo2db_mapper(initial_repo_list, remove_obsolete=False):
321 def repo2db_mapper(initial_repo_list, remove_obsolete=False):
300 """maps all found repositories into db
322 """maps all repos given in initial_repo_list, non existing repositories
323 are created, if remove_obsolete is True it also check for db entries
324 that are not in initial_repo_list and removes them.
325
326 :param initial_repo_list: list of repositories found by scanning methods
327 :param remove_obsolete: check for obsolete entries in database
301 """
328 """
302
329
303 sa = meta.Session()
330 sa = meta.Session()
@@ -305,6 +332,7 b' def repo2db_mapper(initial_repo_list, re'
305 user = sa.query(User).filter(User.admin == True).first()
332 user = sa.query(User).filter(User.admin == True).first()
306
333
307 for name, repo in initial_repo_list.items():
334 for name, repo in initial_repo_list.items():
335 group = map_groups(name.split('/'))
308 if not rm.get_by_repo_name(name, cache=False):
336 if not rm.get_by_repo_name(name, cache=False):
309 log.info('repository %s not found creating default', name)
337 log.info('repository %s not found creating default', name)
310
338
@@ -314,7 +342,8 b' def repo2db_mapper(initial_repo_list, re'
314 'description':repo.description \
342 'description':repo.description \
315 if repo.description != 'unknown' else \
343 if repo.description != 'unknown' else \
316 '%s repository' % name,
344 '%s repository' % name,
317 'private':False
345 'private':False,
346 'group_id':getattr(group, 'group_id', None)
318 }
347 }
319 rm.create(form_data, user, just_db=True)
348 rm.create(form_data, user, just_db=True)
320
349
@@ -80,8 +80,8 b' class RhodeCodeSettings(Base, BaseModel)'
80 self.app_settings_value = v
80 self.app_settings_value = v
81
81
82 def __repr__(self):
82 def __repr__(self):
83 return "<RhodeCodeSetting('%s:%s')>" % (self.app_settings_name,
83 return "<%s('%s:%s')>" % (self.__class__.__name__,
84 self.app_settings_value)
84 self.app_settings_name, self.app_settings_value)
85
85
86 class RhodeCodeUi(Base, BaseModel):
86 class RhodeCodeUi(Base, BaseModel):
87 __tablename__ = 'rhodecode_ui'
87 __tablename__ = 'rhodecode_ui'
@@ -118,7 +118,8 b' class User(Base, BaseModel):'
118 return '%s %s <%s>' % (self.name, self.lastname, self.email)
118 return '%s %s <%s>' % (self.name, self.lastname, self.email)
119
119
120 def __repr__(self):
120 def __repr__(self):
121 return "<User('id:%s:%s')>" % (self.user_id, self.username)
121 return "<%s('id:%s:%s')>" % (self.__class__.__name__,
122 self.user_id, self.username)
122
123
123 def update_lastlogin(self):
124 def update_lastlogin(self):
124 """Update user lastlogin"""
125 """Update user lastlogin"""
@@ -158,9 +159,11 b' class Repository(Base, BaseModel):'
158 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
159 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
159 description = Column("description", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
160 description = Column("description", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
160 fork_id = Column("fork_id", Integer(), ForeignKey(u'repositories.repo_id'), nullable=True, unique=False, default=None)
161 fork_id = Column("fork_id", Integer(), ForeignKey(u'repositories.repo_id'), nullable=True, unique=False, default=None)
162 group_id = Column("group_id", Integer(), ForeignKey(u'groups.group_id'), nullable=True, unique=False, default=None)
161
163
162 user = relation('User')
164 user = relation('User')
163 fork = relation('Repository', remote_side=repo_id)
165 fork = relation('Repository', remote_side=repo_id)
166 group = relation('Group')
164 repo_to_perm = relation('RepoToPerm', cascade='all')
167 repo_to_perm = relation('RepoToPerm', cascade='all')
165 stats = relation('Statistics', cascade='all', uselist=False)
168 stats = relation('Statistics', cascade='all', uselist=False)
166
169
@@ -168,7 +171,27 b' class Repository(Base, BaseModel):'
168
171
169
172
170 def __repr__(self):
173 def __repr__(self):
171 return "<Repository('%s:%s')>" % (self.repo_id, self.repo_name)
174 return "<%s('%s:%s')>" % (self.__class__.__name__,
175 self.repo_id, self.repo_name)
176
177 class Group(Base, BaseModel):
178 __tablename__ = 'groups'
179 __table_args__ = (UniqueConstraint('group_name'), {'useexisting':True},)
180
181 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
182 group_name = Column("group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
183 group_parent_id = Column("group_parent_id", Integer(), ForeignKey(u'groups.group_id'), nullable=True, unique=None, default=None)
184
185 parent_group = relation('Group', remote_side=group_id)
186
187
188 def __init__(self, group_name='', parent_group=None):
189 self.group_name = group_name
190 self.parent_group = parent_group
191
192 def __repr__(self):
193 return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
194 self.group_name)
172
195
173 class Permission(Base, BaseModel):
196 class Permission(Base, BaseModel):
174 __tablename__ = 'permissions'
197 __tablename__ = 'permissions'
@@ -178,7 +201,8 b' class Permission(Base, BaseModel):'
178 permission_longname = Column("permission_longname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
201 permission_longname = Column("permission_longname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
179
202
180 def __repr__(self):
203 def __repr__(self):
181 return "<Permission('%s:%s')>" % (self.permission_id, self.permission_name)
204 return "<%s('%s:%s')>" % (self.__class__.__name__,
205 self.permission_id, self.permission_name)
182
206
183 class RepoToPerm(Base, BaseModel):
207 class RepoToPerm(Base, BaseModel):
184 __tablename__ = 'repo_to_perm'
208 __tablename__ = 'repo_to_perm'
@@ -246,7 +270,8 b' class CacheInvalidation(Base, BaseModel)'
246 self.cache_active = False
270 self.cache_active = False
247
271
248 def __repr__(self):
272 def __repr__(self):
249 return "<CacheInvalidation('%s:%s')>" % (self.cache_id, self.cache_key)
273 return "<%s('%s:%s')>" % (self.__class__.__name__,
274 self.cache_id, self.cache_key)
250
275
251 class DbMigrateVersion(Base, BaseModel):
276 class DbMigrateVersion(Base, BaseModel):
252 __tablename__ = 'db_migrate_version'
277 __tablename__ = 'db_migrate_version'
@@ -135,7 +135,7 b' class ScmModel(BaseModel):'
135 tip = h.get_changeset_safe(repo, 'tip')
135 tip = h.get_changeset_safe(repo, 'tip')
136
136
137 tmp_d = {}
137 tmp_d = {}
138 tmp_d['name'] = repo.name
138 tmp_d['name'] = r.repo_name
139 tmp_d['name_sort'] = tmp_d['name'].lower()
139 tmp_d['name_sort'] = tmp_d['name'].lower()
140 tmp_d['description'] = repo.dbrepo.description
140 tmp_d['description'] = repo.dbrepo.description
141 tmp_d['description_sort'] = tmp_d['description']
141 tmp_d['description_sort'] = tmp_d['description']
General Comments 0
You need to be logged in to leave comments. Login now