#!/usr/bin/perl ################################################################################ # # File: $RCSfile: rmnusers,v $ # Revision: $Revision: 1.3 $ # Description: This script will remove a user to the nusers list for a lock # Author: Andrew@DeFaria.com # Created: Mon Feb 13 10:35:34 PST 2006 # Modified: $Date: 2011/08/31 21:57:06 $ # Language: Perl # # (c) Copyright 2006, Andrew@DeFaria.com, all rights reserved. # ################################################################################ use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; use Getopt::Long; use OSDep; use Display; use Utils; my $me = $FindBin::Script; # Pick up from the environment if the user specifies pvob my $pvob = $ENV{pvob}; my @pvob_related_objects = ( "activity", "stream", ); sub Usage { my $msg = shift; display "Usage: $me: []"; if (defined $msg) { error "$msg", 1; } # if exit 0; } # Usage sub RemoveNuser { my $object = shift; my $username = shift; my @users = @_; my $cmd = "cleartool lock "; $cmd .= "-replace "; if (scalar @users gt 1) { $cmd .= "-nusers "; my $first = $true; foreach (@users) { next if $_ eq $username; if ($first) { $first = $false; $cmd .= $_; } else { $cmd .= ",$_"; } # if } # foreach } # if $cmd .= " $object"; my @output = `$cmd`; return $?; } # RemoveNuser my $object = shift; my @users = @ARGV; Usage "Must specify an object selector" if !defined $object; Usage "Must specify an username" if scalar @users eq 0; my $object_type = $object; my $full_object; $object_type =~ s/:.*//; if ($object =~ m/(.*)\@(.*)/) { $object = $1; $pvob = $2; } # if Usage "Must specify pvob or set pvob in your environment" if !$pvob; if (InArray $object_type, @pvob_related_objects) { # Need to add additional "\\" because Windows will eat them up when executing a ``; if ($arch eq "windows" or $arch eq "cygwin") { $full_object = "$object\@\\$pvob"; } else { $full_object = "$object\@$pvob"; } # if } else { $full_object = $object; # Handle oddity with windows using \ for vob tags if ($full_object =~ /vob:\\(.*)/) { $full_object = "vob:\\\\" . $1; } # if } # if foreach (@users) { my $cmd = "cleartool lslock $full_object 2>&1"; my @output = `$cmd`; my $status = $?; if ($status eq 0) { if (scalar @output eq 0) { display "$object is not locked"; exit 0; } # if } else { display "$object does not exist"; exit 1; } # if my @current_users; foreach (@output) { if (/\"Locked except for users: (.*)\"/) { @current_users = split " ", $1; last; } # if } # foreach if (InArray $_, @current_users) { if (RemoveNuser $full_object, $_, @current_users) { error "Unable to remove $_ from nusers for $object"; } else { display "User $_ removed from the list of nusers for $object"; } # if } else { error "User $_ is not on the nusers list for $object"; } # if } # foreach