Subversion Repositories DevTools

Rev

Rev 3832 | Rev 5709 | 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;
3347 dpurdie 48
my $opt_onlyFullName;
2450 dpurdie 49
my $opt_touch;
3859 dpurdie 50
my @opt_available;
51
my @opt_exclude;
2450 dpurdie 52
my $opt_all;
3832 dpurdie 53
my $opt_protected;
2438 dpurdie 54
 
2450 dpurdie 55
my %excludeRepos;
56
 
2438 dpurdie 57
#-------------------------------------------------------------------------------
58
# Function        : Main Entry
59
#
60
# Description     :
61
#
62
# Inputs          :
63
#
64
# Returns         :
65
#
66
my $result = GetOptions (
67
                "help+"         => \$opt_help,          # flag, multiple use allowed
68
                "manual:3"      => \$opt_help,
69
                "verbose:+"     => \$opt_verbose,       # flag
70
                'repo:s'        => \$opt_repo,
2450 dpurdie 71
                'excluderepo:s' => \$opt_repoExclude,
72
                'age:i'         => \$opt_age,
2438 dpurdie 73
                'user:i'        => \$opt_user,
74
                'tail:i'        => \$opt_tail,
75
                'byage'         => \$opt_ageorder,
76
                'byuser'        => \$opt_ageorderUser,
2450 dpurdie 77
                'byrepo'        => \$opt_reposort,
2438 dpurdie 78
                'byname'        => \$opt_onlyName,
3347 dpurdie 79
                'byfullname'    => \$opt_onlyFullName,
2438 dpurdie 80
                'svn'           => \$opt_svn,            # Include SVNed packages
2450 dpurdie 81
                'touch:s'       => \$opt_touch,
3859 dpurdie 82
                'available:s'   => \@opt_available,
83
                'exclude:s'     => \@opt_exclude,
2450 dpurdie 84
                'all'           => \$opt_all,
3832 dpurdie 85
                'protected'     => \$opt_protected,
86
 
2438 dpurdie 87
                );
88
 
89
#
90
#   Process help and manual options
91
#
92
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
93
pod2usage(-verbose => 1)  if ($opt_help == 2);
94
pod2usage(-verbose => 2)  if ($opt_help > 2);
95
 
96
ErrorConfig( 'name'    =>'CC2SVN_REPOSCAN',
97
             'verbose' => $opt_verbose,
98
              );
99
 
100
#
2450 dpurdie 101
#   Sanity test
102
#
103
Error ("Touch path is not a directory") if ( defined $opt_touch && ! -d $opt_touch );
104
 
3859 dpurdie 105
foreach ( @opt_available )
106
{
107
    Error ("Available selector is not a directory: $_")
108
        unless ( -d $_ );
109
}
110
 
111
foreach ( @opt_exclude )
112
{
113
    Error ("Exclude selector is not a directory: $_")
114
        unless ( -d $_ );
115
}
116
 
2450 dpurdie 117
if ($opt_repoExclude)
118
{
119
    foreach (split m/\s*,\s*/, $opt_repoExclude )
120
    {
121
        $excludeRepos{$_} = 1;
122
    }
123
}
124
 
125
#
2438 dpurdie 126
#   Read in the Mapping Data
127
#
128
Message ("Read in Vob Mapping");
129
 
130
my $fname = 'cc2svn.repo.dat';
131
my $rname;
132
foreach my $base ( '' , '../' , '-' )
133
{
134
    Error ("Connot find file: $fname") if ( $base eq '-' );
135
    $rname = $base . $fname;
136
    last if ( -f $rname );
137
}
138
require $rname;
139
 
140
Error("Data in $fname is not valid")
141
    unless ( keys(%ScmRepoMap) >= 0 );
142
 
