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;
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
 
2764 dpurdie 206
sub sortRepoName
207
{
208
    my $rv = lc $ScmRepoMap{$a}{repo} cmp lc $ScmRepoMap{$b}{repo};
209
    return $rv if ( $rv );
210
    return $a cmp $b
211
}
212
 
2438 dpurdie 213
if ( $opt_ageorderUser ) {
214
    @printOrder = sort {$ScmRepoMap{$a}{ynr} <=> $ScmRepoMap{$b}{ynr}} keys %ScmRepoMap;
215
} elsif ( $opt_ageorder ) {
216
    @printOrder = sort {$ScmRepoMap{$a}{youngest} <=> $ScmRepoMap{$b}{youngest}} keys %ScmRepoMap;
2450 dpurdie 217
} elsif ( $opt_reposort ) {
2764 dpurdie 218
    @printOrder = sort sortRepoName keys %ScmRepoMap;
2438 dpurdie 219
} else {
220
    @printOrder =  sort {$a cmp $b} keys %ScmRepoMap ;
221
}
222
 
2764 dpurdie 223
my $lastRepo = '';
2438 dpurdie 224
foreach my $pkgname ( @printOrder )
225
{
226
    $count++;
227
    if ( $opt_tail && ($count <= ($total - $opt_tail)) )
228
    {
229
        next;
230
    }
231
 
2764 dpurdie 232
    my $entry = $ScmRepoMap{$pkgname};
2438 dpurdie 233
    if ( $opt_onlyName )
234
    {
2764 dpurdie 235
        my $prefix = '';
236
        if ($opt_reposort)
237
        {
238
            $prefix = '    ';
239
            if ( $entry->{repo} ne $lastRepo )
240
            {
241
                $lastRepo =  $entry->{repo};
242
                print  $lastRepo,"\n";
243
            }
244
        }
245
        print "$prefix$pkgname\n";
2438 dpurdie 246
    }
247
    else
248
    {
249
 
250
        my $repo = $entry->{repo};
251
        my $svn = $entry->{SVN} ? 'SVN' : '---';
2450 dpurdie 252
        my $prot = $entry->{protected} ? $entry->{protected} :' ';
253
        $prot =~ m~(.)~;
254
        $prot = $1;
2438 dpurdie 255
 
256
        my $youngest            = $entry->{youngest};
257
        my $youngestNonRipple   = $entry->{ynr};
258
        my $youngestNonBuildadm = $entry->{ynb};
259
 
260
 
2450 dpurdie 261
        my $txt = sprintf ("Last:%5d, User:%5d, NonR:%5d, $svn $prot", $youngest, $youngestNonBuildadm, $youngestNonRipple);
2438 dpurdie 262
        $txt .= sprintf (" %45s %s", $pkgname, $repo );
263
        print "$txt\n";
264
    }
2450 dpurdie 265
 
266
    if ( $opt_touch )
267
    {
268
        TouchFile( $opt_touch .'/'.$pkgname);
269
        unlink ($opt_available . '/' . $pkgname) if ( $opt_available );
270
        unlink ($opt_available . '/' . $pkgname . '.svg') if ( $opt_available );
271
    }
2438 dpurdie 272
}
273
print "Maching entires: $total\n";
274
 
275
#-------------------------------------------------------------------------------
276
#   Documentation
277
#
278
 
279
=pod
280
 
281
=for htmltoc    SYSUTIL::cc2svn::
282
 
283
=head1 NAME
284
 
285
cc2svn_reposcan - Scan Repo.dat file
286
 
287
=head1 SYNOPSIS
288
 
289
  jats cc2svn_reposcan
290
 
291
 Options:
292
    -help              - brief help message
293
    -help -help        - Detailed help message
294
    -man               - Full documentation
295
    -verbose           - Enable verbosity
2450 dpurdie 296
   Package Selection
297
    -svn               - Include packages in SVN too
2438 dpurdie 298
    -repo=name         - Select named repos (default all)
2450 dpurdie 299
    -excludeRepo=name  - Exclude repos
2764 dpurdie 300
    -age=nn            - Select last build age > nn
301
    -user=nn           - Select last user build age> nn
2450 dpurdie 302
    -available=path    - Select if in named directory
303
    -all               - Include Protected and Broken packages
304
   Output Sorting
2438 dpurdie 305
    -byage             - Sort by last build age
306
    -byuser            - Sort by last User Mode age
2450 dpurdie 307
    -byprepo           - Sort by repository name
308
   Display control
309
    -tail=nn           - Display last nn items
2438 dpurdie 310
    -byname            - Only display package names
2450 dpurdie 311
   Process control
312
    -touch=path        - Create a file named after the package
313
                         Delete 'available' marker file
2438 dpurdie 314
 
315
=head1 OPTIONS
316
 
317
=over 8
318
 
319
=item B<-help>
320
 
321
Print a brief help message and exits.
322
 
323
=item B<-help -help>
324
 
325
Print a detailed help message with an explanation for each option.
326
 
327
=item B<-man>
328
 
329
Prints the manual page and exits.
330
 
2450 dpurdie 331
=item B<-available=path>
332
 
333
This option will limit the selection to packages that have a marker file in
334
the named directory. The marker file will be file with the same name
335
as the package or with a '.svg' extension.
336
 
337
When used in conjunction with the '-touch' option the marker file will be
338
deleted after the target marker file has been 'touched'.
339
 
340
=item B<-touch=path>
341
 
342
This option will populate a 'new' or test directory with packages. When used,
343
an empty file named after the package, will be created in the target path.
344
 
2438 dpurdie 345
=back
346
 
347
=head1 DESCRIPTION
348
 
349
This program is a tool used in the conversion of ClearCase VOBS to subversion.
350
 
2450 dpurdie 351
=head2 Examples
352
 
353
The follwoing command will:
354
 
355
 jats cc2svn_reposcan -repo=MASS_Dev_Infra -user=30 -byuser -available=. -touch=../new
356
 
357
Process packages in the MASS_Dev_Infra repository, selecting that that have
358
not been modified by a user for 30 days and that have a marker file in the
359
current directory. It will display the results sorted by the time since last
360
modified by a user. It will also create a marker file in the directory '../new'.
361
 
2438 dpurdie 362
=cut
363