You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Robert Dailey <rc...@gmail.com> on 2008/08/24 21:33:25 UTC

Problem with python + hook

I'm trying to create a post-commit hook using python, but it isn't
working. I can't tell where it is failing, either, as I"m not sure if
any logging is taking place somewhere. Can someone tell me if there
are any error logs somewhere I can look at? Also, is there anything
obviously wrong with my script? Thanks. The filename is "post-commit",
by the way.

#!/usr/bin/python

#REPOS="$1"
#REV="$2"

#commit-email.pl "$REPOS" "$REV" commit-watchers@example.org
#log-commit.py --repository "$REPOS" --revision "$REV"

#svn update --non-interactive /srv/http/website
#chown -R :svn_group /srv/http
#chmod -R 774 /srv/http/website

import sys
from subprocess import call

REPOS = sys.argv[1]
REV = sys.argv[2]

print "This is a test"

call( "svn", "update", "--non-interactive", "/srv/http/website" )

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Problem with python + hook

Posted by Robert Dailey <rc...@gmail.com>.
On Mon, Aug 25, 2008 at 11:50 AM, John Peacock <
john.peacock@havurah-software.org> wrote:

> Robert Dailey wrote:
>
>> So, I ran the python script from the command line as suggested by John,
>> and it worked just fine. My next step was to setup some minimal file logging
>> in the post commit script, however I'm finding that the script fails when
>> run by subversion because the open() function in python does not have
>> sufficient privileges, for some reason. However I can run this manually from
>> the command line and the open() function succeeds.
>>
>
> The script is run as the same user as Subversion itself, not as your user.
>  That means that any files that are going to be changed by the script must
> be owned by or at least writeable by that user.
>
> You will need to switch that that user before testing, e.g.:
>
>        # su svnuser -s /bin/bash
>
> You can rerun the script as many times as you want by just passing in the
> repository and revision on the commandline:
>
>        $ ./post-commit $PWD/.. 23
>
> (assuming you are inside the REPOS/hooks directory and revision 23 was a
> revision where something interesting happened).


I actually setup xinetd to run svnserve as user 'svn', and I even switched
to user 'svn' to run the script and it still works fine when running the
post-commit manually. However, subversion running it doesn't work for some
reason.

Re: Problem with python + hook

Posted by John Peacock <jo...@havurah-software.org>.
Robert Dailey wrote:
> So, I ran the python script from the command line as suggested by John, 
> and it worked just fine. My next step was to setup some minimal file 
> logging in the post commit script, however I'm finding that the script 
> fails when run by subversion because the open() function in python does 
> not have sufficient privileges, for some reason. However I can run this 
> manually from the command line and the open() function succeeds.

The script is run as the same user as Subversion itself, not as your 
user.  That means that any files that are going to be changed by the 
script must be owned by or at least writeable by that user.

You will need to switch that that user before testing, e.g.:

	# su svnuser -s /bin/bash

You can rerun the script as many times as you want by just passing in 
the repository and revision on the commandline:

	$ ./post-commit $PWD/.. 23

(assuming you are inside the REPOS/hooks directory and revision 23 was a 
revision where something interesting happened).

John

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Problem with python + hook

Posted by Robert Dailey <rc...@gmail.com>.
On Mon, Aug 25, 2008 at 8:25 AM, John Peacock <
john.peacock@havurah-software.org> wrote:

> Robert Dailey wrote:
>
>> I tried your hints but I'm still not getting anything. I'm assuming
>> the errors will appear during the commit process on the client,
>> however I have seen no errors.
>>
>
> Please read (and follow) my posting here:
>
> http://svn.haxx.se/users/archive-2007-10/0498.shtml
>
> on developing hook scripts.  The most important step is #3 (see the
> paragraph with the string "DON'T SKIP THIS STEP!" for why).  You should test
> your proposed post-commit hook outside of Subversion itself, because this is
> the only sure-fired way to make sure that the script itself works.  Only
> once you have confirmed that the script fires and does what you think it
> should do can you hope to have it run from Subversion...