143
#
144
#   Filter Repos
145
#
146
my $keep = 0;
147
foreach my $pkgname ( keys %ScmRepoMap )
148
{
149
    my $entry = $ScmRepoMap{$pkgname};
150
    $keep = 1;
151
 
3832 dpurdie 152
    unless ( $opt_all || $opt_protected)
2450 dpurdie 153
    {
154
        if ( $entry->{protected} )
155
        {
156
            $keep = 0;
157
            next;
158
        }
159
    }
160
 
3832 dpurdie 161
    if ( $opt_protected )
162
    {
163
        my $prot = $entry->{protected} ? $entry->{protected} :' ';
164
        $prot =~ m~(.)~;
165
        $prot = $1;
166
        if ( $prot eq 'B' )
167
        {
168
            $keep = 0;
169
            next;
170
        }
171
    }
172
 
2450 dpurdie 173
    if ( $opt_repoExclude )
174
    {
175
        $entry->{repo} =~ m~^(.*?)(/|$)~;
176
        my $baseRepo = $1;
177
        if ( exists $excludeRepos{$baseRepo} || exists $excludeRepos{$entry->{repo}}  )
178
        {
179
            $keep = 0;
180
            next;
181
        }
182
    }
183
 
3859 dpurdie 184
    my $avFound = 2;
185
    foreach my $basedir ( @opt_available )
2450 dpurdie 186
    {
3859 dpurdie 187
        if ( -f $basedir . '/' . $pkgname || -f $basedir . '/' . $pkgname . '.svg' )
2450 dpurdie 188
        {
3859 dpurdie 189
            $avFound = 1;
190
            last;
191
        }
192
        $avFound = 0;
193
    }
194
    unless ($avFound > 0)
195
    {
196
        $keep = 0;
197
        next;
198
    }
199
 
200
    foreach my $basedir ( @opt_exclude )
201
    {
202
        if ( -f $basedir . '/' . $pkgname || -f $basedir . '/' . $pkgname . '.svg' )
203
        {
2450 dpurdie 204
            $keep = 0;
3859 dpurdie 205
            last;
2450 dpurdie 206
        }
207
    }
3859 dpurdie 208
    next unless($keep);
2450 dpurdie 209
 
3859 dpurdie 210
 
2438 dpurdie 211
    if ( $opt_repo )
212
    {
213
        unless ( $entry->{repo} =~ m~^$opt_repo($|/)~i )
214
        {
215
         $keep = 0;
2450 dpurdie 216
         next;
2438 dpurdie 217
        }
218
    }
219
 
2450 dpurdie 220
    if ( defined $opt_age )
2438 dpurdie 221
    {
2450 dpurdie 222
        if ( $opt_age > $entry->{youngest} )
2438 dpurdie 223
        {
224
            $keep = 0;
2450 dpurdie 225
            next;
2438 dpurdie 226
        }
227
    }
228
 
229
    if ( defined $opt_user )
230
    {
231
        if ( $opt_user > $entry->{ynr} )
232
        {
233
            $keep = 0;
2450 dpurdie 234
            next;
2438 dpurdie 235
        }
236
    }
237
 
238
    my $isSvn = exists ($entry->{SVN}) &&  $entry->{SVN};
239
    if (  !$opt_svn )
240
    {
241
        $keep = ! $isSvn;
242
    }
243
    next unless ( $keep );
244
}
245
continue
246
{
247
    delete $ScmRepoMap{$pkgname} unless ( $keep );
248
}
249
 
250
my $count = 0;
251
my $total = scalar keys %ScmRepoMap;
252
my @printOrder;
253
 
2764 dpurdie 254
sub sortRepoName
255
{
256
    my $rv = lc $ScmRepoMap{$a}{repo} cmp lc $ScmRepoMap{$b}{repo};
257
    return $rv if ( $rv );
258
    return $a cmp $b
259
}
260
 
2438 dpurdie 261
if ( $opt_ageorderUser ) {
262
    @printOrder = sort {$ScmRepoMap{$a}{ynr} <=> $ScmRepoMap{$b}{ynr}} keys %ScmRepoMap;
263
} elsif ( $opt_ageorder ) {
264
    @printOrder = sort {$ScmRepoMap{$a}{youngest} <=> $ScmRepoMap{$b}{youngest}} keys %ScmRepoMap;
2450 dpurdie 265
} elsif ( $opt_reposort ) {
2764 dpurdie 266
    @printOrder = sort sortRepoName keys %ScmRepoMap;
2438 dpurdie 267
} else {
268
    @printOrder =  sort {$a cmp $b} keys %ScmRepoMap ;
269
}
270
 
