Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
5209 dpurdie 1
########################################################################
2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
3
#
4
# Module name   : jats_lxr.pl
5
# Module type   : JATS Utility
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
5213 dpurdie 9
# Description   : Tools to maintain LXR information
5209 dpurdie 10
#
5213 dpurdie 11
# Possible imporvements
12
#       Delete files we don't want to index
13
#           .DMP,.dmp,.so,.gz,.zip,.lib,.bz,.bz2,.tbz,.jar,.deb,.exe,.a,.msb
14
#
15
#       Merge ripples package versions
16
#           Just keep one
17
#
18
#       Cots packages
19
#           Use contents from dpkg_archive instead of the package
20
#
5231 dpurdie 21
#       Better Version-Aging algorithm
22
#           Currently keep the last 5
23
#           Perhaps keep one from a month ago and one from 6 months ago.
24
#
25
#       Indication back into ReleaseManager of Releases that are present
26
#
5209 dpurdie 27
# Usage         : See POD at the end of this file
28
#
29
#......................................................................#
30
 
31
require 5.008_002;
32
use strict;
33
use warnings;
34
 
35
use Pod::Usage;
36
use Getopt::Long;
37
use File::Path;
38
use FindBin;
39
use Socket;
5213 dpurdie 40
use Fcntl ':flock';
5209 dpurdie 41
 
42
use JatsError;
43
use JatsRmApi;
44
use DBI;
45
use JatsSystem;
46
use FileUtils;
47
 
48
#
49
#   Config Options
50
#
51
my $VERSION = "1.0.0";                      # Update this
52
my $opt_help = 0;
53
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
54
my $opt_createVersions = 1;
55
my $opt_index = 1;
56
my $opt_purge = 1;
57
my $opt_extract = 1;
58
my $opt_logfile = 1;
5231 dpurdie 59
my $opt_forceViews;
5211 dpurdie 60
my $opt_config;
5209 dpurdie 61
 
62
 
63
#
64
#   Globals
65
#
66
my $scriptDir;
67
my $RM_DB;
5213 dpurdie 68
my $Config;
5209 dpurdie 69
my @addressList;
70
my %ReleaseData;
71
my %Packages;
72
my $PackageStore;
73
my $ReleaseStore;
5213 dpurdie 74
my $StampTime = time;
75
my $lockFile = '/tmp/JATSLXR_LOCK';
5209 dpurdie 76
 
77
#-------------------------------------------------------------------------------
78
# Function        : Main
79
#
80
# Description     : Main entry point
81
#                   Parse user options
82
#
83
# Inputs          :
84
#
85
# Returns         :
86
#
87
 
88
my $result = GetOptions (
89
                "help:+"            => \$opt_help,              # flag, multiple use allowed
90
                "manual:3"          => \$opt_help,              # flag, multiple use allowed
91
                "verbose:+"         => \$opt_verbose,           # flag
92
                "createVersions!"   => \$opt_createVersions,
93
                "purge!"            => \$opt_purge,
94
                "index!"            => \$opt_index,
95
                "extract!"          => \$opt_extract,
5211 dpurdie 96
                "logfile!"          => \$opt_logfile,
97
                "config:s"          => \$opt_config,
5231 dpurdie 98
                "forceViews!"       => \$opt_forceViews,
5209 dpurdie 99
                );
100
 
101
#
102
#   Process help and manual options
103
#
104
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
105
pod2usage(-verbose => 1)  if ($opt_help == 2 );
106
pod2usage(-verbose => 2)  if ($opt_help > 2);
107
 
108
#
109
#   Capture all logging to a file
110
#   Could be done by the jats wrapper, but this way we can control its location
111
#
112
ErrorConfig( 'name'    => 'LXR',
113
             'verbose' => $opt_verbose );
114
 
115
#
116
#   Sanity test
117
#
118
 
119
$scriptDir = $FindBin::Bin;
120
InitFileUtils();
121
 
122
#
123
#   Read the tool configuration
5213 dpurdie 124
#   Sed with Default config
5209 dpurdie 125
#
5213 dpurdie 126
$Config->{'releaseAge'} = 0;
127
$Config->{'packageAge'} = 0;
128
$Config->{'logAge'} = 0;
129
$Config->{'verbose'} = 0;
5209 dpurdie 130
readConfig();
131
 
132
#
133
#   Start logging
134
#
135
startLogFile();
136
Message ("Start of LXR. " . localtime(time) ) if $opt_logfile;
137
Message("ScriptDir: $scriptDir");
5231 dpurdie 138
DebugDumpData("Config", \$Config) if (IsVerbose(1));
5209 dpurdie 139
 
140
#
5231 dpurdie 141
#   Sanity Testing
142
#   
143
 
144
Error ("No LXR Data directory defined") unless( exists $Config->{lxrFiles});
145
Error ("No LXR Data directory found", $Config->{lxrFiles}) unless( -d $Config->{lxrFiles});
146
 
147
Error ("No LXR Install directory defined") unless( exists $Config->{lxr});
148
Error ("No LXR Install directory found",$Config->{lxr}) unless( -d $Config->{lxr});
149
 
150
Error ("No Glimpse Data directory defined") unless( exists $Config->{glimpseDir});
151
Warning ("No Glimpse Data directory found",$Config->{glimpseDir}) unless( -d $Config->{glimpseDir});
152
 
153
ErrorConfig( 'verbose' => $Config->{'verbose'} );
154
 
155
#
5213 dpurdie 156
#   Prevent multiple instances of the program running
157
#
158
#   PerlMonks say to use $0 as the lock file, but that did not work.
159
#   Perhaps the file was open in an editor
160
#   Solution: Create my own file
161
#
162
open( FW, '>',$lockFile);
163
print FW '';
164
close FW;
165
 
166
open (my $self, '<', $lockFile)    || Error("Couldn't open self: $!");
167
flock ($self, (LOCK_EX | LOCK_NB)) || Error("This script is already running");
168
 
169
#
5209 dpurdie 170
#   Check required paths exist
171
#
5213 dpurdie 172
$PackageStore = catdir($Config->{lxrFiles}, 'Packages');
173
$ReleaseStore = catdir($Config->{lxrFiles}, 'Releases');
5209 dpurdie 174
mkpath($PackageStore);
175
mkpath($ReleaseStore);
176
Error ("Package Store not found ",$PackageStore) unless( -d $PackageStore);
177
Error ("Release Store not found ",$ReleaseStore) unless( -d $ReleaseStore);
178
 
179
#
180
#   Determine the various names for this machine
181
#   Include all the IP addresses too
182
#
183
my ($canonname, $aliases, $addrtype, $length, @addrs) = gethostbyname($ENV{GBE_HOSTNAME});
184
push @addressList, $canonname ;
185
push (@addressList, $aliases) if ($aliases) ;
186
push (@addressList, $ENV{GBE_HOSTNAME});
5231 dpurdie 187
foreach (@addrs) {
5209 dpurdie 188
    push @addressList, inet_ntoa($_); 
189
}
190
Message("IpAddress: @addressList");
191
 