So, I ran the python script from the command line as suggested by John, and
it worked just fine. My next step was to setup some minimal file logging in
the post commit script, however I'm finding that the script fails when run
by subversion because the open() function in python does not have sufficient
privileges, for some reason. However I can run this manually from the
command line and the open() function succeeds.

So, as a second option, I attempted to raise an exception in my post-commit
script that simply displayed the user currently running the process. The
user should be "svn", but I wanted to make sure. However, the script fails
yet again saying the following:

Warning: post-commit hook failed (exit code 1) with output:
Warning: Traceback (most recent call last):
Warning:   File "/srv/svn/repo/www/hooks/post-commit", line 6, in <module>
Warning:     raise Exception( os.getlogin() )
Warning: OSError: [Errno 22] Invalid argument


It says "Invalid Argument" right now, but I ran this manually and the
os.getlogin() converted to a string just fine. I'm thinking this has
something to do with my environment not being setup correctly when the
post-commit script is run by subversion. Below is my most recent post-commit
script:

#------------------------------------------
#!/usr/bin/env python
import sys
import os
from subprocess import call

raise Exception( os.getlogin() )
logfile = open( "post-commit-log", "w+b" )
sys.stdout = logfile
sys.stderr = logfile

#_repos = sys.argv[1]
#_rev = sys.argv[2]

call( ["/usr/bin/svn", "update", "--non-interactive", "/srv/http/website"] )
exit( 1 )
#------------------------------------------

As you can see, I'm raising an "Exception", which should display the current
login username, but this fails when running from subversion. Is there more I
must do to initialize the environment so python runs properly? This may not
be an appropriate question for this mailing list, so in the meantime I'll
seek out information elsewhere, but I'm hoping someone here might know a
thing or two. Thanks for everyone's continued help.

Re: Problem with python + hook

Posted by John Peacock <jo...@havurah-software.org>.
Robert Dailey wrote:
> I tried your hints but I'm still not getting anything. I'm assuming
> the errors will appear during the commit process on the client,
> however I have seen no errors.

Please read (and follow) my posting here:

http://svn.haxx.se/users/archive-2007-10/0498.shtml

on developing hook scripts.  The most important step is #3 (see the 
paragraph with the string "DON'T SKIP THIS STEP!" for why).  You should 
test your proposed post-commit hook outside of Subversion itself, 
because this is the only sure-fired way to make sure that the script 
itself works.  Only once you have confirmed that the script fires and 
does what you think it should do can you hope to have it run from 
Subversion...

John

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

RE: Problem with python + hook

Posted by John Niven <jn...@bravurasolutions.com>.
> -----Original Message-----
> From: Ryan Schmidt [mailto:subversion-2008c@ryandesign.com] 
> Sent: Monday, 25 August 2008 15:47
> To: John Niven
> Cc: Robert Dailey; David Weintraub; svn
> Subject: Re: Problem with python + hook
> 
> > As far as I can remember the "#!/usr/bin/env ..." idiom is 
> necessary 
> > with Python, and since your hook scripts run with no environment 
> > you'll need to specify where python is.
> 
> Oh it is? Well I don't know Python. I'm sure the env idiom is 
> useful when a path to python is in the environment, but even 
> the Subversion source comes with a Python script that does 
> not use this strategy:
> 
> http://svn.collab.net/repos/svn/tags/1.5.1/tools/dist/write-
> announcement.py
> 
> So I doubt it's absolutely required.

You're quite right; I believe it's preferred since you can specify the
Python version (e.g. "/usr/bin/env python2.2"), but that's hardly
relevant here.

(That'll teach me to post before remembering fully... It's been a while
since I last used Python)

Cheers
John

