Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
1040 dpurdie 1
#! /usr/bin/perl
2
########################################################################
1044 dpurdie 3
# Copyright (C) 1998-2011 Vix Technology, All rights reserved
1040 dpurdie 4
#
5
# Module name   : blatPopulate
6
# Compiler(s)   : Perl
7
#
8
# Description   : Populate the blat tags directories with RM data
1044 dpurdie 9
#                 See POD at end of this file
1040 dpurdie 10
#
11
#......................................................................#
12
 
13
require 5.008_002;
14
use strict;
15
use warnings;
16
 
17
use Getopt::Long;                               # Option processing
18
use Pod::Usage;                                 # Required for help support
19
 
20
use File::Basename;
21
use File::Spec::Functions qw(catfile);
22
use FindBin;
23
 
24
use FindBin;                                    # Determine the current directory
25
use lib "$FindBin::Bin/lib";                    # Allow local libraries
26
use Utils;
1044 dpurdie 27
use StdLogger;                                  # Log to sdtout
1040 dpurdie 28
use Logger;
29
 
30
use Data::Dumper;
31
 
32
#
33
#   Globals
34
#
35
my $rootDir = $FindBin::Bin;
36
my $configPath = "config/blatPopulate.cfg";
37
my $conf;
38
my $errors;
39
my $logger;
40
my @args;
41
 
42
#
43
#   Options
44
#
45
my $opt_help = 0;
46
my $opt_verbose = 0;
47
my $opt_tagdir = 'tags';
1044 dpurdie 48
my $opt_nodaemonise;
1040 dpurdie 49
 
1044 dpurdie 50
my %pkginfo;
1040 dpurdie 51
 
1044 dpurdie 52
 
1040 dpurdie 53
#
1044 dpurdie 54
#   Describe configuration parameters
1040 dpurdie 55
#
56
my %cdata = (
57
    'logfile'         => {'mandatory' => 1    , 'fmt' => 'vfile'},
58
    'logfile.size'    => {'default' => '1M'   , 'fmt' => 'size'},
59
    'logfile.count'   => {'default' => 9      , 'fmt' => 'int'},
60
    'verbose'         => {'default' => 0      , 'fmt' => 'int'},
61
    'tagdir'          => {'mandatory' => 1    , 'fmt' => 'dir'},
1044 dpurdie 62
    'maxFileAge'      => {'default' => '24h'  , 'fmt' => 'period'},
1040 dpurdie 63
);
64
 
65
#-------------------------------------------------------------------------------
66
# Function        : Mainline Entry Point
67
#
68
# Description     :
69
#
70
# Inputs          :
71
#
72
@args = @ARGV;
1044 dpurdie 73
Getopt::Long::Configure('pass_through');
1040 dpurdie 74
my $result = GetOptions (
75
                "help|h:+"      => \$opt_help,
76
                "manual:3"      => \$opt_help,
77
                "verbose:+"     => \$opt_verbose,
78
                "tagdir=s"      => \$opt_tagdir,
1044 dpurdie 79
                "D"             => \$opt_nodaemonise,
1040 dpurdie 80
 
81
                );
82
 
83
                #
84
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
85
                #
86
 
87
#
88
#   Process help and manual options
89
#
1044 dpurdie 90
pod2usage(-verbose => 0, -message => "blatPopulate") if ($opt_help == 1 || ! $result );
1040 dpurdie 91
pod2usage(-verbose => 1) if ($opt_help == 2 );
92
pod2usage(-verbose => 2) if ($opt_help > 2);
93
 
1044 dpurdie 94
$logger = StdLogger->new();
95
 
1040 dpurdie 96
#
1044 dpurdie 97
#   Set the CWD as the directory of the script
1040 dpurdie 98
#   This simplifies configuration and use
99
#
100
chdir ($rootDir) || die ("Cannot 'cd' to $rootDir: $!\n");
101
 
