Changeset 71

Show
Ignore:
Timestamp:
2009年02月25日 10时17分42秒 (3 years ago)
Author:
jiangx
Message:

Fixed #18: when init hooks for newly created repository, search system-wide hooks directory, and make a symlink as repository hooks.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pysvnmanager/model/repos.py

    r50 r71  
    9090     
    9191    def hooks_init(self, repos_name): 
     92        sys_hook_paths = ['/etc/subversion/hooks', '/opt/svn/hooks', ] 
     93        for p in sys_hook_paths: 
     94            if os.path.exists(os.path.join(p, "parse_ini.sh")): 
     95                return self.hooks_init_symlink(p, repos_name) 
     96        return self.hooks_init_copy(repos_name) 
     97 
     98    def hooks_init_symlink(self, hooks_dir, repos_name): 
     99        if not os.path.exists(os.path.join(hooks_dir, "parse_ini.sh")): 
     100            raise Exception("\"%s\" is not a valid hooks location." % hooks_dir) 
     101        dest = "%(root)s/%(entry)s/hooks" % { "root": self.repos_root, "entry": repos_name} 
     102        dest = os.path.abspath(dest) 
     103         
     104        import shutil 
     105        if os.path.exists(dest): 
     106            assert os.path.basename(dest) == 'hooks' 
     107            shutil.rmtree(dest) 
     108        elif not os.path.exists(os.path.dirname(dest)): 
     109            raise Exception("Destination repository '%s' not exist!" % os.path.dirname(dest)) 
     110        os.symlink(hooks_dir, dest) 
     111 
     112    def hooks_init_copy(self, repos_name): 
    92113        import distutils.version as dv 
    93114        version = '.'.join(self.svnversion()) 
     
    113134            assert os.path.basename(dest) == 'hooks' 
    114135            shutil.rmtree(dest) 
    115         elif not os.path.exists(os.path.basename(dest)): 
    116             raise Exception("Destination repository '%s' not exist!" % os.path.basename(dest)) 
     136        elif not os.path.exists(os.path.dirname(dest)): 
     137            raise Exception("Destination repository '%s' not exist!" % os.path.dirname(dest)) 
    117138        for root, dirs, files in os.walk(src): 
    118139            targetdir = root.replace(src, dest, 1)