> 
> 
> >> None of these have had any effect.
> 
> Did you also change to calling the absolute path of svn? See below.
> 
> 
> >>>>>> call( "svn", "update", "--non-interactive", 
> "/srv/http/website" )
> >>>
> >>>
> >>> You need to specify the absolute path to the svn binary
> >> (and any other
> >>> binaries you want to use) since hooks run with an empty 
> environment 
> >>> for security reasons.
> 
> Call svn with its absolute path as well, presumably:
> 
> call( "/usr/local/bin/svn", "update", "--non-interactive", 
> "/srv/http/ website" )
> 
> Or wherever Subversion actually is on your system.
> 
> Capture all error and regular output from this process and 
> write it to a logfile of your own, with whatever syntax one 
> uses for that in Python.
> 
> 
> If that doesn't help, try a simple post-commit hook which 
> just writes a line to a file. Does it work?
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org


Re: Problem with python + hook

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Aug 24, 2008, at 22:30, John Niven wrote:

>> At the top of "post-commit" file, I put:
>>
>> #!/usr/bin/python
>>
>> I also tried:
>>
>> #!/usr/bin/env python
>
> I suspect it would need to be...
> #!/usr/bin/env /usr/bin/python

Asking the env program where python is won't work since as I said the  
environment will be empty. Just specify the absolute path to the  
binary that should execute the script:

#!/usr/bin/python


> As far as I can remember the "#!/usr/bin/env ..." idiom is necessary
> with Python, and since your hook scripts run with no environment  
> you'll
> need to specify where python is.

Oh it is? Well I don't know Python. I'm sure the env idiom is useful  
when a path to python is in the environment, but even the Subversion  
source comes with a Python script that does not use this strategy:

http://svn.collab.net/repos/svn/tags/1.5.1/tools/dist/write- 
announcement.py

So I doubt it's absolutely required.


>> None of these have had any effect.

Did you also change to calling the absolute path of svn? See below.


>>>>>> call( "svn", "update", "--non-interactive", "/srv/http/website" )
>>>
>>>
>>> You need to specify the absolute path to the svn binary
>> (and any other
>>> binaries you want to use) since hooks run with an empty environment
>>> for security reasons.

Call svn with its absolute path as well, presumably:

