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

Robert Cowham robert at vizim.com
Tue Aug 24 03:22:45 PDT 2010


I personally always write my triggers to accept a %serverport% parameter to
avoid this type of issue. 

E.g. have a trigger framework with common parameter parsing that allows "-p
%serverport% " to be specified. I usually also supply "-u <username>" to
specify user the trigger will execute commands as.

As for passwords - if you require login, then I do a manual login on the
server machine for that user, with a group giving a very long timeout, and
detect errors such as "not logged in" or similar to allow user to report
them to their admins.

Other alternatives include P4CONFIG in env, but I find that can be annoying
if you are testing the triggers on one server and yet checking those
triggers in and out to another server (from the same location).

See
http://public.perforce.com/guest/robert_cowham/perforce/utils/triggers/index
.html

See also my conference presentation on automation/triggers:

http://www.perforce.com/perforce/conferences/eu/2006/index.html

Robert

> -----Original Message-----
> From: Christopher Evans [mailto:chris.evans at gmail.com] 
> Sent: 23 August 2010 22:41
> 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





More information about the perforce-user mailing list