Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
#!/usr/local/bin/perl -w
2
 
3
use strict;
4
use Cwd;
5
use File::Basename;
6
use Getopt::Std;
7
use DeployUtils::Logger;
8
use Clearcase::Cmd;
9
use DeployUtils::RmPkgInfo;
10
use DeployUtils::BuildFile;
11
 
12
use vars qw ( $opt_h $opt_d $opt_c $opt_p $opt_v $opt_V );
13
 
14
#==============================================================================
15
#   Usage
16
#==============================================================================
17
sub Usage
18
{
19
    my $msg = shift;
20
 
21
    my $useStr = 
22
"Usage:
23
$0 [-h] [-d N] [-p] [-v ver | -V | -l rtagId | -c \"comment\" ] files...
24
where:
25
    -h    : This help page
26
    -d N  : Sets Debugging level to N
27
    -p    : Executes a Press Enter to Continue on termination of script
28
    The following are mutually exclusive and only one may be supplied
29
    -v    : Use ver as the version number, overrides version number from build.pl
30
    -V    : Prompts for version number to override from build.pl
31
    -l    : Find latest work in progress version in Release rtag.
32
    -c    : Checkout all files with the this comment.
33
          : If Supplied will not use Release Manager to get comment details
34
 
35
This script will checkout all files supplied on the command line.  If -c not supplied
36
it will find the build.pl file for this tree and use it to get package details and then
37
get the comment from Release Manager for this package.  If -c is supplied it will use it.
38
";
39
    print "$msg \n" if ( defined($msg) );
40
    print $useStr;
41
    exit 0;
42
}   # Usage
43
 
44
getopts ('hd:pc:v:V');
45
 
46
Usage() if ( defined($opt_h) );
47
 
48
# dont want to make debug less than 3
49
setLogLevel($opt_d) if ( defined($opt_d));
50
 
51
my $buildInfo;
52
my $rmInfo;
53
 
54
if ( ! defined($opt_c) )
55
{
56
    my $buildDir = cwd();
57
 
58
    while ( $buildDir ne "" )
59
    {
60
        last if ( -f "$buildDir/build.pl" );
61
        $buildDir = dirname($buildDir);
62
    }
63
 
64
    if ( $buildDir ne "" )
65
    {
66
        $buildInfo = DeployUtils::BuildFile->new("$buildDir/build.pl");
67
        if ( !defined($opt_v) && defined($opt_V) )
68
        {
69
            LogNorm("-n", "Enter Version number for [" . $buildInfo->getBuildName() . "], (default use RM)...");         
70
            $opt_v = <STDIN>;
71
            chomp $opt_v;
72
            $opt_v = $buildInfo->getBuildVersion() if ( $opt_v eq "" );
73
        }
74
        elsif ( ! defined($opt_v) )
75
        {
76
            $opt_v = $buildInfo->getBuildVersion();
77
        }
78
 
79
        LogNorm("Retrieving package info form RM for [" . $buildInfo->getBuildName() . "], [$opt_v]...");
80
        $rmInfo = DeployUtils::RmPkgInfo->new({ PKG_NAME => $buildInfo->getBuildName(), PKG_VERSION =>  $opt_v});
81
 
82
        if ( $rmInfo->foundDetails() )
83
        {
84
            LogError("Package [" . $rmInfo->pkg_name() . "] Version [" . $rmInfo->pkg_version() . "] is locked") if ( $rmInfo->pv_dlocked() eq "Y" );
85
            $opt_c = $rmInfo->pv_reason();
86
            $opt_c =~ s/\r\n/\n/g;
87
            chomp $opt_c;
88
            LogError("RM Comment found is empty, please fix") if ( $opt_c eq "" );
89
            LogNorm("Setting Checkout Comment from RM to [$opt_c]");
90
        }
91
        else
92
        {
93
            LogError("Unable to get RM comment");
94
        }
95
    }
96
    else
97
    {
98
        LogError("Unable to find build.pl in the current tree");
99
    }
100
}
101
 
102
map { $_ = "\"$_\"" } @ARGV;
103
 
104
my $coCmd = Clearcase::Cmd->new();
105
 
106
$coCmd->abortOnError(0);
107
$coCmd->processOutput(0);
108
$coCmd->CCcmd("checkout");
109
$coCmd->CCargs("-reserved");
110
$coCmd->CCaddArgs("-comment \"$opt_c\"");
111
$coCmd->CCaddArgs(@ARGV);
112
LogNorm("Checking out all Files");
113
$coCmd->CCexecute();
114
 
115
# regardless of how or where this program end this will run (unless user Ctrl-C etc)
116
# so if -p supplied we put a wait for enter
117
END
118
{
119
    if ( $opt_p )
120
    {
121
        LogNorm("Press Enter To Continue");
122
        getc();
123
    }
124
}
125
 
126
# -------------------------------------------------------------------------
127
sub GetYesNoQuit
128
#
129
# -------------------------------------------------------------------------
130
{
131
    LogNorm("-n", "$_[0] (default: y) [y,n,q=quit]: ");
132
 
133
    while ( <STDIN> )
134
    {
135
        chomp;
136
 
137
        tr /A-Z/a-z/;
138
 
139
        return "y"  if ( /^$/ );
140
        return "$1" if ( /^ *([yn]{1})$/ );
141
        exit 1      if ( /^ *(q{1})/ );
142
        LogNorm("-n", "Please re-enter response? (default: y) [y,n,q]: ");
143
    }
144
}
145