2764 dpurdie 271
my $lastRepo = '';
2438 dpurdie 272
foreach my $pkgname ( @printOrder )
273
{
274
    $count++;
275
    if ( $opt_tail && ($count <= ($total - $opt_tail)) )
276
    {
277
        next;
278
    }
279
 
2764 dpurdie 280
    my $entry = $ScmRepoMap{$pkgname};
2438 dpurdie 281
    if ( $opt_onlyName )
282
    {
2764 dpurdie 283
        my $prefix = '';
284
        if ($opt_reposort)
285
        {
286
            $prefix = '    ';
287
            if ( $entry->{repo} ne $lastRepo )
288
            {
289
                $lastRepo =  $entry->{repo};
290
                print  $lastRepo,"\n";
291
            }
292
        }
293
        print "$prefix$pkgname\n";
2438 dpurdie 294
    }
3347 dpurdie 295
    elsif ($opt_onlyFullName)
296
    {
297
        printf ("%-45s %s\n", $pkgname, $entry->{repo} );
298
    }
2438 dpurdie 299
    else
300
    {
301
 
302
        my $repo = $entry->{repo};
303
        my $svn = $entry->{SVN} ? 'SVN' : '---';
2450 dpurdie 304
        my $prot = $entry->{protected} ? $entry->{protected} :' ';
305
        $prot =~ m~(.)~;
306
        $prot = $1;
2438 dpurdie 307
 
308
        my $youngest            = $entry->{youngest};
309
        my $youngestNonRipple   = $entry->{ynr};
310
        my $youngestNonBuildadm = $entry->{ynb};
311
 
312
 
2450 dpurdie 313
        my $txt = sprintf ("Last:%5d, User:%5d, NonR:%5d, $svn $prot", $youngest, $youngestNonBuildadm, $youngestNonRipple);
2438 dpurdie 314
        $txt .= sprintf (" %45s %s", $pkgname, $repo );
315
        print "$txt\n";
316
    }
2450 dpurdie 317
 
318
    if ( $opt_touch )
319
    {
320
        TouchFile( $opt_touch .'/'.$pkgname);
3859 dpurdie 321
        foreach my $basePath ( @opt_available )
322
        {
323
            unlink ($basePath . '/' . $pkgname);
324
            unlink ($basePath . '/' . $pkgname . '.svg');
325
        }
2450 dpurdie 326
    }
2438 dpurdie 327
}
328
print "Maching entires: $total\n";
329
 
330
#-------------------------------------------------------------------------------
331
#   Documentation
332
#
333
 
334
=pod
335
 
336
=for htmltoc    SYSUTIL::cc2svn::
337
 
338
=head1 NAME
339
 
340
cc2svn_reposcan - Scan Repo.dat file
341
 
342
=head1 SYNOPSIS
343
 
344
  jats cc2svn_reposcan
345
 
346
 Options:
347
    -help              - brief help message
348
    -help -help        - Detailed help message
349
    -man               - Full documentation
350
    -verbose           - Enable verbosity
2450 dpurdie 351
   Package Selection
352
    -svn               - Include packages in SVN too
2438 dpurdie 353
    -repo=name         - Select named repos (default all)
2450 dpurdie 354
    -excludeRepo=name  - Exclude repos
2764 dpurdie 355
    -age=nn            - Select last build age > nn
356
    -user=nn           - Select last user build age> nn
3859 dpurdie 357
    -available=path    - Select if in named directory. Allow Multiple.
358
    -exclude=path      - Exclude if in named directory. Allow Multiple.
2450 dpurdie 359
    -all               - Include Protected and Broken packages
3832 dpurdie 360
    -protected         - Include Protected packages
2450 dpurdie 361
   Output Sorting
2438 dpurdie 362
    -byage             - Sort by last build age
363
    -byuser            - Sort by last User Mode age
3832 dpurdie 364
    -byrepo            - Sort by repository name
2450 dpurdie 365
   Display control
366
    -tail=nn           - Display last nn items
2438 dpurdie 367
    -byname            - Only display package names
3347 dpurdie 368
    -byfullname        - Only display package names and repo
2450 dpurdie 369
   Process control
370
    -touch=path        - Create a file named after the package
371
                         Delete 'available' marker file
2438 dpurdie 372
 
373
=head1 OPTIONS
374
 
375
=over 8
376
 
377
=item B<-help>
378
 
379
Print a brief help message and exits.
380
 
381
=item B<-help -help>
382
 
383
Print a detailed help message with an explanation for each option.
384
 
385
=item B<-man>
386
 
387
Prints the manual page and exits.
388
 
2450 dpurdie 389
=item B<-available=path>
390
 
391
This option will limit the selection to packages that have a marker file in
392
the named directory. The marker file will be file with the same name
393
as the package or with a '.svg' extension.
394
 
395
When used in conjunction with the '-touch' option the marker file will be
396
deleted after the target marker file has been 'touched'.
397
 
398
=item B<-touch=path>
399
 
400
This option will populate a 'new' or test directory with packages. When used,
401
an empty file named after the package, will be created in the target path.
402
 
2438 dpurdie 403
=back
404
 
405
=head1 DESCRIPTION
406
 
407
This program is a tool used in the conversion of ClearCase VOBS to subversion.
408
 
2450 dpurdie 409
=head2 Examples
410
 
411
The follwoing command will:
412
 
413
 jats cc2svn_reposcan -repo=MASS_Dev_Infra -user=30 -byuser -available=. -touch=../new
414
 
415
Process packages in the MASS_Dev_Infra repository, selecting that that have
416
not been modified by a user for 30 days and that have a marker file in the
417
current directory. It will display the results sorted by the time since last
418
modified by a user. It will also create a marker file in the directory '../new'.
419
 
2438 dpurdie 420
=cut
421