Show More
@@ -427,7 +427,8 b' def map_groups(path):' | |||||
427 | return group |
|
427 | return group | |
428 |
|
428 | |||
429 |
|
429 | |||
430 |
def repo2db_mapper(initial_repo_list, remove_obsolete=False |
|
430 | def repo2db_mapper(initial_repo_list, remove_obsolete=False, | |
|
431 | install_git_hook=False): | |||
431 | """ |
|
432 | """ | |
432 | maps all repos given in initial_repo_list, non existing repositories |
|
433 | maps all repos given in initial_repo_list, non existing repositories | |
433 | are created, if remove_obsolete is True it also check for db entries |
|
434 | are created, if remove_obsolete is True it also check for db entries | |
@@ -435,8 +436,11 b' def repo2db_mapper(initial_repo_list, re' | |||||
435 |
|
436 | |||
436 | :param initial_repo_list: list of repositories found by scanning methods |
|
437 | :param initial_repo_list: list of repositories found by scanning methods | |
437 | :param remove_obsolete: check for obsolete entries in database |
|
438 | :param remove_obsolete: check for obsolete entries in database | |
|
439 | :param install_git_hook: if this is True, also check and install githook | |||
|
440 | for a repo if missing | |||
438 | """ |
|
441 | """ | |
439 | from rhodecode.model.repo import RepoModel |
|
442 | from rhodecode.model.repo import RepoModel | |
|
443 | from rhodecode.model.scm import ScmModel | |||
440 | sa = meta.Session() |
|
444 | sa = meta.Session() | |
441 | rm = RepoModel() |
|
445 | rm = RepoModel() | |
442 | user = sa.query(User).filter(User.admin == True).first() |
|
446 | user = sa.query(User).filter(User.admin == True).first() | |
@@ -446,7 +450,8 b' def repo2db_mapper(initial_repo_list, re' | |||||
446 |
|
450 | |||
447 | for name, repo in initial_repo_list.items(): |
|
451 | for name, repo in initial_repo_list.items(): | |
448 | group = map_groups(name) |
|
452 | group = map_groups(name) | |
449 |
|
|
453 | repo = rm.get_by_repo_name(name) | |
|
454 | if not repo: | |||
450 | log.info('repository %s not found creating now' % name) |
|
455 | log.info('repository %s not found creating now' % name) | |
451 | added.append(name) |
|
456 | added.append(name) | |
452 | desc = (repo.description |
|
457 | desc = (repo.description | |
@@ -460,6 +465,9 b' def repo2db_mapper(initial_repo_list, re' | |||||
460 | owner=user, |
|
465 | owner=user, | |
461 | just_db=True |
|
466 | just_db=True | |
462 | ) |
|
467 | ) | |
|
468 | elif install_git_hook: | |||
|
469 | if repo.repo_type == 'git': | |||
|
470 | ScmModel().install_git_hook(repo.scm_instance) | |||
463 | sa.commit() |
|
471 | sa.commit() | |
464 | removed = [] |
|
472 | removed = [] | |
465 | if remove_obsolete: |
|
473 | if remove_obsolete: | |
@@ -468,9 +476,13 b' def repo2db_mapper(initial_repo_list, re' | |||||
468 | if repo.repo_name not in initial_repo_list.keys(): |
|
476 | if repo.repo_name not in initial_repo_list.keys(): | |
469 | log.debug("Removing non existing repository found in db %s" % |
|
477 | log.debug("Removing non existing repository found in db %s" % | |
470 | repo.repo_name) |
|
478 | repo.repo_name) | |
471 | removed.append(repo.repo_name) |
|
479 | try: | |
472 | sa.delete(repo) |
|
480 | sa.delete(repo) | |
473 | sa.commit() |
|
481 | sa.commit() | |
|
482 | removed.append(repo.repo_name) | |||
|
483 | except: | |||
|
484 | #don't hold further removals on error | |||
|
485 | log.error(traceback.format_exc()) | |||
474 |
|
486 | |||
475 | # clear cache keys |
|
487 | # clear cache keys | |
476 | log.debug("Clearing cache keys now...") |
|
488 | log.debug("Clearing cache keys now...") |
General Comments 0
You need to be logged in to leave comments.
Login now