192
#
193
#   Perform the hard work
194
#
195
getReleaseData();
5213 dpurdie 196
updateReleaseViews() if $opt_createVersions;
5209 dpurdie 197
cleanReleaseViews();
5213 dpurdie 198
rebuildLxrConfig()  if $opt_index;
5209 dpurdie 199
buildIndexes() if $opt_index;
200
cleanPackageStore() if $opt_purge;
201
cleanupLogFiles() if $opt_purge;
202
 
203
#
204
#   All done
205
#
5213 dpurdie 206
unlink $lockFile;
5209 dpurdie 207
Message ("End of LXR. " . localtime(time) ) if $opt_logfile;
208
exit 0;
209
 
210
#-------------------------------------------------------------------------------
5212 dpurdie 211
# Function        : extractPackages 
5209 dpurdie 212
#
5212 dpurdie 213
# Description     : Extract Packages from VCS
5209 dpurdie 214
#                   Don't extract them if they already exist
5212 dpurdie 215
#   
216
#                   Kludge: Prevent extraction from MASS_Dev_Crypto Repo
5209 dpurdie 217
#
5213 dpurdie 218
# Inputs          : $rtagid         - Release To Process
219
#                                     Conatins PackageVersion data  
5209 dpurdie 220
#
221
# Returns         : 
222
#
5212 dpurdie 223
sub extractPackages
5209 dpurdie 224
{
5213 dpurdie 225
    my ($rtagid) = @_;
226
    foreach my $pvid (keys %{$ReleaseData{$rtagid}{data}})
5209 dpurdie 227
    {
228
        my $entry = $Packages{$pvid};
229
        #DebugDumpData("Entry", \$entry);
230
        my $fullName = join('_', $entry->{name}, $entry->{ver});
231
        my $fullPath = catfile($PackageStore , $fullName);
232
        next unless defined $entry->{vcs};
233
        next if ( $entry->{vcs} ) =~ m~^UC::~;
5211 dpurdie 234
        unless (-d $fullPath ) 
235
        {
5231 dpurdie 236
            Message("Extracting: $entry->{name}, $entry->{ver}");
5209 dpurdie 237
            if ($opt_extract)
238
            {
5231 dpurdie 239
                Verbose("Extracting into: $fullPath");
240
                my $result = 'ERROR';
5212 dpurdie 241
                if ($entry->{vcs} =~ m~/MASS_Dev_Crypto/~)
5211 dpurdie 242
                {
5231 dpurdie 243
                    $result = 'SUPPRESSED';
5211 dpurdie 244
                }
245
                else
246
                {
247
                    my $rv = JatsCmd ('jats_vcsrelease', '-devmode=escrow', '-extractfiles', "-view=$fullName", "-label=$entry->{vcs}", "-root=$PackageStore", "-noprefix");
5231 dpurdie 248
                    if ($rv)
249
                    {
250
                        $result = 'ERROR';
251
                        $entry->{bad} = 1;
252
                    }
253
                    else
254
                    {
255
                        $result = 'SUCCESS';
256
                    }
5211 dpurdie 257
                }
5231 dpurdie 258
                Message("Extraction Result: $result");
5209 dpurdie 259
            }
260
        }
5211 dpurdie 261
        else
262
        {
263
            #   Package already extracted
264
            #   Ensure that it does not get aged out
265
            deleteAgeMarker($fullPath);
266
        }
5209 dpurdie 267
    }
268
}
269
 
270
#-------------------------------------------------------------------------------
5213 dpurdie 271
# Function        : updateReleaseViews 
5209 dpurdie 272
#
5213 dpurdie 273
# Description     : 
5209 dpurdie 274
#
275
# Inputs          : 
276
#
277
# Returns         : 
278
#
5213 dpurdie 279
sub updateReleaseViews
5209 dpurdie 280
{
281
    #
5213 dpurdie 282
    #   Process each known Release
5209 dpurdie 283
    #
5213 dpurdie 284
    foreach my $rtagid (sort keys \%ReleaseData)
5209 dpurdie 285
    {
5231 dpurdie 286
        Verbose("updateReleaseViews: $rtagid"); 
5213 dpurdie 287
        if ($ReleaseData{$rtagid}{release}{ACTIVE})
5212 dpurdie 288
        {
5213 dpurdie 289
            #
290
            #   Determinte last created view in this Release
291
            #
292
            my ($latestView, $latestAge) = getLatestVersion(catdir($ReleaseStore, $rtagid ));
5231 dpurdie 293
            if ( ! defined($latestView) || $latestAge > 1 || $opt_forceViews)
5209 dpurdie 294
            {
295
                #
5213 dpurdie 296
                #   If there is no latest view, then we need to create a new view
297
                #   If there is a recent view, but its older than a day then we may need
298
                #   to refresh it.
5209 dpurdie 299
                #
5213 dpurdie 300
                getReleasePakageData($rtagid);
5231 dpurdie 301
                if (checkViewDiffs($latestView,$rtagid) || $opt_forceViews)
5209 dpurdie 302
                {
5213 dpurdie 303
                    #
304
                    #   Need to create a view
305
                    #       Either one does not exist
306
                    #       Content has changed
307
                    #
308
                    createReleaseView($rtagid);
5209 dpurdie 309
                }
5213 dpurdie 310
                else
311
                {
312
                    #   No need to create a new view
313
                    #   Do need to tag it so that we don't examine it again ( for a while )
314
                    Message("No Changes to LXR View: $rtagid");
315
                    if (defined $latestView)
316
                    {
317
                        my $rv = utime $StampTime,$StampTime, $latestView; 
5231 dpurdie 318
                        Debug("Utime $rv: $latestView");
5213 dpurdie 319
                    }
320
                }
5209 dpurdie 321
            }
5213 dpurdie 322
            else
5209 dpurdie 323
            {
5213 dpurdie 324
                Message("Recent LXR View: $rtagid");
5209 dpurdie 325
            }
5213 dpurdie 326
        }
327
        else
328
        {
329
            Message("Inactive LXR View: $rtagid");
330
        }
331
    }
332
}
333
 
