[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">&lt;<a href="mailto:mkhitrov@gmail.com">mkhitrov@gmail.com</a>&gt;</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 &lt;<a \
href="mailto:my.reprive@gmail.com">my.reprive@gmail.com</a>&gt; wrote:<br> &gt; On \
Tue, Jun 29, 2010 at 6:30 AM, Maxim Khitrov &lt;<a \
href="mailto:mkhitrov@gmail.com">mkhitrov@gmail.com</a>&gt; wrote:<br> &gt;&gt;<br>
&gt;&gt; On Tue, Jun 29, 2010 at 5:41 AM, John Ament &lt;<a \
href="mailto:my.reprive@gmail.com">my.reprive@gmail.com</a>&gt; wrote:<br> &gt;&gt; \
&gt; On Tue, Jun 29, 2010 at 12:15 AM, Matt Mackall &lt;<a \
href="mailto:mpm@selenic.com">mpm@selenic.com</a>&gt; wrote:<br> &gt;&gt; &gt;&gt; On \
Mon, 2010-06-28 at 21:05 -0400, John Ament wrote:<br> &gt;&gt; &gt;&gt; &gt; Hmmm.  I \
think it has to do with how the script is being called.  I<br> &gt;&gt; &gt;&gt; &gt; \
executed yours and it worked fine for me.<br> &gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; The script I&#39;m playing with is mozilla&#39;s pushlog hook. \
The call<br> &gt;&gt; &gt;&gt; &gt; looks<br>
&gt;&gt; &gt;&gt; &gt; like this:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; python:mozhghooks.pushlog.log<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; where the log function is defined like this:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; def log(ui, repo, node, **kwargs):<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; There are other calls to os, it just seems like the \
environment is<br> &gt;&gt; &gt;&gt; &gt; getting passed along.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; No, for hooks, the args get passed in via kwargs.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; To be honest with you, I&#39;m not sure which args you&#39;re referring \
to.  os<br> &gt;&gt; &gt; wouldn&#39;t be an arg in this case, right?<br>
&gt;&gt;<br>
&gt;&gt; Now I understand. Matt is referring to the fact that executing a<br>
&gt;&gt; python function is different from running an external program for a<br>
&gt;&gt; hook. In my example, even though it&#39;s python code, it was executed \
as<br> &gt;&gt; a separate process. With external programs, HG_URL is passed as \
an<br> &gt;&gt; environment variable. For python functions, you need to look at \
kwargs<br> &gt;&gt; dictionary. Here&#39;s a modified version of my previous test.py \
code:<br> &gt;&gt;<br>
&gt;&gt; def log(ui, repo, node, **kwargs):<br>
&gt;&gt;    print &#39;Username:&#39;, \
kwargs[&#39;url&#39;].split(&#39;:&#39;)[-1]<br> &gt;&gt;<br>
&gt;&gt; Instead of os.environ[&#39;HG_URL&#39;] you need to look at \
kwargs[&#39;url&#39;].<br> &gt;&gt; Everything else is identical. With this \
modification, I can set my<br> &gt;&gt; hook to the following and everything should \
work as before:<br> &gt;&gt;<br>
&gt;&gt; [hooks]<br>
&gt;&gt; changegroup = python:test.log<br>
&gt;&gt;<br>
&gt;&gt; Python has to be able to find the specified function, but it sounds<br>
&gt;&gt; like that&#39;s not a problem in your case.<br>
&gt;&gt;<br>
&gt;&gt; - Max<br>
&gt;<br>
&gt; Yep so that was it.  Great, thanks!<br>
&gt;<br>
&gt; Is there a list of everything available in kwargs somewhere?<br>
&gt;<br>
&gt; John<br>
<br>
</div></div>John, please don&#39;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>
&quot;Arguments listed as environment variables above are passed as keyword<br>
arguments, with no HG_ prefix, and names in lower case.&quot;<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