call( "/usr/local/bin/svn", "update", "--non-interactive", "/srv/http/ 
website" )

Or wherever Subversion actually is on your system.

Capture all error and regular output from this process and write it  
to a logfile of your own, with whatever syntax one uses for that in  
Python.


If that doesn't help, try a simple post-commit hook which just writes  
a line to a file. Does it work?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: RE: Re: Problem with python + hook

Posted by Robert Dailey <rc...@gmail.com>.
#!/usr/bin/python *is* correct. /usr/bin/python is a link to the
actual binary. I'm assuming links are viable.

Any other reasons why this wouldn't be working?

On Sun, Aug 24, 2008 at 10:36 PM, John Niven
<jn...@bravurasolutions.com> wrote:
> (Disregard that; I've remembered why Python uses /usr/bin/env - it's to
> find python on the $PATH. Use the first approach, and check that the
> path is correct).
>
>> -----Original Message-----
>> From: John Niven [mailto:jniven@bravurasolutions.com]
>> Sent: Monday, 25 August 2008 15:30
>> To: Robert Dailey; Ryan Schmidt
>> Cc: David Weintraub; svn
>> Subject: RE: Re: Problem with python + hook
>>
>> > -----Original Message-----
>> > From: Robert Dailey [mailto:rcdailey@gmail.com]
>> > Sent: Monday, 25 August 2008 15:26
>> > To: Ryan Schmidt
>> > Cc: David Weintraub; svn
>> > Subject: Re: Problem with python + hook
>> >
>> > At the top of "post-commit" file, I put:
>> >
>> > #!/usr/bin/python
>> >
>> > I also tried:
>> >
>> > #!/usr/bin/env python
>>
>> I suspect it would need to be...
>> #!/usr/bin/env /usr/bin/python
>>
>> As far as I can remember the "#!/usr/bin/env ..." idiom is
>> necessary with Python, and since your hook scripts run with
>> no environment you'll need to specify where python is.
>>
>> Cheers
>> John
>>
>> >
>> > None of these have had any effect.
>> >
>> > On Sun, Aug 24, 2008 at 10:18 PM, Ryan Schmidt
>> > <su...@ryandesign.com> wrote:
>> > >
>> > > On Aug 24, 2008, at 22:12, Robert Dailey wrote:
>> > >
>> > >> I tried your hints but I'm still not getting anything. I'm
>> > assuming
>> > >> the errors will appear during the commit process on the client,
>> > >> however I have seen no errors. I don't think that
>> > subversion is even
>> > >> trying to execute it... I've set the chmod to 777, and it
>> > still won't
>> > >> work.
>> > >
>> > > The output of a post-commit hook, whether to stdout or
>> > stderr, is discarded.
>> > > You won't ever see it. You should write any relevant
>> information to
>> > > your own logfile if desired.
>> > >
>> > >
>> > >> Anything else I can try?
>> > >
>> > >
>> > >>> On Sun, Aug 24, 2008 at 5:33 PM, Robert Dailey wrote:
>> > >>>>
>> > >>>
>> > >>>> call( "svn", "update", "--non-interactive",
>> "/srv/http/website" )
>> > >
>> > >
>> > > You need to specify the absolute path to the svn binary
>> > (and any other
>> > > binaries you want to use) since hooks run with an empty
>> environment
>> > > for security reasons.
>> > >
>> > >
>> > >
>> >
>> >
>> ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
>> > For additional commands, e-mail: users-help@subversion.tigris.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
>> For additional commands, e-mail: users-help@subversion.tigris.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: users-help@subversion.tigris.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

RE: RE: Re: Problem with python + hook

Posted by John Niven <jn...@bravurasolutions.com>.
(Disregard that; I've remembered why Python uses /usr/bin/env - it's to
find python on the $PATH. Use the first approach, and check that the
path is correct). 

> -----Original Message-----
> From: John Niven [mailto:jniven@bravurasolutions.com] 
> Sent: Monday, 25 August 2008 15:30
> To: Robert Dailey; Ryan Schmidt
> Cc: David Weintraub; svn
> Subject: RE: Re: Problem with python + hook
> 
> > -----Original Message-----
> > From: Robert Dailey [mailto:rcdailey@gmail.com]
> > Sent: Monday, 25 August 2008 15:26
> > To: Ryan Schmidt
> > Cc: David Weintraub; svn
> > Subject: Re: Problem with python + hook
> > 
> > At the top of "post-commit" file, I put:
> > 
> > #!/usr/bin/python
> > 
> > I also tried:
> > 
> > #!/usr/bin/env python
> 
> I suspect it would need to be...
> #!/usr/bin/env /usr/bin/python
> 
> As far as I can remember the "#!/usr/bin/env ..." idiom is 
> necessary with Python, and since your hook scripts run with 
> no environment you'll need to specify where python is.
> 
> Cheers
> John
> 
> > 
> > None of these have had any effect.
> > 
> > On Sun, Aug 24, 2008 at 10:18 PM, Ryan Schmidt 
> > <su...@ryandesign.com> wrote:
> > >
> > > On Aug 24, 2008, at 22:12, Robert Dailey wrote:
> > >
> > >> I tried your hints but I'm still not getting anything. I'm
> > assuming
> > >> the errors will appear during the commit process on the client, 
> > >> however I have seen no errors. I don't think that
> > subversion is even
> > >> trying to execute it... I've set the chmod to 777, and it
> > still won't
> > >> work.
> > >
> > > The output of a post-commit hook, whether to stdout or
> > stderr, is discarded.
> > > You won't ever see it. You should write any relevant 
> information to 
> > > your own logfile if desired.
> > >
> > >
> > >> Anything else I can try?
> > >
> > >
> > >>> On Sun, Aug 24, 2008 at 5:33 PM, Robert Dailey wrote:
> > >>>>
> > >>>
> > >>>> call( "svn", "update", "--non-interactive", 
> "/srv/http/website" )
> > >
> > >
> > > You need to specify the absolute path to the svn binary
> > (and any other
> > > binaries you want to use) since hooks run with an empty 
> environment 
> > > for security reasons.
> > >
> > >
> > >
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
> > For additional commands, e-mail: users-help@subversion.tigris.org
> > 
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: users-help@subversion.tigris.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org


RE: Re: Problem with python + hook

Posted by John Niven <jn...@bravurasolutions.com>.
> -----Original Message-----
> From: Robert Dailey [mailto:rcdailey@gmail.com] 
> Sent: Monday, 25 August 2008 15:26
> To: Ryan Schmidt
> Cc: David Weintraub; svn
> Subject: Re: Problem with python + hook
> 
> At the top of "post-commit" file, I put:
> 
> #!/usr/bin/python
> 
> I also tried:
> 
> #!/usr/bin/env python

I suspect it would need to be...
#!/usr/bin/env /usr/bin/python

As far as I can remember the "#!/usr/bin/env ..." idiom is necessary
with Python, and since your hook scripts run with no environment you'll
need to specify where python is.

Cheers
John

> 
> None of these have had any effect.
> 
> On Sun, Aug 24, 2008 at 10:18 PM, Ryan Schmidt 
> <su...@ryandesign.com> wrote:
> >
> > On Aug 24, 2008, at 22:12, Robert Dailey wrote:
> >
> >> I tried your hints but I'm still not getting anything. I'm 
> assuming 
> >> the errors will appear during the commit process on the client, 
> >> however I have seen no errors. I don't think that 
> subversion is even 
> >> trying to execute it... I've set the chmod to 777, and it 
> still won't 
> >> work.
> >
> > The output of a post-commit hook, whether to stdout or 
> stderr, is discarded.
> > You won't ever see it. You should write any relevant information to 
> > your own logfile if desired.
> >
> >
> >> Anything else I can try?
> >
> >
> >>> On Sun, Aug 24, 2008 at 5:33 PM, Robert Dailey wrote:
> >>>>
> >>>
> >>>> call( "svn", "update", "--non-interactive", "/srv/http/website" )
> >
> >
> > You need to specify the absolute path to the svn binary 
> (and any other 
> > binaries you want to use) since hooks run with an empty environment 
> > for security reasons.
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: users-help@subversion.tigris.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org


Re: Problem with python + hook

Posted by Robert Dailey <rc...@gmail.com>.
At the top of "post-commit" file, I put:

#!/usr/bin/python

I also tried:

#!/usr/bin/env python

None of these have had any effect.

On Sun, Aug 24, 2008 at 10:18 PM, Ryan Schmidt
<su...@ryandesign.com> wrote:
>
> On Aug 24, 2008, at 22:12, Robert Dailey wrote:
>
>> I tried your hints but I'm still not getting anything. I'm assuming
>> the errors will appear during the commit process on the client,
>> however I have seen no errors. I don't think that subversion is even
>> trying to execute it... I've set the chmod to 777, and it still won't
>> work.
>
> The output of a post-commit hook, whether to stdout or stderr, is discarded.
> You won't ever see it. You should write any relevant information to your own
> logfile if desired.
>
>
>> Anything else I can try?
>
>
>>> On Sun, Aug 24, 2008 at 5:33 PM, Robert Dailey wrote:
>>>>
>>>
>>>> call( "svn", "update", "--non-interactive", "/srv/http/website" )
>
>
> You need to specify the absolute path to the svn binary (and any other
> binaries you want to use) since hooks run with an empty environment for
> security reasons.
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Problem with python + hook

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Aug 24, 2008, at 22:12, Robert Dailey wrote:

> I tried your hints but I'm still not getting anything. I'm assuming
> the errors will appear during the commit process on the client,
> however I have seen no errors. I don't think that subversion is even
> trying to execute it... I've set the chmod to 777, and it still won't
> work.

The output of a post-commit hook, whether to stdout or stderr, is  
discarded. You won't ever see it. You should write any relevant  
information to your own logfile if desired.


> Anything else I can try?


>> On Sun, Aug 24, 2008 at 5:33 PM, Robert Dailey wrote:
>>>
>>
>>> call( "svn", "update", "--non-interactive", "/srv/http/website" )


You need to specify the absolute path to the svn binary (and any  
other binaries you want to use) since hooks run with an empty  
environment for security reasons.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Problem with python + hook

Posted by Robert Dailey <rc...@gmail.com>.
Thanks for your help.

I tried your hints but I'm still not getting anything. I'm assuming
the errors will appear during the commit process on the client,
however I have seen no errors. I don't think that subversion is even
trying to execute it... I've set the chmod to 777, and it still won't
work.

Anything else I can try?


On Sun, Aug 24, 2008 at 9:08 PM, David Weintraub <qa...@gmail.com> wrote:
> A couple of hints:
>
> Hooks only print out information if:
>
> 1). The information is sent to STDERR and not STDOUT
> 2). If the hook itself fails (that is the exit code is not zero)
>
> If you want to see if your hook is working, cause it to fail with an
> exit code of "2" and print to STDERR. I'm not a Python person, but it
> would be something like this:
>
> import sys
> print >> sys.stderr, "this is a test"
> call( "svn", "update", "--non-interactive", "/srv/http/website" )
> exit 2
>
> --
> David Weintraub
> qazwart@gmail.com
>
>
>
> On Sun, Aug 24, 2008 at 5:33 PM, Robert Dailey <rc...@gmail.com> wrote:
>> I'm trying to create a post-commit hook using python, but it isn't
>> working. I can't tell where it is failing, either, as I"m not sure if
>> any logging is taking place somewhere. Can someone tell me if there
>> are any error logs somewhere I can look at? Also, is there anything
>> obviously wrong with my script? Thanks. The filename is "post-commit",
>> by the way.
>>
>> #!/usr/bin/python
>>
>> #REPOS="$1"
>> #REV="$2"
>>
>> #commit-email.pl "$REPOS" "$REV" commit-watchers@example.org
>> #log-commit.py --repository "$REPOS" --revision "$REV"
>>
>> #svn update --non-interactive /srv/http/website
>> #chown -R :svn_group /srv/http
>> #chmod -R 774 /srv/http/website
>>
>> import sys
>> from subprocess import call
>>
>> REPOS = sys.argv[1]
>> REV = sys.argv[2]
>>
>> print "This is a test"
>>
>> call( "svn", "update", "--non-interactive", "/srv/http/website" )
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
>> For additional commands, e-mail: users-help@subversion.tigris.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Problem with python + hook