334
#-------------------------------------------------------------------------------
335
# Function        : checkViewDiffs 
336
#
337
# Description     : Check a view against the current package versions in the
338
#                   Release 
339
#
340
# Inputs          : $vdir       - View entry to process
341
#                   $rtagid     - RtagId
342
#
343
# Returns         : True, If we need to create a new view
5231 dpurdie 344
#                         No view exists
345
#                         View does not match Release Content
5213 dpurdie 346
#
347
sub checkViewDiffs
348
{
349
    my ($vdir, $rtagid) = @_;
350
 
351
    #   No entry to process, then we need to create a view
352
    return 1 if not defined $vdir;
353
 
5231 dpurdie 354
    #
355
    #   Read in the View List
356
    #
5213 dpurdie 357
    my %pkgsUsed;
5231 dpurdie 358
    my $releaseListFile = catfile($vdir, '.lxrRelease');
359
    if (open (my $rf, '<', $releaseListFile ))
5213 dpurdie 360
    {
5231 dpurdie 361
        while (my $data = <$rf>)
5213 dpurdie 362
        {
5231 dpurdie 363
            $data =~ s~\s+$~~;
364
            $pkgsUsed{$data} = 2;
5209 dpurdie 365
        }
5231 dpurdie 366
    }
367
    else
368
    {
369
        Warning ("Cannot find Release List: $releaseListFile", $!);
370
        return 1;
371
    }
5209 dpurdie 372
 
5231 dpurdie 373
    #
374
    #   Compare the packages in the Release against those required
375
    #
376
    foreach my $pvid (keys %{$ReleaseData{$rtagid}{data}})
377
    {
378
        my $entry = $Packages{$pvid};
379
        my $fullName = join('_', $entry->{name}, $entry->{ver});
380
        $pkgsUsed{$fullName}++;
381
    }
5213 dpurdie 382
 
5231 dpurdie 383
    my $needNewView = 0;
384
    #
385
    #   Scan the pkgUsed
386
    #   A value of 1 indicates that it is used only in the New Version
387
    #   A value of 2 indicates that it is only used on the Last Version
388
    #   A value of 3 indicates that its used in both
389
    #   Detect those that are not a 3
390
    #
391
    foreach ( keys %pkgsUsed)
392
    {
393
        if ($pkgsUsed{$_} != 3)
5209 dpurdie 394
        {
5231 dpurdie 395
            $needNewView = 1;
396
            last;
5213 dpurdie 397
        }
398
    }
5231 dpurdie 399
    Warning("Release Contents don't match: $rtagid") if $needNewView;
5213 dpurdie 400
    #DebugDumpData("pkgsUsed",\%pkgsUsed);
401
    return $needNewView;
402
}
5209 dpurdie 403
 
5213 dpurdie 404
#-------------------------------------------------------------------------------
405
# Function        : createReleaseView 
406
#
407
# Description     : Create a new view for a single Release
408
#
409
# Inputs          : $rtagid     - RtagId
410
#
411
# Returns         : 
412
#
413
sub createReleaseView
414
{
415
    my ($rtagid) = @_;
5231 dpurdie 416
    my @ReleaseList;
5213 dpurdie 417
 
418
    #
419
    #   Ensure that packages have been extracted
420
    #
421
    extractPackages($rtagid);
422
 
423
    #
424
    #   Create the actual view directory
425
    #   Its simply a bunch of symlinks back to the package store
426
    #
5231 dpurdie 427
 
428
    #
429
    #   Create directory for the new view
430
    #   Based on current date. Some tools (glimpse and ctags) can't handle spaces in paths
431
    #
432
    my $dateTag = localtime($StampTime);
433
    $dateTag =~ s~\s+~_~g;
434
 
5213 dpurdie 435
    Message("Creating LXR View: $rtagid, $dateTag");
436
    my $releaseDir = catdir($ReleaseStore, $rtagid, $dateTag);
437
    mkpath($releaseDir);
438
    if (-d $releaseDir)
439
    {
440
        foreach my $pvid (keys %{$ReleaseData{$rtagid}{data}})
441
        {
442
            my $entry = $Packages{$pvid};
443
            my $alias = join('', $entry->{name}, $entry->{ext});
444
            my $fullName = join('_', $entry->{name}, $entry->{ver});
445
            my $PackageStore = catdir($PackageStore , $fullName);
5231 dpurdie 446
            my $pkgDir = catdir($releaseDir, $alias );
447
            push @ReleaseList, $fullName;
448
            next if -l $pkgDir;
449
            next if -d $pkgDir;
5213 dpurdie 450
 
5231 dpurdie 451
            #
452
            #   
453
            #   Glimpse will not follow symlinks - which would be nice
454
            #   Clone the Package using hardlinks - still saves space
455
            #
456
            Verbose("HardLink $PackageStore, $releaseDir");
457
            my $rv = System('--NoExit', '--NoShell', 'cp','-al', $PackageStore, $pkgDir);
458
            Warning("Could not duplicate $PackageStore, $releaseDir") if $rv;
459
 
460
 
461
#           Verbose("Symlink $PackageStore, $releaseDir");
462
#           my $rv = symlink ($PackageStore, $releaseDir);
463
#           Warning("Could not link $PackageStore, $releaseDir") unless ($rv);
5209 dpurdie 464
        }
5231 dpurdie 465
 
466
        #
467
        #   Generate a list of package-vesrions in the release
468
        #   Used so that we can detect changes to the release
469
        #
470
        FileCreate(catfile($releaseDir, '.lxrRelease'), \@ReleaseList);
5209 dpurdie 471
    }
5231 dpurdie 472
    Verbose("createReleaseView - End");
5209 dpurdie 473
}
474
 
