Subversion Repositories DevTools

Rev

Rev 7460 | Details | Compare with Previous | Last modification | View Log | RSS feed

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