Posted by David Weintraub <qa...@gmail.com>.
A couple of hints:

Hooks only print out information if:

1). The information is sent to STDERR and not STDOUT
2). If the hook itself fails (that is the exit code is not zero)

If you want to see if your hook is working, cause it to fail with an
exit code of "2" and print to STDERR. I'm not a Python person, but it
would be something like this:

import sys
print >> sys.stderr, "this is a test"
call( "svn", "update", "--non-interactive", "/srv/http/website" )
exit 2

--
David Weintraub
qazwart@gmail.com



On Sun, Aug 24, 2008 at 5:33 PM, Robert Dailey <rc...@gmail.com> wrote:
> I'm trying to create a post-commit hook using python, but it isn't
> working. I can't tell where it is failing, either, as I"m not sure if
> any logging is taking place somewhere. Can someone tell me if there
> are any error logs somewhere I can look at? Also, is there anything
> obviously wrong with my script? Thanks. The filename is "post-commit",
> by the way.
>
> #!/usr/bin/python
>
> #REPOS="$1"
> #REV="$2"
>
> #commit-email.pl "$REPOS" "$REV" commit-watchers@example.org
> #log-commit.py --repository "$REPOS" --revision "$REV"
>
> #svn update --non-interactive /srv/http/website
> #chown -R :svn_group /srv/http
> #chmod -R 774 /srv/http/website
>
> import sys
> from subprocess import call
>
> REPOS = sys.argv[1]
> REV = sys.argv[2]
>
> print "This is a test"
>
> call( "svn", "update", "--non-interactive", "/srv/http/website" )
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: users-help@subversion.tigris.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org