475
#-------------------------------------------------------------------------------
476
# Function        : rebuildLxrConfig 
477
#
478
# Description     : Rebuild the LXR Configuration file
479
#                   This MAY be a bit LXR version specific, but since LXR doesn't
480
#                   provide a scriptable way to update configuration
481
#
482
#                   Uses template files that have been handcrafted after taken from
5211 dpurdie 483
#                   LXR. Basically we to a text replace and a glue together
5209 dpurdie 484
#
485
#                   For each release we need
486
#                       Long Release Name
487
#                       Short Release Name
488
#                       List of Versions
489
#
490
#
491
# Inputs          : Assumes Data has been added to %ReleaseData by other subroutines
492
#
493
# Returns         : 
494
#
495
sub rebuildLxrConfig
496
{
497
    my @lxrTreeText;
5211 dpurdie 498
 
5209 dpurdie 499
    #
5211 dpurdie 500
    #   Sort Sub
501
    #   Sort ReleaseData by Project and Name
502
    #   $a and $b are special to the sort
503
    #
504
    sub ReleaseDataSort
505
    {
506
        my $rv = lc($ReleaseData{$a}{release}{Project}) cmp lc($ReleaseData{$b}{release}{Project});
507
        if ($rv == 0)
508
        {
509
            $rv = lc($ReleaseData{$a}{release}{Name}) cmp lc($ReleaseData{$b}{release}{Name});
510
        }
511
        return $rv;
512
    }
513
 
514
    #
5209 dpurdie 515
    #   Process configured releases
5212 dpurdie 516
    #   Generate in the order we wish to display the Releases
5209 dpurdie 517
    #
518
    #DebugDumpData("ReleaseData", \%ReleaseData);
5211 dpurdie 519
    foreach my $rtagid ( sort ReleaseDataSort keys %ReleaseData )
5209 dpurdie 520
    {
521
        my $entry = $ReleaseData{$rtagid};
5211 dpurdie 522
        Information("Entry: $entry->{release}{Project}, $entry->{release}{Name}, $rtagid");
5209 dpurdie 523
        $entry->{release}{VersionsString} = join( ',', map { '"' . $_ .'"'} @{$entry->{Versions}} );
524
        $entry->{release}{dbName} = genDatabaseName($rtagid);
5213 dpurdie 525
        $entry->{release}{root} = catdir($ReleaseStore, $rtagid );
5209 dpurdie 526
        #DebugDumpData("ENTRY", \$entry);
527
 
528
        my $tfileName = 'lxr.tree.template';
529
        open( my $tf, '<', $tfileName) || Error ("Cannot open $tfileName. $!");
530
        while (my $line = <$tf>)
531
        {
532
            # Chomp trailing write space
533
            $line =~ s~\s+$~~;
534
 
535
            #   Replace known bits in the template
536
            $line =~ s~\@CAPTION\@~$entry->{release}{Project}::$entry->{release}{Name}~g;
537
            $line =~ s~\@SHORT_NAME\@~$rtagid~g;
538
            $line =~ s~\@RELEASE_ROOT\@~$entry->{release}{root}~g;
539
            $line =~ s~\@VERSIONS_LIST\@~$entry->{release}{VersionsString}~g;
540
            $line =~ s~\@DBNAME\@~$entry->{release}{dbName}~g;
541
            push @lxrTreeText, $line
542
        }
543
        close $tf;
544
    }
545
 
546
    #
547
    #   Insert tree sections into the main config file template
548
    #
549
    my $hostList = join( ',', map { '\'http://' . $_ .'\''} @addressList );
550
 
551
    my $tfileName = catfile($scriptDir, 'lxr.template');
5213 dpurdie 552
    my $lxrFileName = catfile($Config->{lxr}, 'lxr.new.conf');
5209 dpurdie 553
    unlink $lxrFileName;
554
    open( my $tf, '<', $tfileName) || Error ("Cannot open $tfileName. $!");
555
    open( my $to, '>', $lxrFileName) || Error ("Cannot open $lxrFileName. $!");
556
    while (my $line = <$tf>)
557
    {
558
        # Chomp trailing write space
559
        $line =~ s~\s+$~~;
560
 
561
        #   Replace known bits in the template
562
        if ($line =~ m~\@TREE_SECTIONS\@~)
563
        {
564
            foreach (@lxrTreeText)
565
            {
566
                print $to $_, "\n";
567
            }
568
        }
569
        else
570
        {
571
            $line =~ s~\@HOSTLIST\@~$hostList~g;
572
            print $to $line, "\n";
573
        }
574
    }
575
    close $tf;
576
    close $to;
577
 
578
    #
579
    #   Install the new config files
580
    #
5213 dpurdie 581
    my $lxrLive = catfile($Config->{lxr}, 'lxr.conf');
582
    my $lxrBackup = catfile($Config->{lxr}, 'lxr.conf.bak');
5209 dpurdie 583
    unlink $lxrBackup;
584
    rename ($lxrLive, $lxrBackup) || Warning("Renaming $lxrLive, $lxrBackup", $!);
585
    rename ($lxrFileName, $lxrLive) || Warning("Renaming $lxrFileName, $lxrLive", $!);
586
 
587
    #
588
    #   Create new database tables if required
589
    #   Use a customized shell script to do the hard work
590
    #
5213 dpurdie 591
    foreach my $rtagid ( sort keys %ReleaseData )
5209 dpurdie 592
    {
593
        my $entry = $ReleaseData{$rtagid};
5213 dpurdie 594
        Verbose("Database:$entry->{release}{Name}, $entry->{release}{dbName} ");
5209 dpurdie 595
        System('--NoExit', '--NoShell', catfile($scriptDir, 'lxr.initdb.sh'), $entry->{release}{dbName});
596
    }
597
}
598
 
599
#-------------------------------------------------------------------------------
600
# Function        : buildIndexes 
601
#
602
# Description     : Build (Generate) indexes for all versions of all releases
603
#                   that don't have an index
604
#                   
605
#                   Place a marker file in the 'version' directory when the
606
#                   index has been created
607
#
608
#                   Notes:
609
#                   The 'genxref' program needs to be run from the lxr insatll directory
610
#                   chdir to that directory for each invocation
611
#
612
#                   genxref uses DBI - and must find the proper PERL DBI and not the one
613
#                   within JATS.. Solution:
614
#                       Kill the PERL5LIB EnvVar
615
#
616
#
617
#
618
# Inputs          : 
619
#
620
# Returns         : 
621
#
622
sub buildIndexes
623
{
624
    #
625
    #   Prep envonment for calling genxref
626
    #   See notes above
627
    #
5213 dpurdie 628
    chdir ($Config->{lxr}) || Error ("Cannot chnage directory:$Config->{lxr}, $!");
5209 dpurdie 629
    delete $ENV{PERL5LIB};
630
 
631
    #
632
    #   Examine each Version in each Release
633
    #   Generate command line like:
634
    #   genxref --tree RTAGID --url http://HOSTNAME/lxr --version 'VERSION'
5213 dpurdie 635
    foreach my $rtagid ( sort keys %ReleaseData )
5209 dpurdie 636
    {
637
        my $entry = $ReleaseData{$rtagid};
638
        foreach my $version (@{$entry->{Versions}})
639
        {
5213 dpurdie 640
            my $markerFile = catfile(catdir($ReleaseStore, $rtagid ), $version, '.lxrIndexed');
5209 dpurdie 641
            unless (-f $markerFile) {
642
                Message("Must index: $rtagid, $version");
643
                my $rv = System('--NoExit', 
644
                       '--NoShell', 
5213 dpurdie 645
                       catfile($Config->{lxr}, 'genxref'),
5209 dpurdie 646
                       '--url', 'http://' . $ENV{GBE_HOSTNAME} . '/lxr',
647
                       '--tree', $rtagid,
648
                       '--version', $version
649
                       );
650
               Verbose("genxref exit: $rv");
651
               unless ($rv) {
652
                   TouchFile($markerFile);
653
               }
654
            }
655
            else
656
            {
657
                Verbose("Already indexed: $rtagid, $version");
658
            }
659
        }
660
    }
661
    #
662
    #   Restore current directory
663
    #
664
    chdir($FileUtils::CwdFull);
665
}
666
 
667
 
