Subversion Repositories DevTools

Rev

Rev 2439 | Rev 2764 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2438 dpurdie 1
########################################################################
2
# Copyright (C) 1998-2012 Vix Technology, All rights reserved
3
#
4
# Module name   : cc2svn_reposcan.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Process the Repo.dat file and generate lists of
10
#                 packages to be processed
2450 dpurdie 11
#
12
#                 Used to select packages that can be processed
2438 dpurdie 13
# Usage:
14
#
15
#......................................................................#
16
 
17
require 5.008_002;
18
use strict;
19
use warnings;
20
 
21
use Pod::Usage;
22
use Getopt::Long;
23
 
24
use JatsError;
2450 dpurdie 25
use FileUtils;
2438 dpurdie 26
 
27
#
28
#   Globals
29
#
30
my  $VERSION = "1.0.0";                      # Update this
31
our %ScmRepoMap;
32
 
33
#
34
#   Options
35
#
36
my $opt_verbose = 0;
37
my $opt_help = 0;
38
my $opt_repo;
2450 dpurdie 39
my $opt_repoExclude;
40
my $opt_age;
2438 dpurdie 41
my $opt_user;
42
my $opt_svn = 0;
43
my $opt_tail;
44
my $opt_ageorder;
45
my $opt_ageorderUser;
2450 dpurdie 46
my $opt_reposort;
2438 dpurdie 47
my $opt_onlyName;
2450 dpurdie 48
my $opt_touch;
49
my $opt_available;
50
my $opt_all;
2438 dpurdie 51
 
2450 dpurdie 52
my %excludeRepos;
53
 
2438 dpurdie 54
#-------------------------------------------------------------------------------
55
# Function        : Main Entry
56
#
57
# Description     :
58
#
59
# Inputs          :
60
#
61
# Returns         :
62
#
63
my $result = GetOptions (
64
                "help+"         => \$opt_help,          # flag, multiple use allowed
65
                "manual:3"      => \$opt_help,
66
                "verbose:+"     => \$opt_verbose,       # flag
67
                'repo:s'        => \$opt_repo,
2450 dpurdie 68
                'excluderepo:s' => \$opt_repoExclude,
69
                'age:i'         => \$opt_age,
2438 dpurdie 70
                'user:i'        => \$opt_user,
71
                'tail:i'        => \$opt_tail,
72
                'byage'         => \$opt_ageorder,
73
                'byuser'        => \$opt_ageorderUser,
2450 dpurdie 74
                'byrepo'        => \$opt_reposort,
2438 dpurdie 75
                'byname'        => \$opt_onlyName,
76
                'svn'           => \$opt_svn,            # Include SVNed packages
2450 dpurdie 77
                'touch:s'       => \$opt_touch,
78
                'available:s'   => \$opt_available,
79
                'all'           => \$opt_all,
2438 dpurdie 80
                );
81
 
82
#
83
#   Process help and manual options
84
#
85
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
86
pod2usage(-verbose => 1)  if ($opt_help == 2);
87
pod2usage(-verbose => 2)  if ($opt_help > 2);
88
 
89
ErrorConfig( 'name'    =>'CC2SVN_REPOSCAN',
90
             'verbose' => $opt_verbose,
91
              );
92
 
93
#
2450 dpurdie 94
#   Sanity test
95
#
96
Error ("Touch path is not a directory") if ( defined $opt_touch && ! -d $opt_touch );
97
Error ("Available selector is not a directory") if ( defined $opt_available && ! -d $opt_available );
98
 
99
if ($opt_repoExclude)
100
{
101
    foreach (split m/\s*,\s*/, $opt_repoExclude )
102
    {
103
        $excludeRepos{$_} = 1;
104
    }
105
}
106
 
107
#
2438 dpurdie 108
#   Read in the Mapping Data
109
#
110
Message ("Read in Vob Mapping");
111
 
112
my $fname = 'cc2svn.repo.dat';
113
my $rname;
114
foreach my $base ( '' , '../' , '-' )
115
{
116
    Error ("Connot find file: $fname") if ( $base eq '-' );
117
    $rname = $base . $fname;
118
    last if ( -f $rname );
119
}
120
require $rname;
121
 
