[p4] Triggers: Log into p4 from inside a python trigger

Gabor Maghera gmaghera at gmail.com
Mon Aug 23 15:50:53 PDT 2010


For triggers which require access to administrative commands (such a p4
monitor), I prefer to use tickets over having a password embedded in the
script.  I always specify the %serverport% parameter in the trigger
definition line, to make sure that I am using the ticket for the correct
server.  I have multiple servers running on the same machine, one for
production, and some other experimental ones.  Rather than trying to log in
through the trigger script, I check for a valid ticket via p4 login -s (for
the server the trigger is supposed to work on).

As an alternate, you could place the encrypted password p4 login -p gives
you inside the script.  To me that feels like unnecessary replication of the
functionality tickets offer.

My $ .02.

--
Gabor

On Mon, Aug 23, 2010 at 2:49 PM, Ivey, William <william_ivey at bmc.com> wrote:

> They inherit the environment of the server. But, unless you control that,
> you're right, you can't assume.
>
> -Wm
>
> -----Original Message-----
> From: perforce-user-bounces at perforce.com [mailto:
> perforce-user-bounces at perforce.com] On Behalf Of Christopher Evans
> Sent: Monday, August 23, 2010 4:41 PM
> To: Robert Cowham
> Cc: perforce-user at perforce.com
> Subject: Re: [p4] Triggers: Log into p4 from inside a python trigger
>
> You were right!
>
> I guess you should never make assumptions about the environment your
> trigger will be run in.
>
> Thanks a bunch!
>
> CE
>
> On Mon, Aug 23, 2010 at 11:22 AM, Robert Cowham <robert at vizim.com> wrote:
> > I would also set p4.port to correct value - the triggers are spawned by
> the
> > p4d server, so with very likely a different environment to your
> interactive
> > command line.
> >
> >> -----Original Message-----
> >> From: perforce-user-bounces at perforce.com
> >> [mailto:perforce-user-bounces at perforce.com] On Behalf Of
> >> Christopher Evans
> >> Sent: 22 August 2010 08:45
> >> To: perforce-user at perforce.com
> >> Subject: [p4] Triggers: Log into p4 from inside a python trigger
> >>
> >> So, I am kind of a newb (first post!), but, I have written
> >> quite a bit with p4python, so now I see weird errors inside a
> >> trigger that I don't get in p4python. This is my first
> >> trigger that does anything other than return 'hello world'.
> >>
> >> This errors out in the try, however, the 'errors' returned
> >> are just spaces or null chars it seems.
> >>
> >> Question: If a submit trigger can only give you the change as
> >> an argument, is this how you log in and get information about
> >> the file being submitted? (describe)
> >>
> >> Disclaimer: Because we don't have a test environ at work, I
> >> am using the free 2 user p4 running on my local machine
> >>
> >> Here's my trigger:
> >>
> >> --------------------------------------------------------------
> >>
> >> import sys
> >> from P4 import P4, P4Exception
> >>
> >> p4 = P4()
> >> describe = []
> >>
> >> try:
> >>       p4.user = "admin"
> >>       p4.password = "admin"
> >>       p4.connect()
> >>       print '1'
> >>       info = p4.run("info")
> >>       print info
> >>
> >> except P4Exception:
> >>       error = ''
> >>       for e in p4.errors: error += (e+'\n')
> >>       print error
> >>       sys.exit(1)
> >>
> >> print 'hello world'
> >> print str(sys.argv)
> >> describe = p4.run('describe',sys.argv[2]) print str(describe)
> >>
> >> p4.disconnect()
> >> sys.exit(1)
> >>
> >> --------------------------------------------------------------
> >>
> >> Thanks,
> >>
> >> --
> >> CE
> >> _______________________________________________
> >> perforce-user mailing list  -  perforce-user at perforce.com
> >> http://maillist.perforce.com/mailman/listinfo/perforce-user
> >
> >
>
>
>
> --
> CE
>
> _______________________________________________
> perforce-user mailing list  -  perforce-user at perforce.com
> http://maillist.perforce.com/mailman/listinfo/perforce-user
>
>
> _______________________________________________
> perforce-user mailing list  -  perforce-user at perforce.com
> http://maillist.perforce.com/mailman/listinfo/perforce-user
>



More information about the perforce-user mailing list