Subversion Repositories DevTools

Rev

Rev 4457 | Rev 7460 | 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;
184
            next;
185
        }
186
 
187
        #
188
        #   Read in the config file
189
        #   Items of interest are:
190
        #       project
191
        #       release
192
        #       pkg.Name
193
        #
194
        my $data = ConfigReader::readConfig($tagfile);
1044 dpurdie 195
        if ( $conf->{verbose} > 2 )
196
        {
197
            $logger->verbose3 ("Config: " . Dumper($data));
198
        }
1040 dpurdie 199
        if ( $data )
200
        {
4457 dpurdie 201
            if (   ( exists $data->{allArchive} && $data->{allArchive} )
202
                || ( exists $data->{allProjects} && $data->{allProjects} ) 
203
                ||   exists $data->{projects}{$pkginfo{proj_id}}
204
                ||   exists $data->{releases}{$pkginfo{rtag_id}}
205
                ||   exists $data->{pkg}{$pkginfo{pkg_name}} )
1040 dpurdie 206
                {
7387 dpurdie 207
                    Utils::TouchFile($conf, catfile( $opt_tagdir, $tag, $pkginfo{pkg_name} . '::' . $pkginfo{pkg_version} ));
1040 dpurdie 208
                }
209
        }
210
    }
211
    closedir $dh;
212
 
7387 dpurdie 213
###############################################################################
1040 dpurdie 214
package ConfigReader;
215
our %config;
216
 
217
#-------------------------------------------------------------------------------
218
# Function        : readConfig
219
#
220
# Description     : Read in a configuration file
221
#                   The file is a perl data structure and it can be
222
#                   required directly
223
#
224
# Inputs          : $fname              - Name of the file to read
225
#
226
# Returns         : Data component of the file
227
#
228
sub readConfig
229
{
230
    my ($fname) = @_;
231
#print "Reading: $fname\n";
232
    require $fname;
233
    return \%config;
234
}
235
 
236
#-------------------------------------------------------------------------------
237
#   Documentation
238
#
239
 
240
=pod
241
 
242
=head1 NAME
243
 
244
blatPopulate - Populate Blats tags directory to provide fast-transfer of packages
245
 
246
=head1 SYNOPSIS
247
 
1044 dpurdie 248
blatPopulate [options] pkg_data
1040 dpurdie 249
 
250
 
251
 Options:
252
    -help              - brief help message
253
    -help -help        - Detailed help message
254
    -man               - Full documentation
255
    -verbose           - A little bit of logging
256
    -tagdir=path       - Specify alternate tag base
1044 dpurdie 257
 PkgData
258
    tag=value          - A list of package information items
1040 dpurdie 259
 
260
=head1 OPTIONS
261
 
262
=over 8
263
 
264
=item B<-help>
265
 
266
Print a brief help message and exits.
267
 
268
=item B<-help -help>
269
 
270
Print a detailed help message with an explanation for each option.
271
 
272
=item B<-man>
273
 
274
Prints the manual page and exits.
275
 
276
=item B<-tagdir=path>
277
 
278
This provides an alternate tag directory root. The default value is a 'tags'
279
directory located below the directory in which the program is located.
280
 
1044 dpurdie 281
=item B<-tagdir=path>
282
 
283
A list of package information items. These include:
284
 
285
=over 4
286
 
287
=item * archive
288
 
289
=item * pkg_name
290
 
291
=item * pkg_version
292
 
293
=item * rtag_id
294
 
295
=item * pkg_id
296
 
297
=item * pv_id
298
 
299
=item * proj_id
300
 
301
=item * mode_id
302
 
1040 dpurdie 303
=back
304
 
1044 dpurdie 305
=back
306
 
1040 dpurdie 307
=head1 DESCRIPTION
308
 
309
This utility is designed to be invoked by Release Manager when a new package
310
has been added to a release.
311
 
312
The function of this program is to determine which Blat transfer targets
313
need to be notified of this event. This is done by
314
 
315
=over 8
316
 
317
=item * Scanning all tag directories for a .config file
318
 
319
=item * Examining the .config file and if the transfer target needs the current
320
        package then a tag file will be created.
321
 
322
=back
323
 
324
The .config file is created by the the consume BlatDaemon on a regular basis.
325
If the file is too old it will be deleted, on the assumption that the
326
blatDaemon is dead.
327
 
1044 dpurdie 328
=head2 EXAMPLE
329
 
330
    blatPopulate.pl  archive=dpkg_archive
331
                     pkg_name='h400sdk'
332
                     pkg_version='1.1.13-4.1000.cots'
333
                     rtag_id=11083
334
                     pkg_id=32885
335
                     pv_id=270088
336
                     proj_id=341
337
                     mode_id=2
338
                     -verbose=3
339
 
1040 dpurdie 340
=cut
341