Edgewall Software
Modify

Opened 14 years ago

Closed 13 years ago

Last modified 12 years ago

#1602 closed enhancement (fixed)

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

Reported by: coreywangler@… Owned by: Christian Boos
Priority: low Milestone: 0.10.4
Component: general Version: 0.10.2
Severity: normal Keywords: contrib windows
Cc: Branch:
Release Notes:
API Changes:

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 (16)

pre-commit.bat (890 bytes ) - added by coreywangler@… 14 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@… 14 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@… 14 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@… 14 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@… 14 years ago.
renamed python script given in #897
trac-pre-commit-hook_4bat (3.0 KB ) - added by coreywangler@… 14 years ago.
renamed python script given in #897
trac-post-commit-hook_4bat (8.3 KB ) - added by coreywangler@… 14 years ago.
renamed python script given in #897
post-commit.2.bat (1.0 KB ) - added by coreywangler@… 14 years ago.
.bat file that launches trac-pre-commit-hook_4bat python script
pre-commit.2.bat (895 bytes ) - added by coreywangler@… 14 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@… 14 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@…> 14 years ago.
Updated to work with Trac 0.9-stable
trac-pre-commit-hook_4bat.2 (3.0 KB ) - added by Denney <denney@…> 14 years ago.
Updated to work with Trac 0.9-stable
post-commit.0.9.cmd (2.1 KB ) - added by jay@… 13 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 13 years 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 13 years 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 13 years ago.
Works with trac 0.10.3, international characters in changeset messages and ticket comments, no temporary file

Download all attachments as: .zip

Change History (45)

by coreywangler@…, 14 years ago

Attachment: pre-commit.bat added

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

by coreywangler@…, 14 years ago

Attachment: post-commit.bat added

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

by coreywangler@…, 14 years ago

Attachment: pre-commit.cmd added

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

by coreywangler@…, 14 years ago

Attachment: post-commit.cmd added

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

comment:1 by anonymous, 14 years ago

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.

comment:2 by coreywangler@…, 14 years ago

Keywords: contrib added; script removed
Milestone: 0.9
Priority: normalhigh
Severity: normalenhancement
Version: 0.8.1devel

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

by coreywangler@…, 14 years ago

Attachment: .2 added

renamed python script given in #897

by coreywangler@…, 14 years ago

Attachment: trac-pre-commit-hook_4bat added

renamed python script given in #897

by coreywangler@…, 14 years ago

Attachment: trac-post-commit-hook_4bat added

renamed python script given in #897

by coreywangler@…, 14 years ago

Attachment: post-commit.2.bat added

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

by coreywangler@…, 14 years ago

Attachment: pre-commit.2.bat added

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

comment:3 by coreywangler@…, 14 years ago

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.

comment:4 by d.mills@…, 14 years ago

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

by d.mills@…, 14 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.

comment:5 by d.mills@…, 14 years ago

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 '.

comment:6 by Christopher Lenz, 14 years ago

Milestone: 0.9
Priority: highlow

by Denney <denney@…>, 14 years ago

Updated to work with Trac 0.9-stable

by Denney <denney@…>, 14 years ago

Attachment: trac-pre-commit-hook_4bat.2 added

Updated to work with Trac 0.9-stable

comment:7 by Denney <denney@…>, 14 years ago

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.

comment:8 by Denney <denney@…>, 14 years ago

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.

comment:9 by anonymous, 14 years ago

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

comment:10 by Christian Boos, 14 years ago

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.

comment:11 by Christopher Lenz, 14 years ago

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

comment:12 by Christian Boos, 14 years ago

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.

comment:13 by Christian Boos, 14 years ago

  • 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.

comment:14 by Christian Boos, 14 years ago

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…

comment:15 by denney@…, 14 years ago

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.

comment:16 by Denney <denney@…>, 14 years ago

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

Updating the script properly fixes the problem.

by jay@…, 13 years ago

Attachment: post-commit.0.9.cmd added

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

comment:17 by Matthew Good, 13 years ago

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

comment:18 by oscar@…, 13 years ago

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.

comment:19 by oscar@…, 13 years ago

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?

comment:20 by sambloomquist, 13 years ago

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

comment:21 by duncanloxton@…, 13 years ago

Version: devel0.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??

comment:22 by sid, 13 years ago

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

comment:23 by duncanloxton@…, 13 years ago

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

comment:24 by sid, 13 years ago

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".

comment:25 by anonymous, 13 years ago

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%

by markus, 13 years ago

Attachment: post-commit.0.10.3.cmd added

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

by markus, 13 years ago

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

by markus, 13 years ago

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

comment:26 by anonymous, 13 years ago

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'.

comment:27 by Christian Boos, 13 years ago

Milestone: 0.10.4
Owner: changed from Jonas Borgström to Christian Boos
Status: newassigned

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

comment:28 by Christian Boos, 13 years ago

Resolution: fixed
Status: assignedclosed

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

comment:29 by Chris, 12 years ago

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/

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to as closed The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.