102
#
103
#   Read in config
104
#
105
($conf, $errors) = Utils::readconf ( $configPath, \%cdata );
106
if ( scalar @{$errors} > 0 )
107
{
108
    warn "$_\n" foreach (@{$errors});
109
    die ("Config contained errors\n");
110
}
111
 
112
$conf->{verbose} = $opt_verbose if ( $opt_verbose > 0 );
7387 dpurdie 113
$logger = Logger->new($conf) unless ( $opt_nodaemonise );
114
$conf->{logger} = $logger;
1040 dpurdie 115
$logger->verbose2("Args: @args");
116
 
117
#
1044 dpurdie 118
#   Porcess command line
4457 dpurdie 119
#   Arguments are of the form aaaa=bbbbm
1044 dpurdie 120
#
121
foreach ( @ARGV )
122
{
123
    next unless ( m~(.+)=(.+)~ );
124
    {
125
        my $tag = $1;
126
        my $value = $2;
127
        $value =~ s~^['"]~~;
128
        $value =~ s~['"]$~~;
129
        $pkginfo{$tag} = $value;
130
    }
131
}
132
 
133
#
1040 dpurdie 134
#   Sanity Test
1044 dpurdie 135
#   Ensure required arguments have been presented
1040 dpurdie 136
#
1044 dpurdie 137
foreach  ( qw(pkg_name pkg_version rtag_id pkg_id pv_id proj_id mode_id) )
138
{
139
    $logger->err ("$_ not provided")    unless ( exists $pkginfo{$_} );
1040 dpurdie 140
 
1044 dpurdie 141
}
142
 
1040 dpurdie 143
#
1044 dpurdie 144
#   Not interested in package deletions
145
#
146
if ( $pkginfo{mode_id} == 2 )
147
{
148
    $logger->verbose3 ("Ignore package deletion: $pkginfo{pkg_name},$pkginfo{pkg_version}");
149
    exit 0;
150
}
151
 
152
#
1040 dpurdie 153
#   Examine all the tag subdirectories
154
#   They will have a configuration file in them that has been created by the
155
#   consumer daemon.
156
#
157
 
158
    my $dh;
159
    unless (opendir($dh, $opt_tagdir) )
160
    {
161
        $logger->err ("Can't opendir $opt_tagdir: $!");
162
    }
163
 
164
    #
165
    #   Process each entry
166
    #       Ignore those that start with a .
167
    #       Only process subdirs
168
    #
169
    while (my $tag = readdir($dh) )
170
    {
171
        next if ( $tag =~ m~^\.~ );
1044 dpurdie 172
        $logger->verbose3 ("Processing: $tag");
1040 dpurdie 173
        my $tagfile = catfile($opt_tagdir, $tag, '.config');
174
        next unless ( -f $tagfile );
1044 dpurdie 175
        $logger->verbose3 ("Tag Dir: $tagfile");
1040 dpurdie 176
 
177
        my ($mtime) = Utils::mtime($tagfile);
178
        my $age = time() - $mtime;
179
        $logger->verbose3( "Config File Age: $age, $conf->{maxFileAge}");
180
        if ( $age > $conf->{maxFileAge} )
181
        {
182
            $logger->verbose ("File is OLD: $tagfile, $age");
183
            unlink $tagfile;
7460 dpurdie 184
            unlink glob (catfile($opt_tagdir, $tag) .  '*::*');
1040 dpurdie 185
            next;
186
        }
187
 
188
        #
189
        #   Read in the config file
190
        #   Items of interest are:
191
        #       project
192
        #       release
193
        #       pkg.Name
194
        #
195
        my $data = ConfigReader::readConfig($tagfile);
1044 dpurdie 196
        if ( $conf->{verbose} > 2 )
197
        {
198
            $logger->verbose3 ("Config: " . Dumper($data));
199
        }
1040 dpurdie 200
        if ( $data )
201
        {
4457 dpurdie 202
            if (   ( exists $data->{allArchive} && $data->{allArchive} )
203
                || ( exists $data->{allProjects} && $data->{allProjects} ) 
204
                ||   exists $data->{projects}{$pkginfo{proj_id}}
205
                ||   exists $data->{releases}{$pkginfo{rtag_id}}
206
                ||   exists $data->{pkg}{$pkginfo{pkg_name}} )
1040 dpurdie 207
                {
7387 dpurdie 208
                    Utils::TouchFile($conf, catfile( $opt_tagdir, $tag, $pkginfo{pkg_name} . '::' . $pkginfo{pkg_version} ));
1040 dpurdie 209
                }
210
        }
211
    }
212
    closedir $dh;
213
 
7387 dpurdie 214
###############################################################################
1040 dpurdie 215
package ConfigReader;
216
our %config;
217
 
218
#-------------------------------------------------------------------------------
219
# Function        : readConfig
220
#
221
# Description     : Read in a configuration file
222
#                   The file is a perl data structure and it can be
223
#                   required directly
224
#
225
# Inputs          : $fname              - Name of the file to read
226
#
227
# Returns         : Data component of the file
228
#
229
sub readConfig
230
{
231
    my ($fname) = @_;
232
#print "Reading: $fname\n";
233
    require $fname;
234
    return \%config;
235
}
236
 
237
#-------------------------------------------------------------------------------
238
#   Documentation
239
#
240
 
241
=pod
242
 
243
=head1 NAME
244
 
245
blatPopulate - Populate Blats tags directory to provide fast-transfer of packages
246
 
247
=head1 SYNOPSIS
248
 
1044 dpurdie 249
blatPopulate [options] pkg_data
1040 dpurdie 250
 
251
 
252
 Options:
253
    -help              - brief help message
254
    -help -help        - Detailed help message
255
    -man               - Full documentation
256
    -verbose           - A little bit of logging
257
    -tagdir=path       - Specify alternate tag base
1044 dpurdie 258
 PkgData
259
    tag=value          - A list of package information items
1040 dpurdie 260
 
261
=head1 OPTIONS
262
 
263
=over 8
264
 
265
=item B<-help>
266
 
267
Print a brief help message and exits.
268
 
269
=item B<-help -help>
270
 
271
Print a detailed help message with an explanation for each option.
272
 
273
=item B<-man>
274
 
275
Prints the manual page and exits.
276
 
277
=item B<-tagdir=path>
278
 
279
This provides an alternate tag directory root. The default value is a 'tags'
280
directory located below the directory in which the program is located.
281
 
1044 dpurdie 282
=item B<-tagdir=path>
283
 
284
A list of package information items. These include:
285
 
286
=over 4
287
 
288
=item * archive
289
 
290
=item * pkg_name
291
 
292
=item * pkg_version
293
 
294
=item * rtag_id
295
 
296
=item * pkg_id
297
 
298
=item * pv_id
299
 
300
=item * proj_id
301
 
302
=item * mode_id
303
 
1040 dpurdie 304
=back
305
 
1044 dpurdie 306
=back
307
 
1040 dpurdie 308
=head1 DESCRIPTION
309
 
310
This utility is designed to be invoked by Release Manager when a new package
311
has been added to a release.
312
 
313
The function of this program is to determine which Blat transfer targets
314
need to be notified of this event. This is done by
315
 
316
=over 8
317
 
318
=item * Scanning all tag directories for a .config file
319
 
320
=item * Examining the .config file and if the transfer target needs the current
321
        package then a tag file will be created.
322
 
323
=back
324
 
325
The .config file is created by the the consume BlatDaemon on a regular basis.
326
If the file is too old it will be deleted, on the assumption that the
327
blatDaemon is dead.
328
 
1044 dpurdie 329
=head2 EXAMPLE
330
 
331
    blatPopulate.pl  archive=dpkg_archive
332
                     pkg_name='h400sdk'
333
                     pkg_version='1.1.13-4.1000.cots'
334
                     rtag_id=11083
335
                     pkg_id=32885
336
                     pv_id=270088
337
                     proj_id=341
338
                     mode_id=2
339
                     -verbose=3
340
 
1040 dpurdie 341
=cut
342