Subversion Repositories DevTools

Rev

Rev 227 | Details | Compare with Previous | 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 Getopt::Std;
5
use DeployUtils::Logger;
6
use Clearcase::LsCheckoutCmd;
7
use Clearcase::CheckinCmd;
8
 
9
use vars qw ( $opt_h $opt_d $opt_p $opt_i $opt_n $opt_c );
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
    -i    : Force Checkin of identical files, otherwise error is produced on file
25
    -n    : Force checkin of files with no checkout comments, comment will be empty
26
    -c    : Set comment of files without checkout comments to comment.
27
    -p    : Executes a Press Enter to Continue on termination of script
28
 
29
This script does a recursive checkin on all checked out files find below pwd.
30
 
31
It will run a lscheckout command to get a list of files that are checked out.
32
It then runs the checkin command on these files to checkin the files.
33
 
34
By default files with checkout comments will be automatically checked in with those comments.
35
Files without comments will be manually prompted during checkin unless -n or -c is used.
36
";
37
    print "$msg \n" if ( defined($msg) );
38
    print $useStr;
39
    exit 0;
40
}   # Usage
41
 
42
getopts ('hd:pinc:');
43
 
44
Usage() if ( defined($opt_h) );
45
 
46
Usage("Must only use one of -n or -c") if ( defined($opt_n) && defined($opt_c) );
47
 
48
# dont want to make debug less than 3
49
setLogLevel($opt_d) if ( defined($opt_d) && $opt_d > 3);
50
 
51
my $coFiles = Clearcase::LsCheckoutCmd->new();
52
 
53
LogNorm("Checking for Checked out Files in " . $coFiles->CCcwd());
54
 
55
if ( $coFiles->CCexecute() == 0 )
56
{
57
    my ( $autoCi, $manCi );
58
    my ( $numCom, $numNoCom ) = $coFiles->countFiles();
59
 
60
    $coFiles->printResult();
61
    LogNorm("");
62
 
63
    if ( $numCom + $numNoCom > 0 )
64
    {
65
        # autoCi is run with -nc that will use the checkout comment if any or 
66
        # if -n is used it will also ci files with no comment if they have no co comment
67
        $autoCi = Clearcase::CheckinCmd->new("-nc");
68
        $autoCi->CCaddArgs("-identical") if ( defined($opt_i) );
69
        # create manCi without args it will be set below
70
        $manCi = Clearcase::CheckinCmd->new();
71
        $manCi->CCaddArgs("-identical") if ( defined($opt_i) );
72
 
73
        if ( defined($opt_n) )
74
        {
75
            $autoCi->addFiles(@{$coFiles->getFileList()});
76
            LogNorm("All Files listed above will be checked in with or without comments as listed above");
77
        }
78
        # if -c is specified then the maniCi will checkin all files without comments with the comment specified by -c
79
        elsif ( defined($opt_c) )
80
        {
81
            if ( $numCom > 0 )
82
            {
83
                $autoCi->addFiles(@{$coFiles->getFileList("COMMENT")});
84
                LogNorm("All files listed above with comments will be checked in with those comments");
85
            }
86
            $manCi->CCaddArgs("-comment", "\"$opt_c\"");
87
            # get files from ls checkout that have no comments
88
            if ( $numNoCom > 0 )
89
            {
90
                $manCi->addFiles(@{$coFiles->getFileList("NOCOMMENT")});
91
                LogNorm("All files listed above with out comments will be checked in with supplied comment");
92
            }
93
        }
94
        # else normal processing of autoCi of files with comments and manCi of files without with comment prompt
95
        else
96
        {
97
            if ( $numCom > 0 )
98
            {
99
                $autoCi->addFiles(@{$coFiles->getFileList("COMMENT")});
100
                LogNorm("All files listed above with comments will be checked in with those comments");
101
            }
102
            $manCi->CCaddArgs("-cqe");
103
            # set man ci to run individually for each file and print message
104
            $manCi->executeIndividually(1);
105
            $manCi->execMsg("Enter Check in Comment");
106
            # get files from ls checkout that have comments
107
            if ( $numNoCom > 0 )
108
            {
109
                $manCi->addFiles(@{$coFiles->getFileList("NOCOMMENT")});
110
                LogNorm("All files listed above with out comments will be checked in after prompting for comment");
111
                LogNorm("If prompted on the console terminate comment with a period on a new line");
112
            }
113
        }
114
 
115
        my $answer = GetYesNoQuit("Do you want to check in the files above");
116
        if ( $answer eq "y" )
117
        {
118
            $autoCi->CCexecute();
119
            $manCi->CCexecute();
120
        }
121
 
122
    }
123
}
124
else
125
{
126
    LogError("Failed to execute LsCheckout Command");
127
}
128
 
129
# regardless of how or where this program end this will run (unless user Ctrl-C etc)
130
# so if -p supplied we put a wait for enter
131
END
132
{
133
    if ( $opt_p )
134
    {
135
        LogNorm("Press Enter To Continue");
136
        getc();
137
    }
138
}
139
 
140
# -------------------------------------------------------------------------
141
sub GetYesNoQuit
142
#
143
# -------------------------------------------------------------------------
144
{
145
    LogNorm("-n", "$_[0] (default: y) [y,n,q=quit]: ");
146
 
147
    while ( <STDIN> )
148
    {
149
        chomp;
150
 
151
        tr /A-Z/a-z/;
152
 
153
        return "y"  if ( /^$/ );
154
        return "$1" if ( /^ *([yn]{1})$/ );
155
        exit 1      if ( /^ *(q{1})/ );
156
        LogNorm("-n", "Please re-enter response? (default: y) [y,n,q]: ");
157
    }
158
}
159