668
#-------------------------------------------------------------------------------
669
# Function        : cleanReleaseViews 
670
#
671
# Description     : Clean up unused Releases and Release Views
672
#                   Maintain the list of retained versions
673
#
674
#                   Two classes
675
#                   Active - Marked as having LXR support
676
#                       Retain the last 5 Versions
677
#
678
#                  InActive - Not having LXR support
679
#                       Retain for 10 days then delete all versions
680
#
681
# Inputs          : 
682
#
683
# Returns         : 
684
#
685
sub cleanReleaseViews
686
{
687
    #
688
    #   Scan Releases and delete all that are not currently configured
689
    #
690
    opendir (my $rdir, $ReleaseStore) || Error ("Cannot open directory: $ReleaseStore", $!);
691
    while (my $rdirEntry = readdir($rdir))
692
    {
693
        #   Skip hidden files and directories
694
        next if ($rdirEntry =~ m~^\.~);
695
        my $vdirName = catdir($ReleaseStore, $rdirEntry );
696
        next unless ( -d $vdirName );
5212 dpurdie 697
        unless(exists $ReleaseData{$rdirEntry} && $ReleaseData{$rdirEntry}{release}{ACTIVE} )
5209 dpurdie 698
        {
5211 dpurdie 699
            #   Release is no longer configured - age it out
5209 dpurdie 700
            #   Assume $rdirEntry is an rtag_id
5213 dpurdie 701
            if (processAgeMarker($vdirName, $Config->{'releaseAge'} ))
5211 dpurdie 702
            {
703
                Message("Delete Release: $rdirEntry");
704
                RmDirTree($vdirName);
705
                System('--NoExit', '--NoShell', catfile($scriptDir, 'lxr.dropdb.sh'), genDatabaseName($rdirEntry));
5231 dpurdie 706
                if ( defined $Config->{glimpseDir} )
707
                {
708
                    my $glimpseData = catdir( $Config->{glimpseDir}, $rdirEntry );
709
                    RmDirTree($glimpseData);
710
                }
5211 dpurdie 711
            }
5209 dpurdie 712
        }
713
        else
714
        {
5211 dpurdie 715
            deleteAgeMarker($vdirName);
5209 dpurdie 716
 
717
            #   Release is configured
718
            #   Keep the last x created
719
            #   Note: Create time is a kludge
720
            #
721
            #   Process each version within the Release
722
            #
723
            my @versionData;
724
            opendir (my $vdir, $vdirName) || Warning ("Cannot open directory: $vdirName", $!);
725
            while (my $vdirEntry = readdir($vdir))
726
            {
727
                #   Skip hidden files and directories
728
                next if ($vdirEntry =~ m~^\.~);
729
                my $ldirName = catdir($vdirName, $vdirEntry );
730
                next unless ( -d $ldirName );
731
                my $data;
732
                $data->{name} = $vdirEntry; 
733
                $data->{path} = $ldirName; 
734
                $data->{ctime} = (stat $ldirName)[9];
735
                push @versionData  , $data;
736
            }
737
            close ($vdir);
738
            #DebugDumpData("versionData",\@versionData);
739
 
740
            my $keepCount = 0;
741
            foreach my $entry ( sort { $b->{ctime} <=> $a->{ctime}} @versionData )
742
            {
743
                #DebugDumpData("Entry", $entry);
744
                $keepCount++;
745
                if ($keepCount > 5)
746
                {
747
                    #   Version is no longer needed - remove it
748
                    Message("Delete Version: $rdirEntry, $entry->{name}, $entry->{ctime}");
749
                    RmDirTree($entry->{path});
750
                }
751
                else
752
                {
753
                    #   Note which versions we have
754
                    push @{$ReleaseData{$rdirEntry}{Versions}}, $entry->{name};
755
                }
756
            }
757
        }
758
    }
759
    close ($rdir);
760
}
761
 
762
#-------------------------------------------------------------------------------
763
# Function        : getLatestVersion 
764
#
765
# Description     : For a specified directory return the newest subdir
766
#
767
#                   Used to determine the most recent version
768
#
5212 dpurdie 769
# Inputs          : $vdirName - Dir to process - expecting a Release directory
5209 dpurdie 770
#
5213 dpurdie 771
# Returns         : latestName  - Patch to the latest directory
772
#                   Age (days ) - Of the named directory
5209 dpurdie 773
#
774
sub getLatestVersion
775
{
776
    my  ($vdirName) = @_;
777
    my $latestName;
778
    my $latestAge = 0;
779
 
5213 dpurdie 780
    if (-d $vdirName )
5209 dpurdie 781
    {
5213 dpurdie 782
        opendir (my $vdir, $vdirName) || Warning ("Cannot open directory: $vdirName", $!);
783
        while (my $vdirEntry = readdir($vdir))
784
        {
785
            #   Skip hidden files and directories
786
            next if ($vdirEntry =~ m~^\.~);
5209 dpurdie 787
 
5213 dpurdie 788
            my $ldirName = catdir($vdirName, $vdirEntry );
789
            next unless ( -d $ldirName );
5209 dpurdie 790
 
5213 dpurdie 791
            my $age = (stat $ldirName)[9];
792
            Verbose3("Age: $ldirName, $age");
5209 dpurdie 793
 
5213 dpurdie 794
            if  ($age > $latestAge )
795
            {
796
                $latestAge = $age;
797
                $latestName = $ldirName;
798
            }
5209 dpurdie 799
        }
5213 dpurdie 800
        close ($vdir);
801
 
802
        #   Convert to Days ago
803
        $latestAge = ($StampTime - $latestAge) / (60*60*24);
804
        #DebugDumpData("versionDataSorted",\@versionDataSorted);
805
        Verbose("Latest: $latestName, $latestAge");
5209 dpurdie 806
    }
5213 dpurdie 807
    else
808
    {
809
        Verbose("Latest: No directory found: $vdirName");
810
    }
5209 dpurdie 811
 
5213 dpurdie 812
    return $latestName, $latestAge;
5209 dpurdie 813
}
814
 
