#1602 closed enhancement (fixed)
Fix & cleanup for .bat and .com for commit hook launch on Windows
Reported by: | 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: | |||
Internal 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)
Change History (45)
by , 19 years ago
Attachment: | pre-commit.bat added |
---|
by , 19 years ago
Attachment: | post-commit.bat added |
---|
fixed .bat file for launching the corresponding python hook script (from #897) in windows
by , 19 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 , 19 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 , 19 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 , 19 years ago
Keywords: | contrib added; script removed |
---|---|
Milestone: | → 0.9 |
Priority: | normal → high |
Severity: | normal → enhancement |
Version: | 0.8.1 → devel |
Changed the properties of this ticket to match that of #897
by , 19 years ago
Attachment: | post-commit.2.bat added |
---|
.bat file that launches trac-pre-commit-hook_4bat python script
by , 19 years ago
Attachment: | pre-commit.2.bat added |
---|
.bat file that launches trac-pre-commit-hook_4bat python script
comment:3 by , 19 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 , 19 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 , 19 years ago
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 by , 19 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 , 19 years ago
Milestone: | 0.9 |
---|---|
Priority: | high → low |
by , 19 years ago
Attachment: | trac-post-commit-hook_4bat.2 added |
---|
Updated to work with Trac 0.9-stable
by , 19 years ago
Attachment: | trac-pre-commit-hook_4bat.2 added |
---|
Updated to work with Trac 0.9-stable
comment:7 by , 19 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 , 19 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 , 19 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 , 19 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:12 by , 19 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 , 19 years ago
-
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 by , 19 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 , 19 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 , 19 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 , 18 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 , 18 years ago
#3464 has been marked as a duplicate. It has an alternate version of the hook scripts to review.
comment:18 by , 18 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 , 18 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 , 18 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 , 18 years ago
Version: | devel → 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 by , 18 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 , 18 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 , 18 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 , 18 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 , 18 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 , 18 years ago
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
by , 18 years ago
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 by , 18 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 , 18 years ago
Milestone: | → 0.10.4 |
---|---|
Owner: | changed from | to
Status: | new → 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 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:29 by , 17 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.
fixed .bat file for launching the corresponding python hook script (from #897) in windows