| 227 |
dpurdie |
1 |
#!/usr/local/bin/perl -w
|
|
|
2 |
|
|
|
3 |
use strict;
|
|
|
4 |
use Getopt::Std;
|
|
|
5 |
use DeployUtils::Logger;
|
|
|
6 |
use Clearcase::LsCmd;
|
|
|
7 |
use Clearcase::Cmd;
|
|
|
8 |
|
|
|
9 |
use vars qw ( $opt_h $opt_d $opt_c $opt_p );
|
|
|
10 |
|
|
|
11 |
#==============================================================================
|
|
|
12 |
# Usage
|
|
|
13 |
#==============================================================================
|
|
|
14 |
sub Usage
|
|
|
15 |
{
|
|
|
16 |
my $msg = shift;
|
|
|
17 |
|
|
|
18 |
my $useStr =
|
|
|
19 |
"Usage:
|
|
|
20 |
$0 [-h] [-d N] [-p] [-c \"comment\"] dir
|
|
|
21 |
where:
|
|
|
22 |
-h : This help page
|
|
|
23 |
-d N : Sets Debugging level to N
|
|
|
24 |
-p : Executes a Press Enter to Continue on termination of script
|
|
|
25 |
-c : Checkout all files with the this comment.
|
|
|
26 |
|
|
|
27 |
This script runs an the Clearcase LsCmd to get a list of all Checked In File.
|
|
|
28 |
It then does a checkout of those files with the the comment if one is supplied
|
|
|
29 |
";
|
|
|
30 |
print "$msg \n" if ( defined($msg) );
|
|
|
31 |
print $useStr;
|
|
|
32 |
exit 0;
|
|
|
33 |
} # Usage
|
|
|
34 |
|
|
|
35 |
getopts ('hd:pc:');
|
|
|
36 |
|
|
|
37 |
Usage() if ( defined($opt_h) );
|
|
|
38 |
|
|
|
39 |
# dont want to make debug less than 3
|
|
|
40 |
setLogLevel($opt_d) if ( defined($opt_d));
|
|
|
41 |
|
|
|
42 |
my $dir = (defined($ARGV[0])) ? $ARGV[0] : ".";
|
|
|
43 |
|
|
|
44 |
my $CClist = Clearcase::LsCmd->new($dir);
|
|
|
45 |
LogNorm("Getting a list of Checked In Files in " . $CClist->CCcwd());
|
|
|
46 |
|
|
|
47 |
if ( $CClist->CCexecute() == 0 )
|
|
|
48 |
{
|
|
|
49 |
if ( $CClist->getNumByState($Clearcase::LsCmd::StateCheckedIn) > 0 )
|
|
|
50 |
{
|
|
|
51 |
# get list of checked in files
|
|
|
52 |
my $CiFiles = $CClist->getListByState($Clearcase::LsCmd::StateCheckedIn);
|
|
|
53 |
map { $_ = "\"$_\"" } @$CiFiles;
|
|
|
54 |
|
|
|
55 |
my $coCmd = Clearcase::Cmd->new();
|
|
|
56 |
|
|
|
57 |
$coCmd->abortOnError(0);
|
|
|
58 |
$coCmd->processOutput(0);
|
|
|
59 |
$coCmd->CCcmd("checkout");
|
|
|
60 |
$coCmd->CCargs("-reserved");
|
|
|
61 |
if ( defined($opt_c))
|
|
|
62 |
{
|
|
|
63 |
$coCmd->CCaddArgs("-comment \"$opt_c\"");
|
|
|
64 |
}
|
|
|
65 |
else
|
|
|
66 |
{
|
|
|
67 |
$coCmd->CCaddArgs("-ncomment");
|
|
|
68 |
}
|
|
|
69 |
$coCmd->CCaddArgs(@$CiFiles);
|
|
|
70 |
LogNorm("Checking out all Files");
|
|
|
71 |
$coCmd->CCexecute();
|
|
|
72 |
}
|
|
|
73 |
else
|
|
|
74 |
{
|
|
|
75 |
LogNorm("No Checked In Files Found");
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
else
|
|
|
79 |
{
|
|
|
80 |
LogError("Failed to execute Ls Command");
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
# regardless of how or where this program end this will run (unless user Ctrl-C etc)
|
|
|
84 |
# so if -p supplied we put a wait for enter
|
|
|
85 |
END
|
|
|
86 |
{
|
|
|
87 |
if ( $opt_p )
|
|
|
88 |
{
|
|
|
89 |
LogNorm("Press Enter To Continue");
|
|
|
90 |
getc();
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
# -------------------------------------------------------------------------
|
|
|
95 |
sub GetYesNoQuit
|
|
|
96 |
#
|
|
|
97 |
# -------------------------------------------------------------------------
|
|
|
98 |
{
|
|
|
99 |
LogNorm("-n", "$_[0] (default: y) [y,n,q=quit]: ");
|
|
|
100 |
|
|
|
101 |
while ( <STDIN> )
|
|
|
102 |
{
|
|
|
103 |
chomp;
|
|
|
104 |
|
|
|
105 |
tr /A-Z/a-z/;
|
|
|
106 |
|
|
|
107 |
return "y" if ( /^$/ );
|
|
|
108 |
return "$1" if ( /^ *([yn]{1})$/ );
|
|
|
109 |
exit 1 if ( /^ *(q{1})/ );
|
|
|
110 |
LogNorm("-n", "Please re-enter response? (default: y) [y,n,q]: ");
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
|