Jump to content


P4V- Action on Map to Workspace view

P4V Triggers customization

  • Please log in to reply
4 replies to this topic

#1 adichamoli

adichamoli

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 12 January 2016 - 05:33 AM

I want to call the trigger/script at the action of “Map to workspace view” which will take 3 arguments.

1.    User
2.    Client(workspace)
3.    Path of the Local workspace

Can Somebody please suggest whether it is possible to do such type of thing.
If yes, can somebody please share the steps how to achieve it.

#2 Mailman Sync

Mailman Sync

    Advanced Member

  • Maillist Aggregator
  • 2495 posts

Posted 12 January 2016 - 11:30 AM

Originally posted to the perforce-user mailing list by: Michael Mirman


The simple answer is "sort of".
The trigger line takes only a depot path - that's what needs to match in order to fire a trigger.
The problem you have to work around is that a client spec can map anything to anything.
So, it is only "p4 where" in the right client context, which would answer the question "is this file mapped or not" in the given client.

However, technically, you can write something like

  mytrigger  change-submit //... /local/user/bin/some/script -changelist %changelist% -match client.name.here

The script would look at the submitted changelist and see if any of the depot paths of that change are mapped by the specified client (by using "p4 where" in that client context).

Not too efficient IMHO, but possible.

--
Michael Mirman
MathWorks, Inc.
508-647-7555


-----Original Message-----
From: perforce-user [mailto:perforce-user-bounces@perforce.com] On Behalf Of adichamoli
Sent: Tuesday, January 12, 2016 12:35 AM
To: perforce-user@perforce.com
Subject: [p4] P4V- Action on Map to Workspace view

Posted on behalf of forum user 'adichamoli'.

I want to call the trigger/script at the action of “ Map to workspace view ”
which will take 3 arguments.

1. �� User
2. �� Client(workspace)
3. �� Path of the Local workspace

Can Somebody please suggest whether it is possible to do such type of thing.
If yes, can somebody please share the steps how to achieve it.



--
Please click here to see the post in its original format:
  http://forums.perfor...-workspace-view
_______________________________________________
perforce-user mailing list  -  perforce-user@perforce.com
http://maillist.perf...o/perforce-user


#3 P4Shimada

P4Shimada

    Advanced Member

  • Members
  • PipPipPip
  • 831 posts

Posted 13 January 2016 - 01:19 AM

View Postadichamoli, on 12 January 2016 - 05:33 AM, said:

I want to call the trigger/script at the action of “Map to workspace view” which will take 3 arguments.

1.    User
2.    Client(workspace)
3.    Path of the Local workspace

Can Somebody please suggest whether it is possible to do such type of thing.
If yes, can somebody please share the steps how to achieve it.

Hi,

In terms of getting the path of the local workspace when selecting 'Map to Workspace View', I need to double-check on that. You can definitely pass in the user and workspace using the %user% and %client% trigger variables. You may want to try %args% to see if it passes in the selected path for the 'Map to Workspace View' option.  That option opens the client workspace form and you can use a form trigger to perform an action when the form opens.

For example, if you wanted something to be added to the description of the Workspace after the client form opens here is an example below that adds several lines of text to the beginning of the client 'Description' field.

EXAMPLE  CLIENT OUTPUT

Owner: admin

Host: rhw-user1

Description:

TESTING client form trigger
User is: admin
Client is: admin2014.1
Arguments are:

Created by admin.

Root: /home/user1/admin2014.1

EXAMPLE TRIGGER ENTRY

Triggers:
client_desc1 form-out client "/home/user1/scripts/client_desc1.pl %formtype% %formfile% %user% %client% %args%"

EXAMPLE SCRIPT

#!/usr/bin/perl
#
# Triggers:
# client_desc1 form-out client "/home/user1/scripts/client_desc1.pl %formtype% %formfile% %user% %client% %args%"
#

my $formtype = $ARGV[0]; # from %formtype% in trigger table
my $formfile = $ARGV[1]; # from %formfile% in trigger table
my $myuser = $ARGV[2]; # from %user% in trigger table
my $myclt = $ARGV[3]; # from %client% in trigger table
my @myargs = $ARGV[4]; # from %args% in trigger table

$defaultin = "Description:";
$addflds = "\n\tTESTING client form trigger\n\tUser is: $myuser\n\tClient is: $myclt\n\tArguments are: $myargs\n\n";

open (LOGFILE, ">/tmp/triggeroutput");
my $modifiedform = "";
open (FORM, "$formfile") || print LOGFILE "Trigger couldn't read form tempfile\n";
while ( <FORM> )
{	 ## Do the substitution as appropriate.
	 if ( m:$defaultin: ) { $_ .= $addflds; }
	 $modifiedform .= $_;
}
print LOGFILE $modifiedform;

open (MODFORM, ">$formfile") || die "Couldn't write form tempfile";
print MODFORM $modifiedform;
close LO
GFILE;
exit 0;

REFERENCES

- Triggering on forms
http://www.perforce.....triggers.forms

- Trigger script variables
http://www.perforce....ggers.variables

#4 adichamoli

adichamoli

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 24 January 2016 - 01:49 PM

Hi,

Thanks all for the valuable suggestions, we tried several possible options and we made a form-commit which solves our purpose.
We are fetching information in the below manner which we applied on "Map to Workspace View" event. There could be more event on which the query can work.

USER=$1
CLNT=$2
WSROOT=`p4 client -o $CLNT |grep "Root" |grep -v "#" |awk -F" " '{print $2}'`

But is it possible to have the same on "Get Latest Revision" or "Get Revision" event.
Any suggestions will be helpful.

#5 P4Shimada

P4Shimada

    Advanced Member

  • Members
  • PipPipPip
  • 831 posts

Posted 27 January 2016 - 07:20 PM

View Postadichamoli, on 24 January 2016 - 01:49 PM, said:

Thanks all for the valuable suggestions, we tried several possible options and we made a form-commit which solves our purpose.

But is it possible to have the same on "Get Latest Revision" or "Get Revision" event.
Any suggestions will be helpful.

Hello,

You're welcome! Glad you now have a solution to solve your purpose.

If you want to execute a script for 'Get Latest Revision' or 'Get Revision' then you can use a command type trigger:

(pre|post)-user-sync \\ before or after the sync command

See the Admin Guide under 'Triggering before or after commands':

  http://www.perforce.....triggers.order

Basically the 'Get Latest Revision' command in P4V will be 'p4 sync //<selected-file/folder>/...#head':

EXAMPLES

p4 sync //gwt/branches/...#head

p4 sync //depot/foo1#head

And the 'Get Revision' option is 'p4 sync' with whatever flags and file arguments are chosen based on the dialog box.





Also tagged with one or more of these keywords: P4V, Triggers, customization

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users