Ticket #1602 (closed enhancement: fixed)
Opened 7 years ago
Last modified 4 years 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: | |||
| 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
Change History
Changed 7 years ago by coreywangler@…
- Attachment pre-commit.bat added
Changed 7 years ago by coreywangler@…
- Attachment post-commit.bat added
fixed .bat file for launching the corresponding python hook script (from #897) in windows
Changed 7 years ago by coreywangler@…
- Attachment pre-commit.cmd added
fixed .com file for launching the corresponding python hook script (from 0.8-stable/contrib/) in windows
Changed 7 years ago by coreywangler@…
- Attachment post-commit.cmd added
fixed .com file for launching the corresponding python hook script (from 0.8-stable/contrib/) in windows
comment:1 Changed 7 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.
comment:2 Changed 7 years ago by coreywangler@…
- Keywords contrib added; script removed
- Milestone set to 0.9
- Priority changed from normal to high
- Severity changed from normal to enhancement
- Version changed from 0.8.1 to devel
Changed the properties of this ticket to match that of #897
Changed 7 years ago by coreywangler@…
- Attachment trac-pre-commit-hook_4bat added
renamed python script given in #897
Changed 7 years ago by coreywangler@…
- Attachment trac-post-commit-hook_4bat added
renamed python script given in #897
Changed 7 years ago by coreywangler@…
- Attachment post-commit.2.bat added
.bat file that launches trac-pre-commit-hook_4bat python script
Changed 7 years ago by coreywangler@…
- Attachment pre-commit.2.bat added
.bat file that launches trac-pre-commit-hook_4bat python script
comment:3 Changed 7 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.
comment:4 Changed 7 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 7 years ago by d.mills@…
- Attachment trac-post-commit-hook-french added
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 Changed 7 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 '.
comment:6 Changed 7 years ago by cmlenz
- Milestone 0.9 deleted
- Priority changed from high to low
Changed 6 years ago by Denney <denney@…>
- Attachment trac-post-commit-hook_4bat.2 added
Updated to work with Trac 0.9-stable
Changed 6 years ago by Denney <denney@…>
- Attachment trac-pre-commit-hook_4bat.2 added
Updated to work with Trac 0.9-stable
comment:7 Changed 6 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.
comment:8 Changed 6 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.
comment:9 Changed 6 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
comment:10 Changed 6 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.
comment:11 Changed 6 years ago by cmlenz
cboos, server upgraded to r3216, getting another error now :-/
comment:12 Changed 6 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.
comment:13 Changed 6 years ago by cboos
-
api.py
258 258 if hasattr(content, 'read'): 259 259 content = content.read(self.get_max_preview_size()) 260 260 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 262 265 263 266 # Determine candidate `IHTMLPreviewRenderer`s 264 267 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
126 126 if content and is_binary(content): 127 127 return 'application/octet-stream' 128 128 else: 129 return None129 return 'text/plain' 130 130 131 131 def is_binary(data): 132 132 """Detect binary content by checking the first thousand bytes for zeroes.
comment:14 Changed 6 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...
comment:15 Changed 6 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.
comment:16 Changed 6 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 6 years ago by jay@…
- Attachment post-commit.0.9.cmd added
Works with 0.9 stable standard Trac hooks source:branches/0.9-stable/contrib/
comment:17 Changed 6 years ago by mgood
#3464 has been marked as a duplicate. It has an alternate version of the hook scripts to review.
comment:18 Changed 5 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.
comment:19 Changed 5 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?
comment:20 Changed 5 years 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
comment:21 Changed 5 years 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??
comment:22 Changed 5 years 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
comment:23 Changed 5 years 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
comment:24 Changed 5 years 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".
comment:25 Changed 5 years 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 5 years ago by markus
- 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
Changed 5 years ago by markus
- Attachment trac-post-commit-hook.0.10.3.cmd added
Works with trac 0.10.3, international characters in changeset messages and ticket comments, no temporary file
Changed 5 years ago by markus
- Attachment trac-post-commit-hook.0.10.3.py added
Works with trac 0.10.3, international characters in changeset messages and ticket comments, no temporary file
comment:26 Changed 5 years 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'.
comment:27 Changed 5 years ago by cboos
- Milestone set to 0.10.4
- Owner changed from jonas to cboos
- Status changed from new to assigned
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 Changed 5 years ago by cboos
- Resolution set to fixed
- Status changed from assigned to closed
comment:29 Changed 4 years 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.



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