Subversion Repositories DevTools

Rev

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