#!/usr/bin/perl
#
# prettyClientView.pl - a trigger to create a user appropriate client view
# for new clients, but only for people in group 'registered'
#
# Usage: prettyClientView.pl %formname% %formfile% %user%
#
use strict;
my $p4user = "user";
my $p4passwd = "password";
my $p4port = "perforce:1666";
my $p4exec = "/usr/local/bin/p4";
my $p4 = "$p4exec -p $p4port -u $p4user -P $p4passwd ";
my $clientname = shift;
my $clientspec = shift;
my $user = shift;
# check to see if user is in 'registered' group
my $result = `$p4 groups -u $user`;
if( $result !~ /registered/ )
{
exit 0;
}
# bail if the client already exists
my @results = `$p4 clients`;
my $clientFound = 0;
foreach( @results )
{
if( /^Client\s$clientname\s/ )
{
$clientFound = 1;
}
}
if( $clientFound )
{
exit 0;
}
open CLIENT, "<$clientspec" or die "couldn't find file: $clientspec";
my $newspec;
my $viewSeen = 0;
while( <CLIENT> )
{
if( /^View:/ )
{
$viewSeen = 1;
$newspec .= $_;
$newspec .= "\t//guest/$user/... //$clientname/...\n";
next;
}
elsif( !$viewSeen && /^\s/ )
{
$newspec .= $_;
}
elsif( /^\w*:/ )
{
$viewSeen = 0;
$newspec .= $_;
}
}
close CLIENT;
open CLIENT, ">", $clientspec or die $!;
print CLIENT $newspec;
close CLIENT;