815
#-------------------------------------------------------------------------------
816
# Function        : cleanPackageStore 
817
#
5231 dpurdie 818
# Description     : Delete unused Packages from the package store
819
#                   Each View in each Release will have a .lxrRelease file that contains the
820
#                   package versions that the view needs.
5209 dpurdie 821
#
822
# Inputs          : 
823
#
824
# Returns         : 
825
#
826
sub cleanPackageStore
827
{
5231 dpurdie 828
    Verbose ("cleanPackageStore");
5209 dpurdie 829
    my %pkgsUsed;
830
    #
831
    #   Examime ALL versions in ALL Releases and build up a hash of
832
    #   Package Versions used
833
    #
834
    opendir (my $rdir, $ReleaseStore) || Error ("Cannot open directory: $ReleaseStore", $!);
835
    while (my $rdirEntry = readdir($rdir))
836
    {
837
        #   Skip hidden files and directories
838
        next if ($rdirEntry =~ m~^\.~);
839
        my $vdirName = catdir($ReleaseStore, $rdirEntry );
840
        next unless ( -d $vdirName );
841
 
842
        #
843
        #   Process each version within the Release
844
        #
845
        opendir (my $vdir, $vdirName) || Warning ("Cannot open directory: $vdirName", $!);
846
        while (my $vdirEntry = readdir($vdir))
847
        {
848
            #   Skip hidden files and directories
849
            next if ($vdirEntry =~ m~^\.~);
850
            my $ldirName = catdir($vdirName, $vdirEntry );
851
            next unless ( -d $ldirName );
852
 
853
            #
5231 dpurdie 854
            #   Read in the View List
5209 dpurdie 855
            #
5231 dpurdie 856
            my $releaseListFile = catfile($ldirName, '.lxrRelease');
857
            if (open (my $rf, '<', $releaseListFile ))
5209 dpurdie 858
            {
5231 dpurdie 859
                Verbose2("Found ", $releaseListFile);
860
                while (my $data = <$rf>)
5209 dpurdie 861
                {
5231 dpurdie 862
                    $data =~ s~\s+$~~;
863
                    $pkgsUsed{$data}++;
5209 dpurdie 864
                }
865
            }
5231 dpurdie 866
            else
867
            {
868
                Warning ("Cannot find Release List: $releaseListFile", $!);
869
            }
5209 dpurdie 870
        }
871
        close ($vdir);
872
    }
873
    close ($rdir);
874
 
875
    #
876
    #   Process the Packages directory and remove those not currently used
877
    #
878
    #
879
    #   Process each entry within the Version
880
    #
881
    opendir (my $pdir, $PackageStore) || Error ("Cannot open directory: $PackageStore", $!);
882
    while (my $pdirEntry = readdir($pdir))
883
    {
884
        #   Skip hidden files and directories
885
        next if ($pdirEntry =~ m~^\.~);
886
        my $pdirName = catdir($PackageStore, $pdirEntry );
887
        next unless ( -d $pdirName );
888
        next if (exists $pkgsUsed{$pdirEntry} );
889
 
5213 dpurdie 890
        if (processAgeMarker($pdirName, $Config->{packageAge})) 
5211 dpurdie 891
        {
892
            Message("Purge Package: $pdirEntry");
893
            RmDirTree($pdirName);
894
        }
5209 dpurdie 895
    }
896
    close ($pdir);
897
 
898
    #DebugDumpData("pkgsUsed", \%pkgsUsed);
899
}
900
 
901
#-------------------------------------------------------------------------------
902
# Function        : getReleaseData 
903
#
904
# Description     : Get all the required Release Data 
905
#
906
# Inputs          :  
907
#
908
# Returns         : 
909
#
910
sub getReleaseData
911
{
912
    my ($rtagid) = @_;
913
    my (@row);
5212 dpurdie 914
    my @releaseList;
915
    my $partSql = '';
5209 dpurdie 916
 
5213 dpurdie 917
    Verbose("getReleaseData");
5209 dpurdie 918
    connectRM(\$RM_DB) unless $RM_DB;
919
 
5212 dpurdie 920
    #
921
    #   Determine list of existing Releases
922
    #   Build up a Clause for the extraction SQL
923
    #   This is used to get data for Releases that exist in the Store but may have been
924
    #   deconfigured.
925
    #
926
    if ( opendir (my $rdir, $ReleaseStore) )
927
    {
928
        while (my $rdirEntry = readdir($rdir))
929
        {
930
            #   Skip hidden files and directories
931
            next if ($rdirEntry =~ m~^\.~);
932
            my $vdirName = catdir($ReleaseStore, $rdirEntry );
933
            next unless ( -d $vdirName );
934
            push @releaseList, $rdirEntry;
935
        }
936
        close $rdir;
937
    }
5209 dpurdie 938
 
5212 dpurdie 939
    if (@releaseList)
940
    {
941
        $partSql = ' OR rt.rtag_id in (' . join(',', @releaseList ) . ')' 
942
    }
943
 
944
 
5209 dpurdie 945
    #
946
    # Determine which Releases need LXR support
947
    #
948
    my $m_sqlstr = 
949
        "SELECT rtag_id, " .
950
        "  rt.proj_id, " .
951
        "  p.PROJ_NAME, " .
952
        "  rtag_name, " .
953
        "  official, " .
5212 dpurdie 954
        "  NVL(TRUNC (SYSDATE - rt.official_stamp),0) AS OFFICIAL_STAMP_DAYS, " .
955
        "  rt.lxr " .
5209 dpurdie 956
        "FROM release_tags rt, " .
957
        "  projects p " .
5212 dpurdie 958
        "WHERE ( rt.lxr  = 'Y'" . $partSql . ")" .
959
        " AND p.PROJ_ID = rt.proj_id ";
5209 dpurdie 960
 
961
    my $sth = $RM_DB->prepare($m_sqlstr);
962
    if ( defined($sth) )
963
    {
964
        if ( $sth->execute( ) )
965
        {
966
            if ( $sth->rows )
967
            {
968
                while ( @row = $sth->fetchrow_array )
969
                {
970
                    my $rtagid = $row[0];
971
                    my $data;
972
                    $data->{Project} = $row[2];
973
                    $data->{Name} = $row[3];
974
                    $data->{official} = substr($row[4],0,1);
975
                    $data->{official_stamp_days} = $row[5];
5212 dpurdie 976
                    $data->{lxr} = $row[6];
5209 dpurdie 977
 
978
                    #
979
                    #   Determine if this request for an LXR release is OK
980
                    #   Ok If the release is Open, CCB or Restricted
5212 dpurdie 981
                    #   Ok If closed and has been closed to < 10 days
5209 dpurdie 982
                    #
5212 dpurdie 983
                    if ($data->{lxr} eq 'Y')
5209 dpurdie 984
                    {
5212 dpurdie 985
                        if (index('NRC', $data->{official}) >= 0)
986
                        {
987
                            $data->{ACTIVE} = 1;
988
                        }
989
                        elsif ($data->{official} eq 'Y' && $data->{official_stamp_days} < 10 )
990
                        {
991
                            $data->{ACTIVE} = 2;
992
                        }
5209 dpurdie 993
                    }
994
 
995
                    $ReleaseData{$rtagid}{release} = $data;
996
                }
997
            }
998
            $sth->finish();
999
        }
1000
    }
1001
    else
1002
    {
1003
        Error("getReleaseData:Prepare failure" );
1004
    }
1005
 
5213 dpurdie 1006
    if (IsVerbose(1))
1007
    {
1008
        DebugDumpData("ReleaseData", \%ReleaseData);
1009
    }
5212 dpurdie 1010
 
5213 dpurdie 1011
    #
1012
    #   Just a summary display for logging
1013
    #
1014
    foreach my $rtagid ( sort keys %ReleaseData)
5209 dpurdie 1015
    {
5213 dpurdie 1016
        my $state = $ReleaseData{$rtagid}{release}{ACTIVE} ? 'ACTIVE' : 'InActive';
1017
        Information("Release: RtagId $rtagid, $state");
5209 dpurdie 1018
    }
1019
}
1020
 
