| 227 |
dpurdie |
1 |
#!/usr/local/bin/perl -w
|
|
|
2 |
|
|
|
3 |
use strict;
|
|
|
4 |
use Getopt::Std;
|
|
|
5 |
use DeployUtils::Logger;
|
|
|
6 |
use Clearcase::LsCheckoutCmd;
|
|
|
7 |
use Clearcase::undoCheckoutCmd;
|
|
|
8 |
|
|
|
9 |
use vars qw ( $opt_h $opt_d $opt_p $opt_k $opt_r );
|
|
|
10 |
|
|
|
11 |
#==============================================================================
|
|
|
12 |
# Usage
|
|
|
13 |
#==============================================================================
|
|
|
14 |
sub Usage
|
|
|
15 |
{
|
|
|
16 |
my $msg = shift;
|
|
|
17 |
|
|
|
18 |
my $useStr =
|
|
|
19 |
"Usage:
|
|
|
20 |
$0 [-h] [-d N] [-i] [-n|-c \"comment\"] [-p]
|
|
|
21 |
where:
|
|
|
22 |
-h : This help page
|
|
|
23 |
-d N : Sets Debugging level to N
|
|
|
24 |
-r : Remove current file after undo checkout (default)
|
|
|
25 |
-k : Keep current file as file.keep
|
|
|
26 |
-p : Executes a Press Enter to Continue on termination of script
|
|
|
27 |
|
|
|
28 |
This script does a recursive undo checkout on all checked out files find below pwd.
|
|
|
29 |
|
|
|
30 |
It will run a lscheckout command to get a list of files that are checked out.
|
|
|
31 |
It then runs the uncheckout command on these files to checkout the files.
|
|
|
32 |
";
|
|
|
33 |
print "$msg \n" if ( defined($msg) );
|
|
|
34 |
print $useStr;
|
|
|
35 |
exit 0;
|
|
|
36 |
} # Usage
|
|
|
37 |
|
|
|
38 |
getopts ('hd:pkr');
|
|
|
39 |
|
|
|
40 |
Usage() if ( defined($opt_h) );
|
|
|
41 |
|
|
|
42 |
Usage("Must only use one of -k or -r") if ( defined($opt_k) && defined($opt_r) );
|
|
|
43 |
|
|
|
44 |
# default to r if none provided
|
|
|
45 |
$opt_r = 1 if ( !defined($opt_k) && ! defined($opt_r) );
|
|
|
46 |
|
|
|
47 |
# dont want to make debug less than 3
|
|
|
48 |
setLogLevel($opt_d) if ( defined($opt_d) && $opt_d > 3);
|
|
|
49 |
|
|
|
50 |
my $coFiles = Clearcase::LsCheckoutCmd->new();
|
|
|
51 |
|
|
|
52 |
LogNorm("Checking for Checked out Files in " . $coFiles->CCcwd());
|
|
|
53 |
|
|
|
54 |
if ( $coFiles->CCexecute() == 0 )
|
|
|
55 |
{
|
|
|
56 |
my ( $undoCo );
|
|
|
57 |
my ( $numCom, $numNoCom ) = $coFiles->countFiles();
|
|
|
58 |
|
|
|
59 |
$coFiles->printResult();
|
|
|
60 |
LogNorm("");
|
|
|
61 |
|
|
|
62 |
if ( $numCom + $numNoCom > 0 )
|
|
|
63 |
{
|
|
|
64 |
$undoCo = Clearcase::UndoCheckoutCmd->new();
|
|
|
65 |
$undoCo->CCaddArgs("-rm") if ( defined($opt_r) );
|
|
|
66 |
$undoCo->CCaddArgs("-keep") if ( defined($opt_k) );
|
|
|
67 |
|
|
|
68 |
$undoCo->addFiles(@{$coFiles->getFileList()});
|
|
|
69 |
|
|
|
70 |
my $answer = GetYesNoQuit("Do you want to undo check outs the files above");
|
|
|
71 |
if ( $answer eq "y" )
|
|
|
72 |
{
|
|
|
73 |
$undoCo->CCexecute();
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
else
|
|
|
78 |
{
|
|
|
79 |
LogError("Failed to execute LsCheckout Command");
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
# regardless of how or where this program end this will run (unless user Ctrl-C etc)
|
|
|
83 |
# so if -p supplied we put a wait for enter
|
|
|
84 |
END
|
|
|
85 |
{
|
|
|
86 |
if ( $opt_p )
|
|
|
87 |
{
|
|
|
88 |
LogNorm("Press Enter To Continue");
|
|
|
89 |
getc();
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
# -------------------------------------------------------------------------
|
|
|
94 |
sub GetYesNoQuit
|
|
|
95 |
#
|
|
|
96 |
# -------------------------------------------------------------------------
|
|
|
97 |
{
|
|
|
98 |
LogNorm("-n", "$_[0] (default: y) [y,n,q=quit]: ");
|
|
|
99 |
|
|
|
100 |
while ( <STDIN> )
|
|
|
101 |
{
|
|
|
102 |
chomp;
|
|
|
103 |
|
|
|
104 |
tr /A-Z/a-z/;
|
|
|
105 |
|
|
|
106 |
return "y" if ( /^$/ );
|
|
|
107 |
return "$1" if ( /^ *([yn]{1})$/ );
|
|
|
108 |
exit 1 if ( /^ *(q{1})/ );
|
|
|
109 |
LogNorm("-n", "Please re-enter response? (default: y) [y,n,q]: ");
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|