Subversion Repositories DevTools

Rev

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