122
Error("Data in $fname is not valid")
123
    unless ( keys(%ScmRepoMap) >= 0 );
124
 
125
#
126
#   Filter Repos
127
#
128
my $keep = 0;
129
foreach my $pkgname ( keys %ScmRepoMap )
130
{
131
    my $entry = $ScmRepoMap{$pkgname};
132
    $keep = 1;
133
 
2450 dpurdie 134
    unless ( $opt_all )
135
    {
136
        if ( $entry->{protected} )
137
        {
138
            $keep = 0;
139
            next;
140
        }
141
    }
142
 
143
    if ( $opt_repoExclude )
144
    {
145
        $entry->{repo} =~ m~^(.*?)(/|$)~;
146
        my $baseRepo = $1;
147
        if ( exists $excludeRepos{$baseRepo} || exists $excludeRepos{$entry->{repo}}  )
148
        {
149
            $keep = 0;
150
            next;
151
        }
152
    }
153
 
154
    if ( $opt_available )
155
    {
156
        unless ( -f $opt_available . '/' . $pkgname || -f $opt_available . '/' . $pkgname . '.svg' )
157
        {
158
            $keep = 0;
159
            next;
160
        }
161
    }
162
 
2438 dpurdie 163
    if ( $opt_repo )
164
    {
165
        unless ( $entry->{repo} =~ m~^$opt_repo($|/)~i )
166
        {
167
         $keep = 0;
2450 dpurdie 168
         next;
2438 dpurdie 169
        }
170
    }
171
 
2450 dpurdie 172
    if ( defined $opt_age )
2438 dpurdie 173
    {
2450 dpurdie 174
        if ( $opt_age > $entry->{youngest} )
2438 dpurdie 175
        {
176
            $keep = 0;
2450 dpurdie 177
            next;
2438 dpurdie 178
        }
179
    }
180
 
181
    if ( defined $opt_user )
182
    {
183
        if ( $opt_user > $entry->{ynr} )
184
        {
185
            $keep = 0;
2450 dpurdie 186
            next;
2438 dpurdie 187
        }
188
    }
189
 
190
    my $isSvn = exists ($entry->{SVN}) &&  $entry->{SVN};
191
    if (  !$opt_svn )
192
    {
193
        $keep = ! $isSvn;
194
    }
195
    next unless ( $keep );
196
}
197
continue
198
{
199
    delete $ScmRepoMap{$pkgname} unless ( $keep );
200
}
201
 
202
my $count = 0;
203
my $total = scalar keys %ScmRepoMap;
204
my @printOrder;
205
 
206
if ( $opt_ageorderUser ) {
207
    @printOrder = sort {$ScmRepoMap{$a}{ynr} <=> $ScmRepoMap{$b}{ynr}} keys %ScmRepoMap;
208
} elsif ( $opt_ageorder ) {
209
    @printOrder = sort {$ScmRepoMap{$a}{youngest} <=> $ScmRepoMap{$b}{youngest}} keys %ScmRepoMap;
2450 dpurdie 210
} elsif ( $opt_reposort ) {
211
    @printOrder = sort {lc $ScmRepoMap{$a}{repo} cmp lc $ScmRepoMap{$b}{repo}} keys %ScmRepoMap;
2438 dpurdie 212
} else {
213
    @printOrder =  sort {$a cmp $b} keys %ScmRepoMap ;
214
}
215
 
216
 
