Changeset 3425

Show
Ignore:
Timestamp:
03/30/08 22:17:54 (9 months ago)
Author:
coderanger
Message:

Maybe working version of the hookscript step.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tracforgeplugin/0.11/tracforge/admin/prototypes_admin.py

    r3406 r3425  
    116116                proto.append((req.args['type'], '')) 
    117117            elif 'save' in req.args: 
     118                proto.tag = data['name'] 
    118119                proto.save() 
    119120                req.redirect(req.href.admin('tracforge/prototypes', proto.tag)) 
  • tracforgeplugin/0.11/tracforge/admin/prototypes.py

    r3424 r3425  
    55import os.path 
    66import time 
     7import stat 
    78 
    89from trac.core import * 
     
    1213from tracforge.admin.api import IProjectSetupParticipant 
    1314from tracforge.admin.util import CommandLine, locate 
    14  
    15 # Try and use ctypes to get fchmod 
    16 try: 
    17     import ctypes 
    18     import ctypes.util 
    19     have_ctypes = True 
    20      
    21     libc = ctypes.CDLL(ctypes.util.find_library('c')) 
    22 except ImportError: 
    23     have_ctypes = False 
    2415 
    2516class ProjectSetupParticipantBase(Component): 
     
    150141     
    151142    Valid arguments are `pre`, `post`, or `both`. 
    152      
    153     '''NOTE''': You cannot automatically activate the pre-commit hook on  
    154     Windows at this time. 
    155143    """ 
    156144     
    157     depends = ['repo_type', 'repo_dir'
     145    depends = ['repo_type', 'repo_dir', 'env'
    158146     
    159147    arg_map = { 
     
    173161    def execute_setup_action(self, action, args, data, log_cb): 
    174162        if data['repo_type'] == 'svn': 
    175             pre, post = dict(reversed(self.arg_map.itertitems())).get(args, (False, False)) 
    176             if pre 
     163            pre, post = dict([(v,k) for k, v in self.arg_map.iteritems()]).get(args, (False, False)) 
     164            if pre: 
     165                hookf, trachook = self._install_hook(data['repo_dir'], 'pre-commit') 
     166                svnlook = locate('svnlook') 
     167                if os.name == 'nt': 
     168                    hookf.write('%s log -t %%2 %%1 > C:\\temp\\svnlog-%%2\n'%svnlook) 
     169                    hookf.write('%s %s %s file:"C:\\temp\\svnlook-%%2\n"'% 
     170                                (sys.executable, trachook, data['env'].path)) 
     171                    hookf.write('IF ERRORLEVEL 1 SET TRAC_CANCEL=YES\n') 
     172                    hookf.write('DEL /F C:\\temp\\svnlog-%2\n') 
     173                    hookf.write('IF DEFINED TRAC_CANCEL EXIT 1\n') 
     174                else: 
     175                    hookf.write('%s %s %s "${%s log -t "$2" "$1"}"\n'% 
     176                                (sys.executable, trachook, data['env'].path, svnlook)) 
     177            if post: 
     178                hookf, trachook = self._install_hook(data['repo_dir'], 'post-commit') 
     179                revarg = os.name == 'nt' and '%2' or '$2' 
     180                hookf.write('%s %s -p "%s" -r "%s"\n'% 
     181                            (sys.executable, trachook, data['env'].path, revarg)) 
     182        return True 
    177183     
    178184    # Internal methods 
     
    197203        # Open source and sink for the trac hook 
    198204        script = resource_stream(__name__, 'scripts/trac-'+hook+'-hook') 
    199         trachook_file = os.path.join(path, 'hooks', 'trac-'+hook+'-hook')  
     205        trachook_file = os.path.join(path, 'hooks', 'trac-'+hook+'-hook') 
     206        print 'Installing script file to %s'%trachook_file 
    200207        out = open(trachook_file, 'w') 
    201208        # Copy over the given trac hook 
     
    213220            hook_file += '.bat' 
    214221        hookf = open(hook_file, 'a') 
    215         hookf.write('%s %s -')   
     222        if os.name != 'nt' and not os.access(hook_file, os.X_OK): 
     223            print 'Making %s executable'%hook_file 
     224            os.chmod(hook_file, os.stat(hook_file).st_mode|stat.S_IXUSR) 
     225        return hookf, trachook_file