1021
#-------------------------------------------------------------------------------
5213 dpurdie 1022
# Function        : getReleasePakageData
5209 dpurdie 1023
#
5212 dpurdie 1024
# Description     : Get PackgeVersion information for one Release
5209 dpurdie 1025
#
1026
# Inputs          : rtagid
1027
#
1028
# Returns         : 
1029
#
5213 dpurdie 1030
sub getReleasePakageData
5209 dpurdie 1031
{
1032
    my ($rtagid) = @_;
1033
    my (@row);
1034
 
1035
    connectRM(\$RM_DB) unless $RM_DB;
1036
 
1037
 
1038
    # Get details for each package in the Release
1039
    #   Don't worry about dependent packages
1040
    #
1041
    my $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION, pv.V_EXT, release_manager.PK_RMAPI.return_vcs_tag(pv.PV_ID)".
1042
                   " FROM RELEASE_MANAGER.RELEASE_CONTENT rc, RELEASE_MANAGER.PACKAGE_VERSIONS pv, RELEASE_MANAGER.PACKAGES pkg" .
1043
                   " WHERE rc.RTAG_ID = $rtagid AND rc.PV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";
1044
    my $sth = $RM_DB->prepare($m_sqlstr);
1045
    if ( defined($sth) )
1046
    {
1047
        if ( $sth->execute( ) )
1048
        {
1049
            if ( $sth->rows )
1050
            {
1051
                while ( @row = $sth->fetchrow_array )
1052
                {
1053
                    my $data;
1054
                    my $pvid = $row[0];
1055
                    unless (exists $Packages{$pvid}) {
1056
                        $data->{pv_id} = $row[0];
1057
                        $data->{name} = $row[1];
1058
                        $data->{ver} = $row[2];
1059
                        $data->{ext} = $row[3] || '';
1060
                        $data->{vcs} = $row[4] || '';
1061
                        $Packages{$pvid} = $data;
1062
                    }
5212 dpurdie 1063
                    $ReleaseData{$rtagid}{data}{$pvid} = 1;
5209 dpurdie 1064
                }
1065
            }
1066
            $sth->finish();
1067
        }
1068
    }
1069
    else
1070
    {
5213 dpurdie 1071
        Error("getReleasePakageData:Prepare failure" );
5209 dpurdie 1072
    }
1073
}
1074
 
1075
#-------------------------------------------------------------------------------
1076
# Function        : genDatabaseName 
1077
#
1078
# Description     : Genertate the name of a database
1079
#
1080
# Inputs          : rtag_id 
1081
#
1082
# Returns         : Text Name of the database
1083
#
1084
 
1085
sub genDatabaseName
1086
{
1087
    my ($rtag_id) = @_;
1088
    return 'LXR_' . $rtag_id;
1089
}
1090
 
1091
#-------------------------------------------------------------------------------
1092
# Function        : readConfig 
1093
#
1094
# Description     : Read the basic LXR config
1095
#                   This is held in a Perl structure 
1096
#
1097
# Inputs          : None 
1098
#
1099
# Returns         : Populate Global Data
1100
#
1101
sub readConfig
1102
{
1103
    my $cfile = catfile($scriptDir,'jats_lxr.conf');
5211 dpurdie 1104
    if ($opt_config)
1105
    {
1106
        Message ("Using alternate config: $opt_config");
1107
        $cfile = $opt_config;
1108
    }
5209 dpurdie 1109
 
5213 dpurdie 1110
    #
1111
    #   Slurp in the file and evaluate it as a perl expression
1112
    #
1113
    if (open(my $CONFIG, '<', $cfile))
1114
    {
1115
        local ($/) = undef;
1116
        my $config_contents = <$CONFIG>;
1117
        $config_contents =~ m/(.*)/s;
1118
        $config_contents = $1;    #untaint it
1119
        my $config = eval("\n#line 1 \"configuration file\"\n" . $config_contents);
1120
        Error($@) if $@;
1121
        close $CONFIG;
5209 dpurdie 1122
 
5213 dpurdie 1123
        #
1124
        #   Merge read data with defaults
1125
        #
1126
        @$Config{ keys %$config } = values %$config;
1127
    }
1128
    else
1129
    {
1130
        Error("Couldn't open configuration file \"$cfile\".", $!);
1131
    }
5209 dpurdie 1132
}
1133
 
1134
#-------------------------------------------------------------------------------
1135
# Function        : startLogFile 
1136
#
1137
# Description     : Start logging to a log file
1138
#                   Generate a nice name for the log file
1139
#
1140
# Inputs          : 
1141
#
1142
# Returns         : 
1143
#
1144
sub startLogFile
1145
{
1146
    if ( $opt_logfile )
1147
    {
5213 dpurdie 1148
        if (exists $Config->{lxrLogDir})
5209 dpurdie 1149
        {
5213 dpurdie 1150
            my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($StampTime);
5209 dpurdie 1151
            my $name = sprintf("jats-lxr-%4.4d%2.2d%2.2d.%2.2d%2.2d%2.2d.log", 1900+$year, 1+$mon, $mday, $hour, $min, $sec);
5213 dpurdie 1152
            $name = catdir($Config->{lxrLogDir}, $name);
5209 dpurdie 1153
 
5213 dpurdie 1154
            mkpath($Config->{lxrLogDir}); 
1155
            if (-d $Config->{lxrLogDir} )
5209 dpurdie 1156
            {
1157
                open STDOUT, '>', $name  or die "Can't redirect STDOUT: $!";
1158
                open STDERR, ">&STDOUT"  or die "Can't dup STDOUT: $!";
1159
            }
1160
            else
1161
            {
5213 dpurdie 1162
                Warning("Can't create log dir: $Config->{lxrLogDir}. $!");
5209 dpurdie 1163
            }
1164
        }
1165
    }
1166
}
1167
 
1168
#-------------------------------------------------------------------------------
1169
# Function        : cleanupLogFiles 
1170
#
1171
# Description     : Remove old log files
1172
#
1173
# Inputs          : 
1174
#
1175
# Returns         : 
1176
#
1177
sub cleanupLogFiles
1178
{
5213 dpurdie 1179
    if (exists $Config->{lxrLogDir} && exists $Config->{logAge}  && $Config->{logAge} > 0 )
5209 dpurdie 1180
    {
5213 dpurdie 1181
        Verbose("cleanupLogFiles:$Config->{lxrLogDir}, $Config->{logAge}");
1182
        if ( opendir my $logDir, $Config->{lxrLogDir} )
5209 dpurdie 1183
        {
1184
            foreach my $fileName (readdir $logDir)
1185
            {
5213 dpurdie 1186
                my $file = catfile($Config->{lxrLogDir}, $fileName);
5209 dpurdie 1187
                next unless -f $file;
5213 dpurdie 1188
                next unless -M $file > $Config->{logAge};
5209 dpurdie 1189
                Verbose("Purge logfile: $fileName");
1190
                unlink $file;
1191
            }
1192
            closedir $logDir;
1193
        }
1194
    }
1195
}
1196
 
