[prev in list] [next in list] [prev in thread] [next in thread]
List: mercurial
Subject: Re: Accessing HTTP user in a hook
From: John Ament <my.reprive () gmail ! com>
Date: 2010-06-29 12:48:12
Message-ID: AANLkTimrB5yVS3IXXTDFlwUl8RzZbPzmGkgyoF6V57CD () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Probably the better explanation is to link to
http://www.selenic.com/mercurial/hgrc.5.html#contents which details each of
the environment variables that are listed.
On Tue, Jun 29, 2010 at 8:40 AM, Maxim Khitrov <mkhitrov@gmail.com> wrote:
> On Tue, Jun 29, 2010 at 8:31 AM, John Ament <my.reprive@gmail.com> wrote:
> > On Tue, Jun 29, 2010 at 6:30 AM, Maxim Khitrov <mkhitrov@gmail.com>
> wrote:
> >>
> >> On Tue, Jun 29, 2010 at 5:41 AM, John Ament <my.reprive@gmail.com>
> wrote:
> >> > On Tue, Jun 29, 2010 at 12:15 AM, Matt Mackall <mpm@selenic.com>
> wrote:
> >> >> On Mon, 2010-06-28 at 21:05 -0400, John Ament wrote:
> >> >> > Hmmm. I think it has to do with how the script is being called. I
> >> >> > executed yours and it worked fine for me.
> >> >> >
> >> >> > The script I'm playing with is mozilla's pushlog hook. The call
> >> >> > looks
> >> >> > like this:
> >> >> >
> >> >> > python:mozhghooks.pushlog.log
> >> >> >
> >> >> > where the log function is defined like this:
> >> >> >
> >> >> > def log(ui, repo, node, **kwargs):
> >> >> >
> >> >> > There are other calls to os, it just seems like the environment is
> >> >> > getting passed along.
> >> >>
> >> >> No, for hooks, the args get passed in via kwargs.
> >> >>
> >> >
> >> > To be honest with you, I'm not sure which args you're referring to.
> os
> >> > wouldn't be an arg in this case, right?
> >>
> >> Now I understand. Matt is referring to the fact that executing a
> >> python function is different from running an external program for a
> >> hook. In my example, even though it's python code, it was executed as
> >> a separate process. With external programs, HG_URL is passed as an
> >> environment variable. For python functions, you need to look at kwargs
> >> dictionary. Here's a modified version of my previous test.py code:
> >>
> >> def log(ui, repo, node, **kwargs):
> >> print 'Username:', kwargs['url'].split(':')[-1]
> >>
> >> Instead of os.environ['HG_URL'] you need to look at kwargs['url'].
> >> Everything else is identical. With this modification, I can set my
> >> hook to the following and everything should work as before:
> >>
> >> [hooks]
> >> changegroup = python:test.log
> >>
> >> Python has to be able to find the specified function, but it sounds
> >> like that's not a problem in your case.
> >>
> >> - Max
> >
> > Yep so that was it. Great, thanks!
> >
> > Is there a list of everything available in kwargs somewhere?
> >
> > John
>
> John, please don't top-post. See hgrc(5) for info on what is in kwargs:
>
> http://www.selenic.com/mercurial/hgrc.5.html
>
> "Arguments listed as environment variables above are passed as keyword
> arguments, with no HG_ prefix, and names in lower case."
>
> - Max
>
[Attachment #5 (text/html)]
Probably the better explanation is to link to <a \
href="http://www.selenic.com/mercurial/hgrc.5.html#contents">http://www.selenic.com/mercurial/hgrc.5.html#contents</a> \
which details each of the environment variables that are listed.<br> <br><div \
class="gmail_quote">On Tue, Jun 29, 2010 at 8:40 AM, Maxim Khitrov <span \
dir="ltr"><<a href="mailto:mkhitrov@gmail.com">mkhitrov@gmail.com</a>></span> \
wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, \
204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <div><div></div><div \
class="h5">On Tue, Jun 29, 2010 at 8:31 AM, John Ament <<a \
href="mailto:my.reprive@gmail.com">my.reprive@gmail.com</a>> wrote:<br> > On \
Tue, Jun 29, 2010 at 6:30 AM, Maxim Khitrov <<a \
href="mailto:mkhitrov@gmail.com">mkhitrov@gmail.com</a>> wrote:<br> >><br>
>> On Tue, Jun 29, 2010 at 5:41 AM, John Ament <<a \
href="mailto:my.reprive@gmail.com">my.reprive@gmail.com</a>> wrote:<br> >> \
> On Tue, Jun 29, 2010 at 12:15 AM, Matt Mackall <<a \
href="mailto:mpm@selenic.com">mpm@selenic.com</a>> wrote:<br> >> >> On \
Mon, 2010-06-28 at 21:05 -0400, John Ament wrote:<br> >> >> > Hmmm. I \
think it has to do with how the script is being called. I<br> >> >> > \
executed yours and it worked fine for me.<br> >> >> ><br>
>> >> > The script I'm playing with is mozilla's pushlog hook. \
The call<br> >> >> > looks<br>
>> >> > like this:<br>
>> >> ><br>
>> >> > python:mozhghooks.pushlog.log<br>
>> >> ><br>
>> >> > where the log function is defined like this:<br>
>> >> ><br>
>> >> > def log(ui, repo, node, **kwargs):<br>
>> >> ><br>
>> >> > There are other calls to os, it just seems like the \
environment is<br> >> >> > getting passed along.<br>
>> >><br>
>> >> No, for hooks, the args get passed in via kwargs.<br>
>> >><br>
>> ><br>
>> > To be honest with you, I'm not sure which args you're referring \
to. os<br> >> > wouldn't be an arg in this case, right?<br>
>><br>
>> Now I understand. Matt is referring to the fact that executing a<br>
>> python function is different from running an external program for a<br>
>> hook. In my example, even though it's python code, it was executed \
as<br> >> a separate process. With external programs, HG_URL is passed as \
an<br> >> environment variable. For python functions, you need to look at \
kwargs<br> >> dictionary. Here's a modified version of my previous test.py \
code:<br> >><br>
>> def log(ui, repo, node, **kwargs):<br>
>> print 'Username:', \
kwargs['url'].split(':')[-1]<br> >><br>
>> Instead of os.environ['HG_URL'] you need to look at \
kwargs['url'].<br> >> Everything else is identical. With this \
modification, I can set my<br> >> hook to the following and everything should \
work as before:<br> >><br>
>> [hooks]<br>
>> changegroup = python:test.log<br>
>><br>
>> Python has to be able to find the specified function, but it sounds<br>
>> like that's not a problem in your case.<br>
>><br>
>> - Max<br>
><br>
> Yep so that was it. Great, thanks!<br>
><br>
> Is there a list of everything available in kwargs somewhere?<br>
><br>
> John<br>
<br>
</div></div>John, please don't top-post. See hgrc(5) for info on what is in \
kwargs:<br> <br>
<a href="http://www.selenic.com/mercurial/hgrc.5.html" \
target="_blank">http://www.selenic.com/mercurial/hgrc.5.html</a><br> <br>
"Arguments listed as environment variables above are passed as keyword<br>
arguments, with no HG_ prefix, and names in lower case."<br>
<br>
- Max<br>
</blockquote></div><br>
_______________________________________________
Mercurial mailing list
Mercurial@selenic.com
http://selenic.com/mailman/listinfo/mercurial
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic