Edgewall Software

Ticket #1602 (closed enhancement: fixed)

Opened 3 years ago

Last modified 5 months ago

Fix & cleanup for .bat and .com for commit hook launch on Windows

Reported by: coreywangler@… Owned by: cboos
Priority: low Milestone: 0.10.4
Component: general Version: 0.10.2
Severity: normal Keywords: contrib windows
Cc:

Description

The .bat files and .com files given in #897 to launch commit hook scripts do not work because the command to open the database connection in the python scripts expects the environment directory (not the trac.db file). The basic change to these windows files is as follows:

REM SET TRAC_ENV="%TRACDB_DIR%\db\trac.db"
SET TRAC_ENV="%TRACDB_DIR%"

...though I have also re-arranged these slightly to make it easier to see what settings needs to be altered when these are added to a given project -- the settings are now at the top of the file, and are just the environment (the rest of the path is added later).

NOTE: the .bat files need to be used with the python hook scripts from #897, due to the way info is passed (via a file). The .com scripts work with the standard python hook scripts available at branches/0.8-stable/contrib/

Attachments

pre-commit.bat (0.9 kB) - added by coreywangler@… 3 years ago.
fixed .bat file for launching the corresponding python hook script (from #897) in windows
post-commit.bat (1.0 kB) - added by coreywangler@… 3 years ago.
fixed .bat file for launching the corresponding python hook script (from #897) in windows
pre-commit.cmd (2.6 kB) - added by coreywangler@… 3 years ago.
fixed .com file for launching the corresponding python hook script (from 0.8-stable/contrib/) in windows
post-commit.cmd (2.1 kB) - added by coreywangler@… 3 years ago.
fixed .com file for launching the corresponding python hook script (from 0.8-stable/contrib/) in windows
.2 (0 bytes) - added by coreywangler@… 3 years ago.
renamed python script given in #897
trac-pre-commit-hook_4bat (3.0 kB) - added by coreywangler@… 3 years ago.
renamed python script given in #897
trac-post-commit-hook_4bat (8.3 kB) - added by coreywangler@… 3 years ago.
renamed python script given in #897
post-commit.2.bat (1.0 kB) - added by coreywangler@… 3 years ago.
.bat file that launches trac-pre-commit-hook_4bat python script
pre-commit.2.bat (0.9 kB) - added by coreywangler@… 3 years ago.
.bat file that launches trac-pre-commit-hook_4bat python script
trac-post-commit-hook-french (8.5 kB) - added by d.mills@… 3 years ago.
French translation of the python hook file (doc not translated), remove the -french in the name and place in the hooks directory to use.
trac-post-commit-hook_4bat.2 (8.4 kB) - added by Denney <denney@…> 2 years ago.
Updated to work with Trac 0.9-stable
trac-pre-commit-hook_4bat.2 (3.0 kB) - added by Denney <denney@…> 2 years ago.
Updated to work with Trac 0.9-stable
post-commit.0.9.cmd (2.1 kB) - added by jay@… 2 years ago.
Works with 0.9 stable standard Trac hooks source:branches/0.9-stable/contrib/
post-commit.0.10.3.cmd (120 bytes) - added by markus 20 months ago.
Works with trac 0.10.3, international characters in changeset messages and ticket comments, no temporary file
trac-post-commit-hook.0.10.3.cmd (399 bytes) - added by markus 20 months ago.
Works with trac 0.10.3, international characters in changeset messages and ticket comments, no temporary file
trac-post-commit-hook.0.10.3.py (8.2 kB) - added by markus 20 months ago.
Works with trac 0.10.3, international characters in changeset messages and ticket comments, no temporary file

Change History

Changed 3 years ago by coreywangler@…

fixed .bat file for launching the corresponding python hook script (from #897) in windows

Changed 3 years ago by coreywangler@…

fixed .bat file for launching the corresponding python hook script (from #897) in windows

Changed 3 years ago by coreywangler@…

fixed .com file for launching the corresponding python hook script (from 0.8-stable/contrib/) in windows

Changed 3 years ago by coreywangler@…

fixed .com file for launching the corresponding python hook script (from 0.8-stable/contrib/) in windows

Changed 3 years ago by anonymous

Just a thought... if these are to be included with the trac distribution, it might be a good idea to rename the altered python hook scripts (the ones for the .bat launchers, given in #897) so that the file names don't conflict, and change the .bat files to launch the re-named python hook scripts.

Changed 3 years ago by coreywangler@…

  • keywords contrib added; script removed
  • priority changed from normal to high
  • version changed from 0.8.1 to devel
  • severity changed from normal to enhancement
  • milestone set to 0.9

Changed the properties of this ticket to match that of #897

Changed 3 years ago by coreywangler@…

  • attachment .2 added

renamed python script given in #897

Changed 3 years ago by coreywangler@…

renamed python script given in #897

Changed 3 years ago by coreywangler@…

renamed python script given in #897

Changed 3 years ago by coreywangler@…

.bat file that launches trac-pre-commit-hook_4bat python script

Changed 3 years ago by coreywangler@…

.bat file that launches trac-pre-commit-hook_4bat python script

Changed 3 years ago by coreywangler@…

Added files:

python scripts that work with the bat launcher (renamed)

  • trac-pre-commit-hook_4bat
  • trac-post-commit-hook_4bat

modified .bat files to launch these renamed python scripts

  • pre-commit.bat (attachment is pre-commit.2.bat)
  • post-commit.bat (attachment is post-commit.2.bat)

These 4 files, together with the pre-commit.cmd and pre-commit.cmd files, are what should be placed into the contrib directory.

Changed 3 years ago by d.mills@…

Just a small clarification on what coreywangler posted:

For one hook (ie pre or post) you need the python script + either the corresponding .bat or the corresponding .cmd.

IIRC having both would call the script twice, that said I haven't tried

Changed 3 years ago by d.mills@…

French translation of the python hook file (doc not translated), remove the -french in the name and place in the hooks directory to use.

Changed 3 years ago by d.mills@…

Just to clarify on the attachement:

If you use this file, the commands become 'ferme' and 'resout' to close a ticket, and 'concerne', 'référence', 'réf' and 're:' to just add a comment.

Ticket number seperators are ' & ', ' , ' and ' et '.

Changed 3 years ago by cmlenz

  • priority changed from high to low
  • milestone 0.9 deleted

Changed 2 years ago by Denney <denney@…>

Updated to work with Trac 0.9-stable

Changed 2 years ago by Denney <denney@…>

Updated to work with Trac 0.9-stable

Changed 2 years ago by Denney <denney@…>

There was a database version error with the old scripts. These updates make them work with the .bat files when running v0.9-stable.

Plus, you get the added bonus of the updated scripts.

Changed 2 years ago by Denney <denney@…>

If you want to use the %TRAC_URL% variable from the commit hooks, just add:

-s "http://____YOUR_TRAC_PROJECT_URL" to the .bat file where it calls the commit hook.

Changed 2 years ago by anonymous

When clicking the trac-pre-commit-hook_4bat.2 and another link, there is an internal error on this page. No files can be downloaded. This is the error reported -


Trac detected an internal error:

If you think this really should work and you can reproduce it, you should consider reporting this problem to the Trac team.

Go to http://trac.edgewall.com/ and create a new ticket where you describe the problem, how to reproduce it. Don't forget to include the Python traceback found below.

TracGuide — The Trac User and Administration Guide Python Traceback

Traceback (most recent call last):

File "/usr/lib/python2.3/site-packages/trac/web/main.py", line 299, in dispatch_request

dispatcher.dispatch(req)

File "/usr/lib/python2.3/site-packages/trac/web/main.py", line 189, in dispatch

resp = chosen_handler.process_request(req)

File "/usr/lib/python2.3/site-packages/trac/attachment.py", line 289, in process_request

self._render_view(req, attachment)

File "/usr/lib/python2.3/site-packages/trac/attachment.py", line 465, in _render_view

attachment.filename, raw_href, annotations=lineno?)

File "/usr/lib/python2.3/site-packages/trac/mimeview/api.py", line 407, in preview_to_hdf

url, annotations)}

File "/usr/lib/python2.3/site-packages/trac/mimeview/api.py", line 259, in render

content = content.read(mimeview.get_max_preview_size())

NameError?: global name 'mimeview' is not defined

Changed 2 years ago by cboos

Thanks for the report, I fixed that in r3216.

You'll have to wait a bit that this server is upgraded to this changeset before being able to download the file.

Changed 2 years ago by cmlenz

cboos, server upgraded to r3216, getting another error now :-/

Changed 2 years ago by cboos

Hm, I see, it's when we don't have any mimetype.

There should be a fallback MIME type, either 'text/plain' or 'application/octet-stream', if the content is binary.

Changed 2 years ago by cboos

  • api.py

     
    258258            if hasattr(content, 'read'): 
    259259                content = content.read(self.get_max_preview_size()) 
    260260            full_mimetype = self.get_mimetype(filename, content) 
    261         mimetype = full_mimetype.split(';')[0].strip() # split off charset 
     261        if full_mimetype: 
     262            mimetype = full_mimetype.split(';')[0].strip() # split off charset 
     263        else: 
     264            mimetype = full_mimetype = 'text/plain' # fallback if not binary 
    262265 
    263266        # Determine candidate `IHTMLPreviewRenderer`s 
    264267        candidates = [] 

Do you think this would be OK?

In last resort, the function get_mimetype returns application/octet-stream if the content is binary, but None otherwise.

I'm not sure we can change the get_mimetype to return text/plain instead of None, as it's also used in trac.web. If you think we can change it, then the fix is even simpler:

  • api.py

     
    126126        if content and is_binary(content): 
    127127            return 'application/octet-stream' 
    128128        else: 
    129             return None 
     129            return 'text/plain' 
    130130 
    131131def is_binary(data): 
    132132    """Detect binary content by checking the first thousand bytes for zeroes. 

Changed 2 years ago by cboos

I opted for the first solution in r3222, as I think it's important that the get_mimetype returns None in case it didn't autodetect anything.

Issue hopefully fixed...

Changed 2 years ago by denney@…

These scripts don't seem to work with the latest v.10-devel. I can't seem to figure out why either.

I just upgraded from v0.9.3 Stable to v0.10 Devel and, even after updating to use the current contrib/trac-post-commit-hook, it won't work. Just to let you know. Still looking for a fix.

Changed 2 years ago by Denney <denney@…>

Never mind. It was my bodgy updating job that must of been producing the error.

Updating the script properly fixes the problem.

Changed 2 years ago by jay@…

Works with 0.9 stable standard Trac hooks source:branches/0.9-stable/contrib/

Changed 2 years ago by mgood

#3464 has been marked as a duplicate. It has an alternate version of the hook scripts to review.

Changed 2 years ago by oscar@…

Using 0.10b1, I had to comment out the database version check to get it to run at all, it complained about the version. After that, it doesn't give any errors anymore, but doesn't update the tickets like it should at all.

Using tracd and Windows 2000.

Changed 2 years ago by oscar@…

Removing the db version check wasn't a good idea, don't do that, it didn't write to the db with Utf-8 so it got corrupted. Anyone working on updated scripts?

Changed 23 months ago by sambloomquist

I'm using Windows 2000 and the '.2' files that are attached to this page. To get them to work with Trac .10 I had to change line 102 in the trac-post-commit-hook_4bat file from

from trac.Notify import TicketNotifyEmail

to

from trac.ticket.notification import TicketNotifyEmail

Changed 22 months ago by duncanloxton@…

  • version changed from devel to 0.10.2

I have upgraded from 0.9.6 to 0.10.2 and cant seem to get this to work, where it was working fine before. I am now using source:trunk/contrib/trac-post-commit-hook and have added in the trac_url to my bat file which is the same now as post-commit.2.bat on this page. It fails silently and I cant find out why. Can any one help please??

Changed 22 months ago by sid

I'd recommend not using the one from trunk unless you are running 0.11dev (see r4159). Try this one instead: source:branches/0.10-stable/contrib/trac-post-commit-hook

Changed 22 months ago by duncanloxton@…

now I have source:branches/0.10-stable/contrib/trac-post-commit-hook and have tried attachment:post-commit.2.bat.

When using the keywords in a commit message there is no evidence of action on the ticket. Running from the command line results in:

Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\Documents and Settings\LoxtonD>cd \

C:\>cd svn\learnsvn\hooks

C:\svn\LearnSVN\hooks>post-commit
svnlook: missing argument: r
Type 'svnlook help' for usage.
svnlook: missing argument: r
Type 'svnlook help' for usage.
C:\svn\LearnSVN\hooks>

Is there somewhere I can try and fish out an error message?

My svn path is C:\svn\LearnSVN My trac path is C:\tracProjects\LearnSVN.db

Windows 2003 server, Python 2.3, SVN 1.3.1

Changed 21 months ago by sid

  • keywords hook removed

Right, you cannot run post-commit directly from the command line. It requires arguments. Notice line 2 and 3 in the script are:

SET REPOS=%1
SET REV=%2

Try submitting a changeset with the correct syntax in the changeset description. For example "references #1".

Changed 21 months ago by anonymous

Way of determining repository dir automatically (may be there is faster way of doing it: writing external program, but this is pure shell code)

 REM WINXP only, find our dir

 SET myName=%CD%

 if "%myName:~-1%" == "\" (
	SET myName=%myName:~0,-1%
 )

 :dirname
 if "%myName:~-1%" NEQ "\" (
	SET myName=%myName:~0,-1%
	GOTO dirname
 )
 REM strip backslash (\)
 SET myName=%myName:~0,-1%

 SET dirname=
 :basename
 if "%myName:~-1%" NEQ "\" (
	SET dirname=%myName:~-1%%dirname%
	SET myName=%myName:~0,-1%
	GOTO basename
 )

 SET SVNREP_DIR=C:\InetPub\svnroot\%dirname%
 SET TRACDB_DIR=C:\InetPub\tracroot\%dirname%

Changed 20 months ago by markus

Works with trac 0.10.3, international characters in changeset messages and ticket comments, no temporary file

Changed 20 months ago by markus

Works with trac 0.10.3, international characters in changeset messages and ticket comments, no temporary file

Changed 20 months ago by markus

Works with trac 0.10.3, international characters in changeset messages and ticket comments, no temporary file

Changed 20 months ago by anonymous

As posted in comment:ticket:1310:31, I uploaded the post-commit scripts for windows (2k and higher) and trac 0.10.3 which:

  • pass only the revision number, environment path and url to the python script.
  • work perfectly well with international characters because the log is retrieved in the python script instead of a temporary file.
  • do need less configuration because the batch scripts do not need any subversion binaries and can be placed outside the repository.

The post-commit.cmd file is placed in the hooks directory and simply calls the trac-post-commit-hook.cmd file which should be placed outside the subversion repository. That way, you'll need to configure the trac-post-commit-hook.cmd file only once for all repositories.

The trac-post-commit-hook.cmd checks whether a trac environment with the same name as the repository exists and calls the python script in the same directory if this is the case.

The python script has been modified to retrieve the log and author itself. I do not really know python, but I guess one could simplify the script and remove the user and log options that are added to the OptionParser and have become obsolete.

Note that this only works if your trac environments have the same name as the corresponding svn repository. Otherwise you'll have to add some code to the trac-post-commit-hook.cmd script.

The files attachment:post-commit.0.10.3.cmd, attachment:trac-post-commit-hook.0.10.3.cmd and attachment:trac-post-commit-hook.0.10.3.py have to be renamed by removing '.0.10.3'.

Changed 20 months ago by cboos

  • owner changed from jonas to cboos
  • status changed from new to assigned
  • milestone set to 0.10.4

Thanks for the scripts, I've updated them a bit and I think that only the trac-post-commit-hook.cmd file is needed.

Changed 20 months ago by cboos

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in r4532, r4533 (trunk) and r4534 (0.10-stable).

Changed 5 months ago by Chris

If you were to write a Trac backend for Scmbug, you wouldn't have to mess with hooks, .bat files, etc. and you would be offering more flexible integration.

http://freshmeat.net/projects/scmbug/

Add/Change #1602 (Fix & cleanup for .bat and .com for commit hook launch on Windows)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.