217
foreach my $pkgname ( @printOrder )
218
{
219
    $count++;
220
    if ( $opt_tail && ($count <= ($total - $opt_tail)) )
221
    {
222
        next;
223
    }
224
 
225
    if ( $opt_onlyName )
226
    {
227
        print "$pkgname\n";
228
    }
229
    else
230
    {
231
        my $entry = $ScmRepoMap{$pkgname};
232
 
233
        my $repo = $entry->{repo};
234
        my $svn = $entry->{SVN} ? 'SVN' : '---';
2450 dpurdie 235
        my $prot = $entry->{protected} ? $entry->{protected} :' ';
236
        $prot =~ m~(.)~;
237
        $prot = $1;
2438 dpurdie 238
 
239
        my $youngest            = $entry->{youngest};
240
        my $youngestNonRipple   = $entry->{ynr};
241
        my $youngestNonBuildadm = $entry->{ynb};
242
 
243
 
2450 dpurdie 244
        my $txt = sprintf ("Last:%5d, User:%5d, NonR:%5d, $svn $prot", $youngest, $youngestNonBuildadm, $youngestNonRipple);
2438 dpurdie 245
        $txt .= sprintf (" %45s %s", $pkgname, $repo );
246
        print "$txt\n";
247
    }
2450 dpurdie 248
 
249
    if ( $opt_touch )
250
    {
251
        TouchFile( $opt_touch .'/'.$pkgname);
252
        unlink ($opt_available . '/' . $pkgname) if ( $opt_available );
253
        unlink ($opt_available . '/' . $pkgname . '.svg') if ( $opt_available );
254
    }
2438 dpurdie 255
}
256
print "Maching entires: $total\n";
257
 
258
#-------------------------------------------------------------------------------
259
#   Documentation
260
#
261
 
262
=pod
263
 
264
=for htmltoc    SYSUTIL::cc2svn::
265
 
266
=head1 NAME
267
 
268
cc2svn_reposcan - Scan Repo.dat file
269
 
270
=head1 SYNOPSIS
271
 
272
  jats cc2svn_reposcan
273
 
274
 Options:
275
    -help              - brief help message
276
    -help -help        - Detailed help message
277
    -man               - Full documentation
278
    -verbose           - Enable verbosity
2450 dpurdie 279
   Package Selection
280
    -svn               - Include packages in SVN too
2438 dpurdie 281
    -repo=name         - Select named repos (default all)
2450 dpurdie 282
    -excludeRepo=name  - Exclude repos
2438 dpurdie 283
    -last=nn           - Select last build > nn
284
    -user=nn           - Select last user > nn
2450 dpurdie 285
    -available=path    - Select if in named directory
286
    -all               - Include Protected and Broken packages
287
   Output Sorting
2438 dpurdie 288
    -byage             - Sort by last build age
289
    -byuser            - Sort by last User Mode age
2450 dpurdie 290
    -byprepo           - Sort by repository name
291
   Display control
292
    -tail=nn           - Display last nn items
2438 dpurdie 293
    -byname            - Only display package names
2450 dpurdie 294
   Process control
295
    -touch=path        - Create a file named after the package
296
                         Delete 'available' marker file
2438 dpurdie 297
 
298
=head1 OPTIONS
299
 
300
=over 8
301
 
302
=item B<-help>
303
 
304
Print a brief help message and exits.
305
 
306
=item B<-help -help>
307
 
308
Print a detailed help message with an explanation for each option.
309
 
310
=item B<-man>
311
 
312
Prints the manual page and exits.
313
 
2450 dpurdie 314
=item B<-available=path>
315
 
316
This option will limit the selection to packages that have a marker file in
317
the named directory. The marker file will be file with the same name
318
as the package or with a '.svg' extension.
319
 
320
When used in conjunction with the '-touch' option the marker file will be
321
deleted after the target marker file has been 'touched'.
322
 
323
=item B<-touch=path>
324
 
325
This option will populate a 'new' or test directory with packages. When used,
326
an empty file named after the package, will be created in the target path.
327
 
2438 dpurdie 328
=back
329
 
330
=head1 DESCRIPTION
331
 
332
This program is a tool used in the conversion of ClearCase VOBS to subversion.
333
 
2450 dpurdie 334
=head2 Examples
335
 
336
The follwoing command will:
337
 
338
 jats cc2svn_reposcan -repo=MASS_Dev_Infra -user=30 -byuser -available=. -touch=../new
339
 
340
Process packages in the MASS_Dev_Infra repository, selecting that that have
341
not been modified by a user for 30 days and that have a marker file in the
342
current directory. It will display the results sorted by the time since last
343
modified by a user. It will also create a marker file in the directory '../new'.
344
 
2438 dpurdie 345
=cut
346