changeset 2619:f1dfd3a2a193 beta

Added option to re-install githooks to repo2db mapper, and catch exception on removal so it doesn't break after first error
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 16 Jul 2012 03:02:41 +0200
parents e1370dcb9908
children cd207411cf22
files rhodecode/lib/utils.py
diffstat 1 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/utils.py	Mon Jul 16 02:28:02 2012 +0200
+++ b/rhodecode/lib/utils.py	Mon Jul 16 03:02:41 2012 +0200
@@ -427,7 +427,8 @@
     return group
 
 
-def repo2db_mapper(initial_repo_list, remove_obsolete=False):
+def repo2db_mapper(initial_repo_list, remove_obsolete=False,
+                   install_git_hook=False):
     """
     maps all repos given in initial_repo_list, non existing repositories
     are created, if remove_obsolete is True it also check for db entries
@@ -435,8 +436,11 @@
 
     :param initial_repo_list: list of repositories found by scanning methods
     :param remove_obsolete: check for obsolete entries in database
+    :param install_git_hook: if this is True, also check and install githook
+        for a repo if missing
     """
     from rhodecode.model.repo import RepoModel
+    from rhodecode.model.scm import ScmModel
     sa = meta.Session()
     rm = RepoModel()
     user = sa.query(User).filter(User.admin == True).first()
@@ -446,7 +450,8 @@
 
     for name, repo in initial_repo_list.items():
         group = map_groups(name)
-        if not rm.get_by_repo_name(name):
+        repo = rm.get_by_repo_name(name)
+        if not repo:
             log.info('repository %s not found creating now' % name)
             added.append(name)
             desc = (repo.description
@@ -460,6 +465,9 @@
                 owner=user,
                 just_db=True
             )
+        elif install_git_hook:
+            if repo.repo_type == 'git':
+                ScmModel().install_git_hook(repo.scm_instance)
     sa.commit()
     removed = []
     if remove_obsolete:
@@ -468,9 +476,13 @@
             if repo.repo_name not in initial_repo_list.keys():
                 log.debug("Removing non existing repository found in db %s" %
                           repo.repo_name)
-                removed.append(repo.repo_name)
-                sa.delete(repo)
-                sa.commit()
+                try:
+                    sa.delete(repo)
+                    sa.commit()
+                    removed.append(repo.repo_name)
+                except:
+                    #don't hold further removals on error
+                    log.error(traceback.format_exc())
 
     # clear cache keys
     log.debug("Clearing cache keys now...")