Mercurial > kallithea
comparison rhodecode/lib/utils.py @ 2120:d5527cebf76a beta
Resolve error occurring during recursive group creation in API create-repo function
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 11 Mar 2012 17:51:23 +0200 |
parents | 8ecfed1d8f8b |
children | d25bd432bc3e |
comparison
equal
deleted
inserted
replaced
2119:4d076981a7b1 | 2120:d5527cebf76a |
---|---|
378 | 378 |
379 def get_file_size(self, path): | 379 def get_file_size(self, path): |
380 return 0 | 380 return 0 |
381 | 381 |
382 | 382 |
383 def map_groups(groups): | 383 def map_groups(path): |
384 """ | 384 """ |
385 Checks for groups existence, and creates groups structures. | 385 Given a full path to a repository, create all nested groups that this |
386 It returns last group in structure | 386 repo is inside. This function creates parent-child relationships between |
387 | 387 groups and creates default perms for all new groups. |
388 :param groups: list of groups structure | 388 |
389 :param paths: full path to repository | |
389 """ | 390 """ |
390 sa = meta.Session | 391 sa = meta.Session |
391 | 392 groups = path.split(Repository.url_sep()) |
392 parent = None | 393 parent = None |
393 group = None | 394 group = None |
394 | 395 |
395 # last element is repo in nested groups structure | 396 # last element is repo in nested groups structure |
396 groups = groups[:-1] | 397 groups = groups[:-1] |
398 for lvl, group_name in enumerate(groups): | 399 for lvl, group_name in enumerate(groups): |
399 group_name = '/'.join(groups[:lvl] + [group_name]) | 400 group_name = '/'.join(groups[:lvl] + [group_name]) |
400 group = RepoGroup.get_by_group_name(group_name) | 401 group = RepoGroup.get_by_group_name(group_name) |
401 desc = '%s group' % group_name | 402 desc = '%s group' % group_name |
402 | 403 |
403 # # WTF that doesn't work !? | |
404 # if group is None: | |
405 # group = rgm.create(group_name, desc, parent, just_db=True) | |
406 # sa.commit() | |
407 | |
408 # skip folders that are now removed repos | 404 # skip folders that are now removed repos |
409 if REMOVED_REPO_PAT.match(group_name): | 405 if REMOVED_REPO_PAT.match(group_name): |
410 break | 406 break |
411 | 407 |
412 if group is None: | 408 if group is None: |
413 log.debug('creating group level: %s group_name: %s' % (lvl, group_name)) | 409 log.debug('creating group level: %s group_name: %s' % (lvl, |
410 group_name)) | |
414 group = RepoGroup(group_name, parent) | 411 group = RepoGroup(group_name, parent) |
415 group.group_description = desc | 412 group.group_description = desc |
416 sa.add(group) | 413 sa.add(group) |
417 rgm._create_default_perms(group) | 414 rgm._create_default_perms(group) |
418 sa.commit() | 415 sa.flush() |
419 parent = group | 416 parent = group |
420 return group | 417 return group |
421 | 418 |
422 | 419 |
423 def repo2db_mapper(initial_repo_list, remove_obsolete=False): | 420 def repo2db_mapper(initial_repo_list, remove_obsolete=False): |
436 if user is None: | 433 if user is None: |
437 raise Exception('Missing administrative account !') | 434 raise Exception('Missing administrative account !') |
438 added = [] | 435 added = [] |
439 | 436 |
440 for name, repo in initial_repo_list.items(): | 437 for name, repo in initial_repo_list.items(): |
441 group = map_groups(name.split(Repository.url_sep())) | 438 group = map_groups(name) |
442 if not rm.get_by_repo_name(name, cache=False): | 439 if not rm.get_by_repo_name(name, cache=False): |
443 log.info('repository %s not found creating default' % name) | 440 log.info('repository %s not found creating default' % name) |
444 added.append(name) | 441 added.append(name) |
445 form_data = { | 442 form_data = { |
446 'repo_name': name, | 443 'repo_name': name, |