5211 dpurdie 1197
#-------------------------------------------------------------------------------
1198
# Function        : processAgeMarker 
1199
#
1200
# Description     : Age out directories
1201
#                   Will create age markers as required
1202
#
1203
# Inputs          : $tdir       - Target Directory
1204
#                   $age        - Configured age 
1205
#
1206
# Returns         : true        - Directory has reached age
1207
#
1208
sub processAgeMarker
1209
{
1210
    my ($tdir, $age) = @_;
1211
 
1212
    unless (-d $tdir) {
1213
        Warning ("Expected directory not found: $tdir");
1214
        return 0; 
1215
    }
5209 dpurdie 1216
 
5211 dpurdie 1217
    #   A configured age of 0 implies delete immediatly
1218
    if ($age == 0)
1219
    {
1220
        return 1;
1221
    }
1222
 
1223
    #
1224
    #   Create the file ONCE
1225
    #
1226
    my $markerfile = catfile($tdir, '.lxrAge');
1227
    unless (-f $markerfile)
1228
    {
1229
        TouchFile($markerfile);
1230
    }
1231
    else
1232
    {
5213 dpurdie 1233
        my $fileAge = -M $markerfile;
1234
        Verbose ("Age: $fileAge, $tdir");
1235
        if ($fileAge > $age)
5211 dpurdie 1236
        {
1237
            return 1
1238
        }
1239
    }
1240
    return 0;
1241
}
1242
 
1243
 
5209 dpurdie 1244
#-------------------------------------------------------------------------------
5211 dpurdie 1245
# Function        : deleteAgeMarker 
1246
#
1247
# Description     : Delete any age marker
1248
#                   Used when a (potentially) agable directory is used to remove
1249
#                   the aging marker
1250
#
1251
# Inputs          :  $tdir      - Directory
1252
#
1253
# Returns         : 
1254
#
1255
sub deleteAgeMarker
1256
{
1257
    my ($tdir) = @_;
1258
 
1259
    unless (-d $tdir) {
1260
        Warning ("Expected directory not found: $tdir");
1261
        return 0; 
1262
    }
1263
 
1264
    #
1265
    #   Use same file name as in processAgeMarker
1266
    #
1267
    my $markerfile = catfile($tdir, '.lxrAge');
1268
    unlink $markerfile;
1269
}
1270
 
1271
 
1272
#-------------------------------------------------------------------------------
5209 dpurdie 1273
#   Documentation
1274
#
1275
 
1276
=pod
1277
 
1278
=head1 NAME
1279
 
1280
jats_lxr - Maintain LXR Releases
1281
 
1282
=head1 SYNOPSIS
1283
 
1284
  jats jats_lxr [options]
1285
 
1286
 Options:
1287
    -help               - brief help message
1288
    -help -help         - Detailed help message
1289
    -man                - Full documentation
1290
    -[no]createVersions - Create new versions. Default:Create
1291
    -[no]extract        - Extract source code. Default:Extract
1292
    -[no]index          - Index new LXR versions. Default:Index
1293
    -[no]purge          - Purge unused packages. Default:Purge
1294
    -[no]logfile        - Capture out to a log file. Default:Log
5231 dpurdie 1295
    -[no]forceViews     - Force creation of new views. Default:NoForceView
5211 dpurdie 1296
    -config=file        - Alternate config file
5209 dpurdie 1297
 
1298
=head1 OPTIONS
1299
 
1300
=over 8
1301
 
1302
=item B<-help>
1303
 
1304
Print a brief help message and exits.
1305
 
1306
=item B<-help -help>
1307
 
1308
Print a detailed help message with an explanation for each option.
1309
 
1310
=item B<-man>
1311
 
1312
Prints the manual page and exits.
1313
 
1314
=item B<-verbose>
1315
 
1316
This option will display progress information as the program executes.
1317
 
1318
=item B<-[no]createVersions>
1319
 
1320
This option can be used to suppress the creation of new views.
1321
 
1322
=item B<-[no]extract>
1323
 
1324
This option can be used to suppress the extraction of source.
1325
 
1326
=item B<-[no]index>
1327
 
1328
This option can be used to suppress the indexing of newly created views.
1329
 
1330
=item B<-[no]purge>
1331
 
1332
This option can be used to suppress purging of packages that are no longer used by any of the LXR Trees.
1333
 
5231 dpurdie 1334
=item B<-[no]forceViews>
1335
 
1336
This option can be used to force the creation of a new View in each Release.
1337
 
5211 dpurdie 1338
=item B<-config=file>
1339
 
1340
This option can be used to override the standard config file. Used in testing.
1341
 
5209 dpurdie 1342
=back
1343
 
1344
=head1 DESCRIPTION
1345
 
1346
This program is a tool for creating and maintaining an LXR instance within the VIX Build System.
1347
 
1348
The program can:
1349
 
1350
=over 8
1351
 
1352
=item * 
1353
 
1354
Examine the Release Manager Database and determine which Releases are a part of the set to have LXR Views created.
1355
 
1356
Releases that are Open (or Restricted or in CCB Mode) or that have been closed for less than 10 days will be processed.
1357
 
1358
=item *
1359
 
1360
Examine the Release Manager Database and determine the package-versions that are a part of the LXR Release Set.
1361
 
1362
The process will only examine the contents of a Release. It will not descend the version dependency tree.
1363
 
1364
The program will then extract new package-versions into it's Package Store. Multiple LXR Tree's will share the one 
1365
instance of the extracted source code.
1366
 
1367
=item *
1368
 
1369
Create a new 'Version' for each Release.
1370
 
1371
The Version Name is based on the date-time at which the process is run.
1372
 
1373
Each Version is a symlink to the required package-version held in the Package Store.
1374
 
1375
This step can be suppressed though a command line option.
1376
 
1377
=item *
1378
 
1379
Remove unused LXR Trees (Releases no longer being processed) and unused Versions within each Tree.
1380
 
1381
Releases that are no longer eligable for processing will be retained for 10 days and then deleted. 
1382
During this time the existing versions will not be aged out.
1383
 
1384
At the moment this tool simply retains the last 5 Versions of each Release. If the tool 
1385
is run nightly then this will translate into  5 days.
1386
 
1387
=item *
1388
 
1389
Regenerate the LXR Configuration file
1390
 
1391
Create new database tables for new Releases
1392
 
1393
=item *
1394
 
1395
Run the LXR indexer for each LXR Version that has not been processed. Once processed the Version will 
1396
be tagged to prevent further indexing.
1397
 
1398
=item *
1399
 
1400
Remove unused Package-Versions from the Package Store.
1401
 
1402
=back
1403
 
1404
=cut
1405